Fix action plan state change when action failed

Since default workflow engine action container do_execute method
does not raise exception when action failed, workflow engine action
container execute method never raise exception and
action plan state becomes always SUCCEEDED.

This patch fixes default workflow engine action container do_execute
method to raise exception when action does not return True.

Change-Id: I7eeef69dbdfb5d40e3cf0b1004cbfe199a16bf7b
Closes-Bug: #1719793
This commit is contained in:
Hidekazu Nakamura
2017-09-27 16:37:35 +09:00
parent 773b20a05f
commit 5814914aef
4 changed files with 15 additions and 5 deletions

View File

@@ -127,8 +127,10 @@ class TaskFlowActionContainer(base.BaseTaskFlowActionContainer):
return self.engine.notify(self._db_action,
objects.action.State.SUCCEEDED)
else:
return self.engine.notify(self._db_action,
objects.action.State.FAILED)
self.engine.notify(self._db_action,
objects.action.State.FAILED)
raise exception.ActionExecutionFailure(
action_id=self._db_action.uuid)
def do_post_execute(self):
LOG.debug("Post-condition action: %s", self.name)

View File

@@ -435,6 +435,10 @@ class ActionDescriptionNotFound(ResourceNotFound):
msg_fmt = _("The action description %(action_id)s cannot be found.")
class ActionExecutionFailure(WatcherException):
msg_fmt = _("The action %(action_id)s execution failed.")
# Model
class ComputeResourceNotFound(WatcherException):

View File

@@ -51,7 +51,7 @@ class FakeAction(abase.BaseAction):
pass
def execute(self):
raise ExpectedException()
return False
def get_description(self):
return "fake action, just for test"
@@ -311,7 +311,8 @@ class TestDefaultWorkFlowEngine(base.DbTestCase):
exc = self.assertRaises(exception.WorkflowExecutionException,
self.engine.execute, actions)
self.assertIsInstance(exc.kwargs['error'], ExpectedException)
self.assertIsInstance(exc.kwargs['error'],
exception.ActionExecutionFailure)
self.check_action_state(actions[0], objects.action.State.FAILED)
@mock.patch.object(objects.ActionPlan, "get_by_uuid")

View File

@@ -21,6 +21,7 @@ import mock
from watcher.applier.workflow_engine import default as tflow
from watcher.common import clients
from watcher.common import exception
from watcher.common import nova_helper
from watcher import objects
from watcher.tests.db import base
@@ -79,7 +80,9 @@ class TestTaskFlowActionContainer(base.DbTestCase):
action_container = tflow.TaskFlowActionContainer(
db_action=action,
engine=self.engine)
action_container.execute()
self.assertRaises(exception.ActionExecutionFailure,
action_container.execute, action_id=action.uuid)
self.assertTrue(action.state, objects.action.State.FAILED)