Raise if no validation has been executed

If no validations has been run, the CLI should raise
a exceptions.CommandError  instead of trying to build the prettytable
from results.

Change-Id: I2ed22b9c01ebb64281ad5b8b3b569cc53a4f122e
(cherry picked from commit efcf2d98be)
(cherry picked from commit a60ec726e4)
This commit is contained in:
Mathieu Bultel 2020-10-12 23:08:11 +02:00 committed by Gael Chamoulaud (Strider)
parent 10e13cbb99
commit 11c7c2663a
No known key found for this signature in database
GPG Key ID: 4119D0305C651D66
1 changed files with 37 additions and 30 deletions

View File

@ -363,37 +363,44 @@ class TripleOValidatorRun(command.Command):
v_consts.DEFAULT_VALIDATIONS_BASEDIR = constants.\ v_consts.DEFAULT_VALIDATIONS_BASEDIR = constants.\
DEFAULT_VALIDATIONS_BASEDIR DEFAULT_VALIDATIONS_BASEDIR
actions = ValidationActions() actions = ValidationActions()
results = actions.run_validations( try:
inventory=static_inventory, results = actions.run_validations(
limit_hosts=limit, inventory=static_inventory,
group=parsed_args.group, limit_hosts=limit,
extra_vars=extra_vars, group=parsed_args.group,
validations_dir=constants.ANSIBLE_VALIDATION_DIR, extra_vars=extra_vars,
validation_name=parsed_args.validation_name, validations_dir=constants.ANSIBLE_VALIDATION_DIR,
extra_env_vars=parsed_args.extra_env_vars, validation_name=parsed_args.validation_name,
python_interpreter=parsed_args.python_interpreter, extra_env_vars=parsed_args.extra_env_vars,
quiet=True) python_interpreter=parsed_args.python_interpreter,
quiet=True)
except RuntimeError as e:
raise exceptions.CommandError(e)
# Build output if results:
t = PrettyTable(border=True, header=True, padding_width=1) # Build output
# Set Field name by getting the result dict keys t = PrettyTable(border=True, header=True, padding_width=1)
t.field_names = results[0].keys() # Set Field name by getting the result dict keys
for r in results: t.field_names = results[0].keys()
if r.get('Status_by_Host'): for r in results:
h = [] if r.get('Status_by_Host'):
for host in r['Status_by_Host'].split(', '): h = []
_name, _status = host.split(',') for host in r['Status_by_Host'].split(', '):
color = (GREEN if _status == 'PASSED' else RED) _name, _status = host.split(',')
_name = '{}{}{}'.format(color, _name, RESET) color = (GREEN if _status == 'PASSED' else RED)
h.append(_name) _name = '{}{}{}'.format(color, _name, RESET)
r['Status_by_Host'] = ', '.join(h) h.append(_name)
if r.get('status'): r['Status_by_Host'] = ', '.join(h)
status = r.get('status') if r.get('status'):
color = (CYAN if status in ['starting', 'running'] status = r.get('status')
else GREEN if status == 'PASSED' else RED) color = (CYAN if status in ['starting', 'running']
r['status'] = '{}{}{}'.format(color, status, RESET) else GREEN if status == 'PASSED' else RED)
t.add_row(r.values()) r['status'] = '{}{}{}'.format(color, status, RESET)
print(t) t.add_row(r.values())
print(t)
else:
msg = "No Validation has been run, please check your parameters."
raise exceptions.CommandError(msg)
if not parsed_args.static_inventory: if not parsed_args.static_inventory:
LOG.debug(_('Removing static tripleo ansible inventory file')) LOG.debug(_('Removing static tripleo ansible inventory file'))