diff --git a/doc/notification_samples/server_group-delete.json b/doc/notification_samples/server_group-delete.json new file mode 100644 index 000000000000..c6bfee800fe1 --- /dev/null +++ b/doc/notification_samples/server_group-delete.json @@ -0,0 +1,19 @@ +{ + "priority": "INFO", + "payload": { + "nova_object.version": "1.0", + "nova_object.namespace": "nova", + "nova_object.name": "ServerGroupPayload", + "nova_object.data": { + "uuid": "788608ec-ebdc-45c5-bc7f-e5f24ab92c80", + "name": "test-server-group", + "project_id": "6f70656e737461636b20342065766572", + "user_id": "fake", + "policies": ["anti-affinity"], + "members": [], + "hosts": null + } + }, + "event_type": "server_group.delete", + "publisher_id": "nova-api:fake-mini" +} diff --git a/nova/notifications/objects/server_group.py b/nova/notifications/objects/server_group.py index e42ef722f260..cafb56659159 100644 --- a/nova/notifications/objects/server_group.py +++ b/nova/notifications/objects/server_group.py @@ -50,6 +50,7 @@ class ServerGroupPayload(base.NotificationPayloadBase): @base.notification_sample('server_group-create.json') +@base.notification_sample('server_group-delete.json') @nova_base.NovaObjectRegistry.register_notification class ServerGroupNotification(base.NotificationBase): # Version 1.0: Initial version diff --git a/nova/objects/instance_group.py b/nova/objects/instance_group.py index ae9fedebf128..53d4bb1c6198 100644 --- a/nova/objects/instance_group.py +++ b/nova/objects/instance_group.py @@ -436,6 +436,10 @@ class InstanceGroup(base.NovaPersistentObject, base.NovaObject, self.obj_reset_changes() compute_utils.notify_about_server_group_update(self._context, "delete", payload) + compute_utils.notify_about_server_group_action( + context=self._context, + group=self, + action=fields.NotificationAction.DELETE) @base.remotable_classmethod def add_members(cls, context, group_uuid, instance_uuids): diff --git a/nova/tests/functional/notification_sample_tests/test_server_group.py b/nova/tests/functional/notification_sample_tests/test_server_group.py index 3f1290680c6b..d8675a8754f6 100644 --- a/nova/tests/functional/notification_sample_tests/test_server_group.py +++ b/nova/tests/functional/notification_sample_tests/test_server_group.py @@ -17,7 +17,7 @@ from nova.tests.unit import fake_notifier class TestServerGroupNotificationSample( notification_sample_base.NotificationSampleTestBase): - def test_server_group_create(self): + def test_server_group_create_delete(self): group_req = { "name": "test-server-group", "policies": ["anti-affinity"]} @@ -28,3 +28,12 @@ class TestServerGroupNotificationSample( 'server_group-create', replacements={'uuid': group['id']}, actual=fake_notifier.VERSIONED_NOTIFICATIONS[0]) + + fake_notifier.reset() + self.api.delete_server_group(group['id']) + + self.assertEqual(1, len(fake_notifier.VERSIONED_NOTIFICATIONS)) + self._verify_notification( + 'server_group-delete', + replacements={'uuid': group['id']}, + actual=fake_notifier.VERSIONED_NOTIFICATIONS[0]) diff --git a/nova/tests/unit/objects/test_instance_group.py b/nova/tests/unit/objects/test_instance_group.py index be7f08978975..7bdea163895d 100644 --- a/nova/tests/unit/objects/test_instance_group.py +++ b/nova/tests/unit/objects/test_instance_group.py @@ -189,12 +189,20 @@ class _TestInstanceGroupObject(object): group=group_matcher, action='create') + @mock.patch('nova.compute.utils.notify_about_server_group_action') @mock.patch('nova.compute.utils.notify_about_server_group_update') @mock.patch('nova.objects.InstanceGroup._destroy_in_db') - def test_destroy(self, mock_db_delete, mock_notify): + def test_destroy(self, mock_db_delete, mock_notify, mock_notify_action): obj = objects.InstanceGroup(context=self.context) obj.uuid = _DB_UUID obj.destroy() + + group_matcher = test_utils.CustomMockCallMatcher( + lambda group: group.uuid == _DB_UUID) + + mock_notify_action.assert_called_once_with(context=obj._context, + group=group_matcher, + action='delete') mock_db_delete.assert_called_once_with(self.context, _DB_UUID) mock_notify.assert_called_once_with(self.context, "delete", {'server_group_id': _DB_UUID})