Notification Cancel Action Plan

This patch adds Notifications for cancel action plan
operation.

Change-Id: I5a89a80729349e3db43ca35ff9fbe8579e86b3b1
Implements: blueprint notifications-actionplan-cancel
This commit is contained in:
aditi
2017-08-11 10:57:23 +00:00
parent e74095da1f
commit d4e6e82dd2
14 changed files with 800 additions and 19 deletions

View File

@@ -353,3 +353,133 @@ class TestActionNotification(base.DbTestCase):
},
notification
)
def test_send_action_cancel(self):
action = utils.create_test_action(
mock.Mock(), state=objects.action.State.PENDING,
action_type='nop', input_parameters={'param1': 1, 'param2': 2},
parents=[], action_plan_id=self.action_plan.id)
notifications.action.send_cancel_notification(
mock.MagicMock(), action, 'cancel', phase='start', host='node0')
# The 1st notification is because we created the audit object.
# The 2nd notification is because we created the action plan object.
self.assertEqual(4, self.m_notifier.info.call_count)
notification = self.m_notifier.info.call_args[1]
self.assertEqual("infra-optim:node0", self.m_notifier.publisher_id)
self.assertDictEqual(
{
'event_type': 'action.cancel.start',
'payload': {
'watcher_object.namespace': 'watcher',
'watcher_object.version': '1.0',
'watcher_object.name': 'ActionCancelPayload',
'watcher_object.data': {
'uuid': '10a47dd1-4874-4298-91cf-eff046dbdb8d',
'input_parameters': {
'param2': 2,
'param1': 1
},
'created_at': '2016-10-18T09:52:05Z',
'fault': None,
'updated_at': None,
'state': 'PENDING',
'action_plan': {
'watcher_object.namespace': 'watcher',
'watcher_object.version': '1.0',
'watcher_object.name': 'TerseActionPlanPayload',
'watcher_object.data': {
'uuid': '76be87bd-3422-43f9-93a0-e85a577e3061',
'global_efficacy': {},
'created_at': '2016-10-18T09:52:05Z',
'updated_at': None,
'state': 'ONGOING',
'audit_uuid': '10a47dd1-4874-4298'
'-91cf-eff046dbdb8d',
'strategy_uuid': 'cb3d0b58-4415-4d90'
'-b75b-1e96878730e3',
'deleted_at': None
}
},
'parents': [],
'action_type': 'nop',
'deleted_at': None
}
}
},
notification
)
def test_send_action_cancel_with_error(self):
action = utils.create_test_action(
mock.Mock(), state=objects.action.State.FAILED,
action_type='nop', input_parameters={'param1': 1, 'param2': 2},
parents=[], action_plan_id=self.action_plan.id)
try:
# This is to load the exception in sys.exc_info()
raise exception.WatcherException("TEST")
except exception.WatcherException:
notifications.action.send_cancel_notification(
mock.MagicMock(), action, 'cancel', phase='error',
host='node0', priority='error')
self.assertEqual(1, self.m_notifier.error.call_count)
notification = self.m_notifier.error.call_args[1]
self.assertEqual("infra-optim:node0", self.m_notifier.publisher_id)
self.assertDictEqual(
{
'event_type': 'action.cancel.error',
'payload': {
'watcher_object.namespace': 'watcher',
'watcher_object.version': '1.0',
'watcher_object.name': 'ActionCancelPayload',
'watcher_object.data': {
'uuid': '10a47dd1-4874-4298-91cf-eff046dbdb8d',
'input_parameters': {
'param2': 2,
'param1': 1
},
'created_at': '2016-10-18T09:52:05Z',
'fault': {
'watcher_object.data': {
'exception': u'WatcherException',
'exception_message': u'TEST',
'function_name': (
'test_send_action_cancel_with_error'),
'module_name': (
'watcher.tests.notifications.'
'test_action_notification')
},
'watcher_object.name': 'ExceptionPayload',
'watcher_object.namespace': 'watcher',
'watcher_object.version': '1.0'
},
'updated_at': None,
'state': 'FAILED',
'action_plan': {
'watcher_object.namespace': 'watcher',
'watcher_object.version': '1.0',
'watcher_object.name': 'TerseActionPlanPayload',
'watcher_object.data': {
'uuid': '76be87bd-3422-43f9-93a0-e85a577e3061',
'global_efficacy': {},
'created_at': '2016-10-18T09:52:05Z',
'updated_at': None,
'state': 'ONGOING',
'audit_uuid': '10a47dd1-4874-4298'
'-91cf-eff046dbdb8d',
'strategy_uuid': 'cb3d0b58-4415-4d90'
'-b75b-1e96878730e3',
'deleted_at': None
}
},
'parents': [],
'action_type': 'nop',
'deleted_at': None
}
}
},
notification
)

View File

@@ -427,3 +427,164 @@ class TestActionPlanNotification(base.DbTestCase):
},
notification
)
def test_send_action_plan_cancel(self):
action_plan = utils.create_test_action_plan(
mock.Mock(), state=objects.action_plan.State.ONGOING,
audit_id=self.audit.id, strategy_id=self.strategy.id,
audit=self.audit, strategy=self.strategy)
notifications.action_plan.send_cancel_notification(
mock.MagicMock(), action_plan, host='node0',
action='cancel', phase='start')
# The 1st notification is because we created the audit object.
# The 2nd notification is because we created the action plan object.
self.assertEqual(3, self.m_notifier.info.call_count)
notification = self.m_notifier.info.call_args[1]
self.assertEqual("infra-optim:node0", self.m_notifier.publisher_id)
self.assertDictEqual(
{
"event_type": "action_plan.cancel.start",
"payload": {
"watcher_object.data": {
"created_at": "2016-10-18T09:52:05Z",
"deleted_at": None,
"fault": None,
"audit_uuid": "10a47dd1-4874-4298-91cf-eff046dbdb8d",
"audit": {
"watcher_object.namespace": "watcher",
"watcher_object.name": "TerseAuditPayload",
"watcher_object.version": "1.1",
"watcher_object.data": {
"interval": None,
"next_run_time": None,
"auto_trigger": False,
"parameters": {},
"uuid": "10a47dd1-4874-4298-91cf-eff046dbdb8d",
"strategy_uuid": None,
"goal_uuid": (
"f7ad87ae-4298-91cf-93a0-f35a852e3652"),
"deleted_at": None,
"scope": [],
"state": "PENDING",
"updated_at": None,
"created_at": "2016-10-18T09:52:05Z",
"audit_type": "ONESHOT"
}
},
"global_efficacy": {},
"state": "ONGOING",
"strategy_uuid": (
"cb3d0b58-4415-4d90-b75b-1e96878730e3"),
"strategy": {
"watcher_object.data": {
"created_at": "2016-10-18T09:52:05Z",
"deleted_at": None,
"display_name": "test strategy",
"name": "TEST",
"parameters_spec": {},
"updated_at": None,
"uuid": "cb3d0b58-4415-4d90-b75b-1e96878730e3"
},
"watcher_object.name": "StrategyPayload",
"watcher_object.namespace": "watcher",
"watcher_object.version": "1.0"
},
"updated_at": None,
"uuid": "76be87bd-3422-43f9-93a0-e85a577e3061"
},
"watcher_object.name": "ActionPlanCancelPayload",
"watcher_object.namespace": "watcher",
"watcher_object.version": "1.0"
}
},
notification
)
def test_send_action_plan_cancel_with_error(self):
action_plan = utils.create_test_action_plan(
mock.Mock(), state=objects.action_plan.State.ONGOING,
audit_id=self.audit.id, strategy_id=self.strategy.id,
audit=self.audit, strategy=self.strategy)
try:
# This is to load the exception in sys.exc_info()
raise exception.WatcherException("TEST")
except exception.WatcherException:
notifications.action_plan.send_cancel_notification(
mock.MagicMock(), action_plan, host='node0',
action='cancel', priority='error', phase='error')
self.assertEqual(1, self.m_notifier.error.call_count)
notification = self.m_notifier.error.call_args[1]
self.assertEqual("infra-optim:node0", self.m_notifier.publisher_id)
self.assertDictEqual(
{
"event_type": "action_plan.cancel.error",
"payload": {
"watcher_object.data": {
"created_at": "2016-10-18T09:52:05Z",
"deleted_at": None,
"fault": {
"watcher_object.data": {
"exception": "WatcherException",
"exception_message": "TEST",
"function_name": (
"test_send_action_plan_cancel_with_error"),
"module_name": "watcher.tests.notifications."
"test_action_plan_notification"
},
"watcher_object.name": "ExceptionPayload",
"watcher_object.namespace": "watcher",
"watcher_object.version": "1.0"
},
"audit_uuid": "10a47dd1-4874-4298-91cf-eff046dbdb8d",
"audit": {
"watcher_object.data": {
"interval": None,
"next_run_time": None,
"auto_trigger": False,
"parameters": {},
"uuid": "10a47dd1-4874-4298-91cf-eff046dbdb8d",
"strategy_uuid": None,
"goal_uuid": (
"f7ad87ae-4298-91cf-93a0-f35a852e3652"),
"deleted_at": None,
"scope": [],
"state": "PENDING",
"updated_at": None,
"created_at": "2016-10-18T09:52:05Z",
"audit_type": "ONESHOT"
},
"watcher_object.name": "TerseAuditPayload",
"watcher_object.namespace": "watcher",
"watcher_object.version": "1.1"
},
"global_efficacy": {},
"state": "ONGOING",
"strategy_uuid": (
"cb3d0b58-4415-4d90-b75b-1e96878730e3"),
"strategy": {
"watcher_object.data": {
"created_at": "2016-10-18T09:52:05Z",
"deleted_at": None,
"display_name": "test strategy",
"name": "TEST",
"parameters_spec": {},
"updated_at": None,
"uuid": "cb3d0b58-4415-4d90-b75b-1e96878730e3"
},
"watcher_object.name": "StrategyPayload",
"watcher_object.namespace": "watcher",
"watcher_object.version": "1.0"
},
"updated_at": None,
"uuid": "76be87bd-3422-43f9-93a0-e85a577e3061"
},
"watcher_object.name": "ActionPlanCancelPayload",
"watcher_object.namespace": "watcher",
"watcher_object.version": "1.0"
}
},
notification
)

View File

@@ -250,7 +250,7 @@ class TestNotificationBase(testbase.TestCase):
expected_notification_fingerprints = {
'EventType': '1.3-4258a2c86eca79fd34a7dffe1278eab9',
'EventType': '1.3-bc4f4bc4a497d789e5a3c30f921edae1',
'ExceptionNotification': '1.0-9b69de0724fda8310d05e18418178866',
'ExceptionPayload': '1.0-4516ae282a55fe2fd5c754967ee6248b',
'NotificationPublisher': '1.0-bbbc1402fb0e443a3eb227cc52b61545',
@@ -277,6 +277,8 @@ expected_notification_fingerprints = {
'ActionPlanUpdateNotification': '1.0-9b69de0724fda8310d05e18418178866',
'ActionPlanUpdatePayload': '1.0-3e1a348a0579c6c43c1c3d7257e3f26b',
'ActionPlanActionNotification': '1.0-9b69de0724fda8310d05e18418178866',
'ActionPlanCancelNotification': '1.0-9b69de0724fda8310d05e18418178866',
'ActionCancelNotification': '1.0-9b69de0724fda8310d05e18418178866',
'ActionCreateNotification': '1.0-9b69de0724fda8310d05e18418178866',
'ActionCreatePayload': '1.0-519b93b7450319d8928b4b6e6362df31',
'ActionDeleteNotification': '1.0-9b69de0724fda8310d05e18418178866',
@@ -287,6 +289,8 @@ expected_notification_fingerprints = {
'ActionStateUpdatePayload': '1.0-1a1b606bf14a2c468800c2b010801ce5',
'ActionUpdateNotification': '1.0-9b69de0724fda8310d05e18418178866',
'ActionUpdatePayload': '1.0-03306c7e7f4d49ac328c261eff6b30b8',
'ActionPlanCancelPayload': '1.0-d9f134708e06cf2ff2d3b8d522ac2aa8',
'ActionCancelPayload': '1.0-bff9f820a2abf7bb6d7027b7450157df',
'TerseActionPlanPayload': '1.0-42bf7a5585cc111a9a4dbc008a04c67e',
'ServiceUpdateNotification': '1.0-9b69de0724fda8310d05e18418178866',
'ServicePayload': '1.0-9c5a9bc51e6606e0ec3cf95baf698f4f',