Provide more information when 'node provide' fails
Because 'provide' calls to other workflows, the error message that surfaces back can be quite difficult to parse. This attempts to make the message more readable. Change-Id: Iae3f29e5da25177fdee45752410f92b064c874c3 Depends-On: I8da43e4ff76488fc5cdb7bd2efa0cf9c39e7bb5e Closes-Bug: #1620949
This commit is contained in:
parent
c0f79d4477
commit
0573b605a2
|
@ -120,6 +120,27 @@ class TestBaremetalWorkflows(utils.TestCommand):
|
|||
'queue_name': "QUEUE_NAME"
|
||||
})
|
||||
|
||||
def test_format_provide_errors(self):
|
||||
payload = {'message': [{'result': 'Error1a\nError1b'},
|
||||
{'result': 'Error2a\nError2b\n'}]}
|
||||
|
||||
error_string = baremetal._format_provide_errors(payload)
|
||||
self.assertEqual(error_string, "Error1b\nError2b")
|
||||
|
||||
def test_provide_error_with_format_message(self):
|
||||
|
||||
self.websocket.wait_for_message.return_value = {
|
||||
"status": "FAIL",
|
||||
"message": ['Error1', 'Error2']
|
||||
}
|
||||
|
||||
self.assertRaises(
|
||||
exceptions.NodeProvideError,
|
||||
baremetal.provide,
|
||||
self.app.client_manager,
|
||||
node_uuids=[],
|
||||
queue_name="QUEUE_NAME")
|
||||
|
||||
def test_introspect_success(self):
|
||||
|
||||
self.websocket.wait_for_message.return_value = {
|
||||
|
|
|
@ -43,6 +43,21 @@ def register_or_update(clients, **workflow_input):
|
|||
'Exception registering nodes: {}'.format(payload['message']))
|
||||
|
||||
|
||||
def _format_provide_errors(payload):
|
||||
errors = []
|
||||
messages = payload.get('message', [])
|
||||
for msg in messages:
|
||||
try:
|
||||
# With multiple workflows, the error message can become
|
||||
# quite large and unreadable as it gets passed from task to
|
||||
# task. This attempts to keep only the last, and hopefully
|
||||
# useful part.
|
||||
errors.append(msg.get('result', '').rstrip('\n').split('\n')[-1])
|
||||
except Exception:
|
||||
errors.append(msg.get('result', ''))
|
||||
return '\n'.join(errors)
|
||||
|
||||
|
||||
def provide(clients, **workflow_input):
|
||||
"""Provide Baremetal Nodes
|
||||
|
||||
|
@ -62,12 +77,15 @@ def provide(clients, **workflow_input):
|
|||
with tripleoclients.messaging_websocket(queue_name) as ws:
|
||||
payload = ws.wait_for_message(execution.id)
|
||||
|
||||
if payload['status'] == 'SUCCESS':
|
||||
print('Successfully set all nodes to available.')
|
||||
else:
|
||||
raise exceptions.NodeProvideError(
|
||||
'Failed to set nodes to available state: {}'.format(
|
||||
payload['message']))
|
||||
if payload['status'] == 'SUCCESS':
|
||||
print('Successfully set all nodes to available.')
|
||||
else:
|
||||
try:
|
||||
message = _format_provide_errors(payload)
|
||||
except Exception:
|
||||
message = 'Failed.'
|
||||
raise exceptions.NodeProvideError(
|
||||
'Failed to set nodes to available state: {}'.format(message))
|
||||
|
||||
|
||||
def introspect(clients, **workflow_input):
|
||||
|
|
Loading…
Reference in New Issue