Handle failed actions

The result of syncrhonously called Mistral actions wasn't being checked
to see if the action passed or failed. The result is now checked and if
the action has failed, an exception will be raised.

Change-Id: I95ae8c98fec94cf91f3f209b593f6c1815729fd4
Closes-Bug: #1686811
This commit is contained in:
James Slagle 2017-04-27 15:16:07 -04:00
parent dd19054206
commit 026cb4a76e
4 changed files with 41 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
fixes:
- The result of Mistral actions will now be checked, and if they've failed,
an exception will be raised. See
https://bugs.launchpad.net/tripleo/+bug/1686811

View File

@ -78,3 +78,12 @@ class PlanCreationError(Exception):
class PlanExportError(Exception):
"""Plan export failed"""
class WorkflowActionError(Exception):
"""Workflow action failed"""
msg_format = "Action {} execution failed: {}"
def __init__(self, message, action='', output=''):
message = message.format(action, output)
super(WorkflowActionError, self).__init__(message)

View File

@ -58,3 +58,25 @@ class TestBaseWorkflows(utils.TestCommand):
self.assertTrue(mistral.executions.get.called)
websocket.wait_for_messages.assert_called_with(timeout=None)
def test_call_action_success(self):
mistral = mock.Mock()
action = 'test-action'
result = mock.Mock()
result.output = '{"result":"test-result"}'
mistral.action_executions.create = mock.Mock(return_value=result)
self.assertEqual(base.call_action(mistral, action), "test-result")
def test_call_action_fail(self):
mistral = mock.Mock()
action = 'test-action'
result = mock.Mock()
result.output = '{"result":"test-result"}'
result.state = 'ERROR'
mistral.action_executions.create = mock.Mock(return_value=result)
self.assertRaises(exceptions.WorkflowActionError,
base.call_action, mistral, action)

View File

@ -25,7 +25,11 @@ def call_action(workflow_client, action, **input_):
save_result=True, run_sync=True)
# Parse the JSON output. Mistral client should do this for us really.
return json.loads(result.output)['result']
output = json.loads(result.output)['result']
if result.state == 'ERROR':
raise exceptions.WorkflowActionError(action, output)
return output
def start_workflow(workflow_client, identifier, workflow_input):