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

Commit

Permalink
Atomic/scan.py: Fix scan error message (BZ #1508453)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
baude committed Nov 1, 2017
1 parent cd6af24 commit c4b1faa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Atomic/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,16 @@ def get_additional_args():
scan_type = self.get_scan_type()

# Load the atomic config file and check scanner settings
yaml_error = "The image name or scanner arguments for '{}' is not " \
"defined in /etc/atomic.conf".format(self.scanner)

scanner_image_name, scanner_args, custom_args = get_scan_info(self.scanner, scan_type)

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

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

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

Expand Down
16 changes: 16 additions & 0 deletions Atomic/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,22 @@ def _recursive_get(atomic_config, items):
else:
return default

def get_scanner_conf_path_by_name(scanner_name):
if not os.path.exists(ATOMIC_CONFD):
raise ValueError("{} does not exist".format(ATOMIC_CONFD))
files = [os.path.join(ATOMIC_CONFD, x) for x in os.listdir(ATOMIC_CONFD) if os.path.isfile(os.path.join(ATOMIC_CONFD, x))]
for f in files:
with open(f, 'r') as conf_file:
try:
temp_conf = yaml_load(conf_file)
if temp_conf.get('type') == "scanner" and temp_conf.get("scanner_name") == scanner_name:
return conf_file.name
except YAMLError:
pass
except AttributeError:
pass
raise ValueError("Unable to correlate {} to its configuration file".format(scanner_name))

def get_scanners():
scanners = []
if not os.path.exists(ATOMIC_CONFD):
Expand Down

0 comments on commit c4b1faa

Please sign in to comment.