Skip to content
This repository was archived by the owner on Oct 10, 2020. It is now read-only.

Commit f8c7399

Browse files
committed
Atomic/scan.py: Fix scan error message (BZ #1508453)
BZ #1508453 correctly points out that the error message points to the wrong file when telling the user it cannot find the scanner image or arguments. Signed-off-by: baude <[email protected]>
1 parent cd6af24 commit f8c7399

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

Atomic/scan.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,16 @@ def get_additional_args():
110110
scan_type = self.get_scan_type()
111111

112112
# Load the atomic config file and check scanner settings
113-
yaml_error = "The image name or scanner arguments for '{}' is not " \
114-
"defined in /etc/atomic.conf".format(self.scanner)
115-
116113
scanner_image_name, scanner_args, custom_args = get_scan_info(self.scanner, scan_type)
117114

118115
if not isinstance(scanner_args, list):
119116
raise ValueError("The scanner arguments for {} must be in list"
120117
" ([]) form.".format(self.scanner))
121118

122119
if None in [scanner_image_name, scanner_args]:
123-
raise ValueError(yaml_error)
120+
sconf_file = util.get_scanner_conf_path_by_name(self.scanner)
121+
raise ValueError("The scanner configuration for '{}' in '{}' is missing its image name "
122+
"or scanner arguments".format(self.scanner, sconf_file))
124123

125124
self.results_dir = os.path.join(self.results, self.scanner, self.cur_time)
126125

Atomic/util.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,20 @@ def _recursive_get(atomic_config, items):
486486
else:
487487
return default
488488

489+
def get_scanner_conf_path_by_name(scanner_name):
490+
if not os.path.exists(ATOMIC_CONFD):
491+
raise ValueError("{} does not exist".format(ATOMIC_CONFD))
492+
files = [os.path.join(ATOMIC_CONFD, x) for x in os.listdir(ATOMIC_CONFD) if os.path.isfile(os.path.join(ATOMIC_CONFD, x))]
493+
for f in files:
494+
with open(f, 'r') as conf_file:
495+
try:
496+
temp_conf = yaml_load(conf_file)
497+
if temp_conf.get('type') == "scanner" and temp_conf.get("scanner_name") == scanner_name:
498+
return conf_file.name
499+
except:
500+
pass
501+
raise ValueError("Unable to correlate {} to its configuration file".format(scanner_name))
502+
489503
def get_scanners():
490504
scanners = []
491505
if not os.path.exists(ATOMIC_CONFD):

0 commit comments

Comments
 (0)