Browse Source

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
tags/7.1.0
James Slagle 2 years ago
parent
commit
026cb4a76e
4 changed files with 41 additions and 1 deletions
  1. +5
    -0
      releasenotes/notes/handle-failed-actions-cac0abd02ed67a51.yaml
  2. +9
    -0
      tripleoclient/exceptions.py
  3. +22
    -0
      tripleoclient/tests/workflows/test_base.py
  4. +5
    -1
      tripleoclient/workflows/base.py

+ 5
- 0
releasenotes/notes/handle-failed-actions-cac0abd02ed67a51.yaml 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

+ 9
- 0
tripleoclient/exceptions.py 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)

+ 22
- 0
tripleoclient/tests/workflows/test_base.py 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)

+ 5
- 1
tripleoclient/workflows/base.py 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):

Loading…
Cancel
Save