Improve validations run outputs through the CLI

When the tripleo.messaging.v1.send workflow fails with the error
'Workflow failed due to message status', the return message is None and
we don't have more information about what's failing. The same happens if
the validation runs well.

This patch improves the output in case of a messaging workflow failure.

Change-Id: I3fbf1a05b706b55fe1ab6d35653aecdaa8d4cc6e
Signed-off-by: Gael Chamoulaud <gchamoul@redhat.com>
This commit is contained in:
Gael Chamoulaud 2019-05-16 16:16:39 +02:00
parent e1a051d6ac
commit 1acbef8a06
3 changed files with 21 additions and 21 deletions

View File

@ -1857,6 +1857,11 @@ def get_validations_yaml(validations_data):
indent=2) indent=2)
def indent(text):
'''Indent the given text by four spaces.'''
return ''.join(' {}\n'.format(line) for line in text.splitlines())
def get_local_timezone(): def get_local_timezone():
info = run_command(['timedatectl'], name='timedatectl') info = run_command(['timedatectl'], name='timedatectl')
timezoneline = [tz for tz in info.split('\n') if 'Time zone:' in tz] timezoneline = [tz for tz in info.split('\n') if 'Time zone:' in tz]

View File

@ -30,11 +30,11 @@ class _CommaListGroupAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None): def __call__(self, parser, namespace, values, option_string=None):
opts = constants.VALIDATION_GROUPS opts = constants.VALIDATION_GROUPS
for value in values.split(','): for value in values.split(','):
if value not in opts: if value not in opts:
message = ("Invalid choice: {value} (choose from {choice})" message = ("Invalid choice: {value} (choose from {choice})"
.format(value=value, .format(value=value,
choice=opts)) choice=opts))
raise argparse.ArgumentError(self, message) raise argparse.ArgumentError(self, message)
setattr(namespace, self.dest, values.split(',')) setattr(namespace, self.dest, values.split(','))
@ -168,12 +168,12 @@ class TripleOValidatorRun(command.Command):
} }
LOG.debug(_('Runnning the validations')) LOG.debug(_('Runnning the validations'))
try: output = validations.run_validations(clients, workflow_input)
output = validations.run_validations(clients, workflow_input) for out in output:
print(oooutils.get_validations_json(output)) print('[{}] - {}\n{}'.format(
except Exception as e: out.get('status'),
print(_("Running the validations finished with errors")) out.get('validation_name'),
print('Output: {}'.format(e)) oooutils.indent(out.get('stdout'))))
def take_action(self, parsed_args): def take_action(self, parsed_args):
self._run_validator_run(parsed_args) self._run_validator_run(parsed_args)

View File

@ -16,8 +16,6 @@ import pprint
from tripleoclient.workflows import base from tripleoclient.workflows import base
from tripleoclient import exceptions
def list_validations(clients, workflow_input): def list_validations(clients, workflow_input):
@ -41,6 +39,7 @@ def run_validations(clients, workflow_input):
workflow_client = clients.workflow_engine workflow_client = clients.workflow_engine
tripleoclients = clients.tripleoclient tripleoclients = clients.tripleoclient
results = []
with tripleoclients.messaging_websocket() as ws: with tripleoclients.messaging_websocket() as ws:
@ -60,12 +59,8 @@ def run_validations(clients, workflow_input):
) )
for payload in base.wait_for_messages(workflow_client, ws, execution): for payload in base.wait_for_messages(workflow_client, ws, execution):
if 'message' in payload: if payload.get('message') is None:
if payload['status'] == 'SUCCESS': if payload.get('status') in ['SUCCESS', 'FAILED']:
return payload['message'] results.append(payload)
if payload['status'] == 'FAILED': return results
raise exceptions.RegisterOrUpdateError(
'Exception running validations: {}'.format(
payload['message'])
)