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)
def indent(text):
'''Indent the given text by four spaces.'''
return ''.join(' {}\n'.format(line) for line in text.splitlines())
def get_local_timezone():
info = run_command(['timedatectl'], name='timedatectl')
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):
opts = constants.VALIDATION_GROUPS
for value in values.split(','):
if value not in opts:
message = ("Invalid choice: {value} (choose from {choice})"
.format(value=value,
choice=opts))
raise argparse.ArgumentError(self, message)
if value not in opts:
message = ("Invalid choice: {value} (choose from {choice})"
.format(value=value,
choice=opts))
raise argparse.ArgumentError(self, message)
setattr(namespace, self.dest, values.split(','))
@ -168,12 +168,12 @@ class TripleOValidatorRun(command.Command):
}
LOG.debug(_('Runnning the validations'))
try:
output = validations.run_validations(clients, workflow_input)
print(oooutils.get_validations_json(output))
except Exception as e:
print(_("Running the validations finished with errors"))
print('Output: {}'.format(e))
output = validations.run_validations(clients, workflow_input)
for out in output:
print('[{}] - {}\n{}'.format(
out.get('status'),
out.get('validation_name'),
oooutils.indent(out.get('stdout'))))
def take_action(self, parsed_args):
self._run_validator_run(parsed_args)

View File

@ -16,8 +16,6 @@ import pprint
from tripleoclient.workflows import base
from tripleoclient import exceptions
def list_validations(clients, workflow_input):
@ -41,6 +39,7 @@ def run_validations(clients, workflow_input):
workflow_client = clients.workflow_engine
tripleoclients = clients.tripleoclient
results = []
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):
if 'message' in payload:
if payload['status'] == 'SUCCESS':
return payload['message']
if payload.get('message') is None:
if payload.get('status') in ['SUCCESS', 'FAILED']:
results.append(payload)
if payload['status'] == 'FAILED':
raise exceptions.RegisterOrUpdateError(
'Exception running validations: {}'.format(
payload['message'])
)
return results