Added action_plan.execution.* actions
Partially Implements: blueprint action-plan-versioned-notifications-api Change-Id: I9bd346c19f1cafcaa720de554fd9c056c76de050
This commit is contained in:
@@ -18,6 +18,9 @@
|
||||
import mock
|
||||
|
||||
from watcher.applier.action_plan import default
|
||||
from watcher.applier import default as ap_applier
|
||||
from watcher import notifications
|
||||
from watcher import objects
|
||||
from watcher.objects import action_plan as ap_objects
|
||||
from watcher.tests.db import base
|
||||
from watcher.tests.objects import utils as obj_utils
|
||||
@@ -25,17 +28,67 @@ from watcher.tests.objects import utils as obj_utils
|
||||
|
||||
class TestDefaultActionPlanHandler(base.DbTestCase):
|
||||
|
||||
class FakeApplierException(Exception):
|
||||
pass
|
||||
|
||||
def setUp(self):
|
||||
super(TestDefaultActionPlanHandler, self).setUp()
|
||||
|
||||
p_action_plan_notifications = mock.patch.object(
|
||||
notifications, 'action_plan', autospec=True)
|
||||
self.m_action_plan_notifications = p_action_plan_notifications.start()
|
||||
self.addCleanup(p_action_plan_notifications.stop)
|
||||
|
||||
obj_utils.create_test_goal(self.context)
|
||||
obj_utils.create_test_strategy(self.context)
|
||||
obj_utils.create_test_audit(self.context)
|
||||
self.action_plan = obj_utils.create_test_action_plan(self.context)
|
||||
|
||||
def test_launch_action_plan(self):
|
||||
@mock.patch.object(objects.ActionPlan, "get_by_uuid")
|
||||
def test_launch_action_plan(self, m_get_action_plan):
|
||||
m_get_action_plan.return_value = self.action_plan
|
||||
command = default.DefaultActionPlanHandler(
|
||||
self.context, mock.MagicMock(), self.action_plan.uuid)
|
||||
command.execute()
|
||||
action_plan = ap_objects.ActionPlan.get_by_uuid(
|
||||
self.context, self.action_plan.uuid)
|
||||
self.assertEqual(ap_objects.State.SUCCEEDED, action_plan.state)
|
||||
|
||||
expected_calls = [
|
||||
mock.call(self.context, self.action_plan,
|
||||
action=objects.fields.NotificationAction.EXECUTION,
|
||||
phase=objects.fields.NotificationPhase.START),
|
||||
mock.call(self.context, self.action_plan,
|
||||
action=objects.fields.NotificationAction.EXECUTION,
|
||||
phase=objects.fields.NotificationPhase.END)]
|
||||
|
||||
self.assertEqual(ap_objects.State.SUCCEEDED, self.action_plan.state)
|
||||
|
||||
self.assertEqual(
|
||||
expected_calls,
|
||||
self.m_action_plan_notifications
|
||||
.send_action_notification
|
||||
.call_args_list)
|
||||
|
||||
@mock.patch.object(ap_applier.DefaultApplier, "execute")
|
||||
@mock.patch.object(objects.ActionPlan, "get_by_uuid")
|
||||
def test_launch_action_plan_with_error(self, m_get_action_plan, m_execute):
|
||||
m_get_action_plan.return_value = self.action_plan
|
||||
m_execute.side_effect = self.FakeApplierException
|
||||
command = default.DefaultActionPlanHandler(
|
||||
self.context, mock.MagicMock(), self.action_plan.uuid)
|
||||
command.execute()
|
||||
|
||||
expected_calls = [
|
||||
mock.call(self.context, self.action_plan,
|
||||
action=objects.fields.NotificationAction.EXECUTION,
|
||||
phase=objects.fields.NotificationPhase.START),
|
||||
mock.call(self.context, self.action_plan,
|
||||
action=objects.fields.NotificationAction.EXECUTION,
|
||||
priority=objects.fields.NotificationPriority.ERROR,
|
||||
phase=objects.fields.NotificationPhase.ERROR)]
|
||||
|
||||
self.assertEqual(ap_objects.State.FAILED, self.action_plan.state)
|
||||
|
||||
self.assertEqual(
|
||||
expected_calls,
|
||||
self.m_action_plan_notifications
|
||||
.send_action_notification
|
||||
.call_args_list)
|
||||
|
||||
Reference in New Issue
Block a user