diff --git a/doc/notification_samples/instance-shutdown-end.json b/doc/notification_samples/instance-shutdown-end.json new file mode 100644 index 000000000000..329762f212c7 --- /dev/null +++ b/doc/notification_samples/instance-shutdown-end.json @@ -0,0 +1,62 @@ +{ + "event_type":"instance.shutdown.end", + "payload":{ + "nova_object.data":{ + "architecture":"x86_64", + "availability_zone":null, + "created_at":"2012-10-29T13:42:11Z", + "deleted_at":null, + "display_name":"some-server", + "fault":null, + "host":"compute", + "host_name":"some-server", + "ip_addresses": [{ + "nova_object.name": "IpPayload", + "nova_object.namespace": "nova", + "nova_object.version": "1.0", + "nova_object.data": { + "mac": "fa:16:3e:4c:2c:30", + "address": "192.168.1.3", + "port_uuid": "ce531f90-199f-48c0-816c-13e38010b442", + "meta": {}, + "version": 4, + "label": "private-network", + "device_name": "tapce531f90-19" + } + }], + "kernel_id":"", + "launched_at":"2012-10-29T13:42:11Z", + "image_uuid": "155d900f-4e14-4e4c-a73d-069cbf4541e6", + "metadata":{}, + "node":"fake-mini", + "os_type":null, + "progress":0, + "ramdisk_id":"", + "reservation_id":"r-npxv0e40", + "state":"active", + "task_state":"deleting", + "power_state":"running", + "tenant_id":"6f70656e737461636b20342065766572", + "terminated_at":null, + "flavor": { + "nova_object.name": "FlavorPayload", + "nova_object.data": { + "flavorid": "a22d5517-147c-4147-a0d1-e698df5cd4e3", + "root_gb": 1, + "vcpus": 1, + "ephemeral_gb": 0, + "memory_mb": 512 + }, + "nova_object.version": "1.0", + "nova_object.namespace": "nova" + }, + "user_id":"fake", + "uuid":"178b0921-8f85-4257-88b6-2e743b5a975c" + }, + "nova_object.name":"InstanceActionPayload", + "nova_object.namespace":"nova", + "nova_object.version":"1.0" + }, + "priority":"INFO", + "publisher_id":"nova-compute:compute" +} diff --git a/doc/notification_samples/instance-shutdown-start.json b/doc/notification_samples/instance-shutdown-start.json new file mode 100644 index 000000000000..4a149c38d39c --- /dev/null +++ b/doc/notification_samples/instance-shutdown-start.json @@ -0,0 +1,62 @@ +{ + "event_type":"instance.shutdown.start", + "payload":{ + "nova_object.data":{ + "architecture":"x86_64", + "availability_zone":null, + "created_at":"2012-10-29T13:42:11Z", + "deleted_at":null, + "display_name":"some-server", + "fault":null, + "host":"compute", + "host_name":"some-server", + "ip_addresses": [{ + "nova_object.name": "IpPayload", + "nova_object.namespace": "nova", + "nova_object.version": "1.0", + "nova_object.data": { + "mac": "fa:16:3e:4c:2c:30", + "address": "192.168.1.3", + "port_uuid": "ce531f90-199f-48c0-816c-13e38010b442", + "meta": {}, + "version": 4, + "label": "private-network", + "device_name": "tapce531f90-19" + } + }], + "kernel_id":"", + "launched_at":"2012-10-29T13:42:11Z", + "image_uuid": "155d900f-4e14-4e4c-a73d-069cbf4541e6", + "metadata":{}, + "node":"fake-mini", + "os_type":null, + "progress":0, + "ramdisk_id":"", + "reservation_id":"r-npxv0e40", + "state":"active", + "task_state":"deleting", + "power_state":"running", + "tenant_id":"6f70656e737461636b20342065766572", + "terminated_at":null, + "flavor": { + "nova_object.name": "FlavorPayload", + "nova_object.data": { + "flavorid": "a22d5517-147c-4147-a0d1-e698df5cd4e3", + "root_gb": 1, + "vcpus": 1, + "ephemeral_gb": 0, + "memory_mb": 512 + }, + "nova_object.version": "1.0", + "nova_object.namespace": "nova" + }, + "user_id":"fake", + "uuid":"178b0921-8f85-4257-88b6-2e743b5a975c" + }, + "nova_object.name":"InstanceActionPayload", + "nova_object.namespace":"nova", + "nova_object.version":"1.0" + }, + "priority":"INFO", + "publisher_id":"nova-compute:compute" +} diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 98d1312f7751..dfaee532ebeb 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -2175,6 +2175,9 @@ class ComputeManager(manager.Manager): if notify: self._notify_about_instance_usage(context, instance, "shutdown.start") + compute_utils.notify_about_instance_action(context, instance, + self.host, action=fields.NotificationAction.SHUTDOWN, + phase=fields.NotificationPhase.START) network_info = compute_utils.get_nw_info_for_instance(instance) @@ -2250,6 +2253,9 @@ class ComputeManager(manager.Manager): if notify: self._notify_about_instance_usage(context, instance, "shutdown.end") + compute_utils.notify_about_instance_action(context, instance, + self.host, action=fields.NotificationAction.SHUTDOWN, + phase=fields.NotificationPhase.END) def _cleanup_volumes(self, context, instance_uuid, bdms, raise_exc=True): exc_info = None diff --git a/nova/notifications/objects/instance.py b/nova/notifications/objects/instance.py index a5accc494987..189f6bef5471 100644 --- a/nova/notifications/objects/instance.py +++ b/nova/notifications/objects/instance.py @@ -259,8 +259,8 @@ class InstanceStateUpdatePayload(base.NotificationPayloadBase): @base.notification_sample('instance-power_off-end.json') # @base.notification_sample('instance-reboot-start.json') # @base.notification_sample('instance-reboot-end.json') -# @base.notification_sample('instance-shutdown-start.json') -# @base.notification_sample('instance-shutdown-end.json') +@base.notification_sample('instance-shutdown-start.json') +@base.notification_sample('instance-shutdown-end.json') # @base.notification_sample('instance-snapshot-start.json') # @base.notification_sample('instance-snapshot-end.json') # @base.notification_sample('instance-add_fixed_ip-start.json') diff --git a/nova/tests/functional/notification_sample_tests/test_instance.py b/nova/tests/functional/notification_sample_tests/test_instance.py index 2858ae571a12..9c94a30aac38 100644 --- a/nova/tests/functional/notification_sample_tests/test_instance.py +++ b/nova/tests/functional/notification_sample_tests/test_instance.py @@ -81,8 +81,7 @@ class TestInstanceNotificationSample( extra_params={'networks': [{'port': self.neutron.port_1['id']}]}) self.api.delete_server(server['id']) self._wait_until_deleted(server) - - self.assertEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS)) + self.assertEqual(4, len(fake_notifier.VERSIONED_NOTIFICATIONS)) self._verify_notification( 'instance-delete-start', replacements={ @@ -90,11 +89,23 @@ class TestInstanceNotificationSample( 'uuid': server['id']}, actual=fake_notifier.VERSIONED_NOTIFICATIONS[0]) self._verify_notification( - 'instance-delete-end', + 'instance-shutdown-start', replacements={ 'reservation_id': server['reservation_id'], 'uuid': server['id']}, actual=fake_notifier.VERSIONED_NOTIFICATIONS[1]) + self._verify_notification( + 'instance-shutdown-end', + replacements={ + 'reservation_id': server['reservation_id'], + 'uuid': server['id']}, + actual=fake_notifier.VERSIONED_NOTIFICATIONS[2]) + self._verify_notification( + 'instance-delete-end', + replacements={ + 'reservation_id': server['reservation_id'], + 'uuid': server['id']}, + actual=fake_notifier.VERSIONED_NOTIFICATIONS[3]) def _verify_instance_update_steps(self, steps, notifications, initial=None): diff --git a/nova/tests/unit/compute/test_compute_mgr.py b/nova/tests/unit/compute/test_compute_mgr.py index b0390b2b2ad4..afaf8925b073 100755 --- a/nova/tests/unit/compute/test_compute_mgr.py +++ b/nova/tests/unit/compute/test_compute_mgr.py @@ -1151,6 +1151,33 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase): mock_instance_save.assert_called_once_with() self.assertIsNone(instance.task_state) + @mock.patch('nova.context.RequestContext.elevated') + @mock.patch('nova.compute.utils.get_nw_info_for_instance') + @mock.patch( + 'nova.compute.manager.ComputeManager._get_instance_block_device_info') + @mock.patch('nova.virt.driver.ComputeDriver.destroy') + @mock.patch('nova.virt.fake.FakeDriver.get_volume_connector') + @mock.patch('nova.compute.utils.notify_about_instance_action') + @mock.patch( + 'nova.compute.manager.ComputeManager._notify_about_instance_usage') + def test_shutdown_instance_versioned_notifications(self, + mock_notify_unversioned, mock_notify, mock_connector, + mock_destroy, mock_blk_device_info, mock_nw_info, mock_elevated): + mock_elevated.return_value = self.context + instance = fake_instance.fake_instance_obj( + self.context, + uuid=uuids.instance, + vm_state=vm_states.ERROR, + task_state=task_states.DELETING) + bdms = [mock.Mock(id=1, is_volume=True)] + self.compute._shutdown_instance(self.context, instance, bdms, + notify=True, try_deallocate_networks=False) + mock_notify.assert_has_calls([ + mock.call(self.context, instance, 'fake-mini', + action='shutdown', phase='start'), + mock.call(self.context, instance, 'fake-mini', + action='shutdown', phase='end')]) + @mock.patch('nova.context.RequestContext.elevated') @mock.patch('nova.compute.utils.get_nw_info_for_instance') @mock.patch(