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

View File

@ -363,6 +363,7 @@ 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()
try:
results = actions.run_validations( results = actions.run_validations(
inventory=static_inventory, inventory=static_inventory,
limit_hosts=limit, limit_hosts=limit,
@ -373,7 +374,10 @@ class TripleOValidatorRun(command.Command):
extra_env_vars=parsed_args.extra_env_vars, extra_env_vars=parsed_args.extra_env_vars,
python_interpreter=parsed_args.python_interpreter, python_interpreter=parsed_args.python_interpreter,
quiet=True) quiet=True)
except RuntimeError as e:
raise exceptions.CommandError(e)
if results:
# Build output # Build output
t = PrettyTable(border=True, header=True, padding_width=1) t = PrettyTable(border=True, header=True, padding_width=1)
# Set Field name by getting the result dict keys # Set Field name by getting the result dict keys
@ -394,6 +398,9 @@ class TripleOValidatorRun(command.Command):
r['status'] = '{}{}{}'.format(color, status, RESET) r['status'] = '{}{}{}'.format(color, status, RESET)
t.add_row(r.values()) t.add_row(r.values())
print(t) 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'))