Merge "Adjust the action state judgment logic"
This commit is contained in:
@@ -120,14 +120,15 @@ class TaskFlowActionContainer(base.BaseTaskFlowActionContainer):
|
|||||||
def do_execute(self, *args, **kwargs):
|
def do_execute(self, *args, **kwargs):
|
||||||
LOG.debug("Running action: %s", self.name)
|
LOG.debug("Running action: %s", self.name)
|
||||||
|
|
||||||
# NOTE: For result is False, set action state fail
|
# NOTE:Some actions(such as migrate) will return None when exception
|
||||||
|
# Only when True is returned, the action state is set to SUCCEEDED
|
||||||
result = self.action.execute()
|
result = self.action.execute()
|
||||||
if result is False:
|
if result is True:
|
||||||
return self.engine.notify(self._db_action,
|
|
||||||
objects.action.State.FAILED)
|
|
||||||
else:
|
|
||||||
return self.engine.notify(self._db_action,
|
return self.engine.notify(self._db_action,
|
||||||
objects.action.State.SUCCEEDED)
|
objects.action.State.SUCCEEDED)
|
||||||
|
else:
|
||||||
|
return self.engine.notify(self._db_action,
|
||||||
|
objects.action.State.FAILED)
|
||||||
|
|
||||||
def do_post_execute(self):
|
def do_post_execute(self):
|
||||||
LOG.debug("Post-condition action: %s", self.name)
|
LOG.debug("Post-condition action: %s", self.name)
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ import eventlet
|
|||||||
import mock
|
import mock
|
||||||
|
|
||||||
from watcher.applier.workflow_engine import default as tflow
|
from watcher.applier.workflow_engine import default as tflow
|
||||||
|
from watcher.common import clients
|
||||||
|
from watcher.common import nova_helper
|
||||||
from watcher import objects
|
from watcher import objects
|
||||||
from watcher.tests.db import base
|
from watcher.tests.db import base
|
||||||
from watcher.tests.objects import utils as obj_utils
|
from watcher.tests.objects import utils as obj_utils
|
||||||
@@ -55,6 +57,32 @@ class TestTaskFlowActionContainer(base.DbTestCase):
|
|||||||
|
|
||||||
self.assertTrue(action.state, objects.action.State.SUCCEEDED)
|
self.assertTrue(action.state, objects.action.State.SUCCEEDED)
|
||||||
|
|
||||||
|
@mock.patch.object(clients.OpenStackClients, 'nova', mock.Mock())
|
||||||
|
def test_execute_with_failed(self):
|
||||||
|
nova_util = nova_helper.NovaHelper()
|
||||||
|
instance = "31b9dd5c-b1fd-4f61-9b68-a47096326dac"
|
||||||
|
nova_util.nova.servers.get.return_value = instance
|
||||||
|
action_plan = obj_utils.create_test_action_plan(
|
||||||
|
self.context, audit_id=self.audit.id,
|
||||||
|
strategy_id=self.strategy.id,
|
||||||
|
state=objects.action.State.ONGOING)
|
||||||
|
|
||||||
|
action = obj_utils.create_test_action(
|
||||||
|
self.context, action_plan_id=action_plan.id,
|
||||||
|
state=objects.action.State.ONGOING,
|
||||||
|
action_type='migrate',
|
||||||
|
input_parameters={"resource_id":
|
||||||
|
instance,
|
||||||
|
"migration_type": "live",
|
||||||
|
"destination_node": "host2",
|
||||||
|
"source_node": "host1"})
|
||||||
|
action_container = tflow.TaskFlowActionContainer(
|
||||||
|
db_action=action,
|
||||||
|
engine=self.engine)
|
||||||
|
action_container.execute()
|
||||||
|
|
||||||
|
self.assertTrue(action.state, objects.action.State.FAILED)
|
||||||
|
|
||||||
@mock.patch('eventlet.spawn')
|
@mock.patch('eventlet.spawn')
|
||||||
def test_execute_with_cancel_action_plan(self, mock_eventlet_spawn):
|
def test_execute_with_cancel_action_plan(self, mock_eventlet_spawn):
|
||||||
action_plan = obj_utils.create_test_action_plan(
|
action_plan = obj_utils.create_test_action_plan(
|
||||||
|
|||||||
Reference in New Issue
Block a user