diff --git a/doc/notification_samples/instance-unshelve-end.json b/doc/notification_samples/instance-unshelve-end.json new file mode 100644 index 0000000000..b581ea49c1 --- /dev/null +++ b/doc/notification_samples/instance-unshelve-end.json @@ -0,0 +1,62 @@ +{ + "event_type":"instance.unshelve.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":null, + "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-unshelve-start.json b/doc/notification_samples/instance-unshelve-start.json new file mode 100644 index 0000000000..3dd1909d41 --- /dev/null +++ b/doc/notification_samples/instance-unshelve-start.json @@ -0,0 +1,62 @@ +{ + "event_type":"instance.unshelve.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":null, + "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":null, + "os_type":null, + "progress":0, + "ramdisk_id":"", + "reservation_id":"r-npxv0e40", + "state":"shelved_offloaded", + "task_state":"unshelving", + "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 0505e8b612..64053ab7a6 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -4332,6 +4332,10 @@ class ComputeManager(manager.Manager): node): LOG.info(_LI('Unshelving'), instance=instance) self._notify_about_instance_usage(context, instance, 'unshelve.start') + compute_utils.notify_about_instance_action(context, instance, + self.host, action=fields.NotificationAction.UNSHELVE, + phase=fields.NotificationPhase.START) + instance.task_state = task_states.SPAWNING instance.save() @@ -4386,6 +4390,9 @@ class ComputeManager(manager.Manager): instance.save(expected_task_state=task_states.SPAWNING) self._update_scheduler_instance_info(context, instance) self._notify_about_instance_usage(context, instance, 'unshelve.end') + compute_utils.notify_about_instance_action(context, instance, + self.host, action=fields.NotificationAction.UNSHELVE, + phase=fields.NotificationPhase.END) @messaging.expected_exceptions(NotImplementedError) @wrap_instance_fault diff --git a/nova/notifications/objects/instance.py b/nova/notifications/objects/instance.py index 6e468593d3..43a68da816 100644 --- a/nova/notifications/objects/instance.py +++ b/nova/notifications/objects/instance.py @@ -302,8 +302,8 @@ class InstanceStateUpdatePayload(base.NotificationPayloadBase): # @base.notification_sample('instance-trigger_crash_dump-end.json') # @base.notification_sample('instance-unrescue-start.json') # @base.notification_sample('instance-unrescue-end.json') -# @base.notification_sample('instance-unshelve-start.json') -# @base.notification_sample('instance-unshelve-end.json') +@base.notification_sample('instance-unshelve-start.json') +@base.notification_sample('instance-unshelve-end.json') @nova_base.NovaObjectRegistry.register_notification class InstanceActionNotification(base.NotificationBase): # Version 1.0: Initial version diff --git a/nova/tests/functional/notification_sample_tests/test_instance.py b/nova/tests/functional/notification_sample_tests/test_instance.py index e0399ca8b1..7f69b43af3 100644 --- a/nova/tests/functional/notification_sample_tests/test_instance.py +++ b/nova/tests/functional/notification_sample_tests/test_instance.py @@ -67,6 +67,7 @@ class TestInstanceNotificationSample( self._test_pause_server, self._test_shelve_server, self._test_shelve_offload_server, + self._test_unshelve_server, self._test_resize_server, ] @@ -321,6 +322,31 @@ class TestInstanceNotificationSample( self.api.post_server_action(server['id'], {'unshelve': None}) self._wait_for_state_change(self.admin_api, server, 'ACTIVE') + def _test_unshelve_server(self, server): + # setting the shelved_offload_time to 0 should set the + # instance status to 'SHELVED_OFFLOADED' + self.flags(shelved_offload_time = 0) + self.api.post_server_action(server['id'], {'shelve': {}}) + self._wait_for_state_change(self.api, server, + expected_status='SHELVED_OFFLOADED') + + post = {'unshelve': None} + self.api.post_server_action(server['id'], post) + self._wait_for_state_change(self.admin_api, server, 'ACTIVE') + self.assertEqual(6, len(fake_notifier.VERSIONED_NOTIFICATIONS)) + self._verify_notification( + 'instance-unshelve-start', + replacements={ + 'reservation_id': server['reservation_id'], + 'uuid': server['id']}, + actual=fake_notifier.VERSIONED_NOTIFICATIONS[4]) + self._verify_notification( + 'instance-unshelve-end', + replacements={ + 'reservation_id': server['reservation_id'], + 'uuid': server['id']}, + actual=fake_notifier.VERSIONED_NOTIFICATIONS[5]) + def _test_suspend_server(self, server): post = {'suspend': {}} self.api.post_server_action(server['id'], post) diff --git a/nova/tests/unit/compute/test_shelve.py b/nova/tests/unit/compute/test_shelve.py index 25be858855..7a56cd88ff 100644 --- a/nova/tests/unit/compute/test_shelve.py +++ b/nova/tests/unit/compute/test_shelve.py @@ -211,7 +211,8 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase): def test_shelve_offload_forced_shutdown(self): self._shelve_offload(clean_shutdown=False) - def test_unshelve(self): + @mock.patch('nova.compute.utils.notify_about_instance_action') + def test_unshelve(self, mock_notify): instance = self._create_fake_instance_obj() instance.task_state = task_states.UNSHELVING instance.save() @@ -295,6 +296,13 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase): self.context, instance, image=image, filter_properties=filter_properties, node=node) + + mock_notify.assert_has_calls([ + mock.call(self.context, instance, 'fake-mini', + action='unshelve', phase='start'), + mock.call(self.context, instance, 'fake-mini', + action='unshelve', phase='end')]) + self.assertNotIn('shelved_at', instance.system_metadata) self.assertNotIn('shelved_image_id', instance.system_metadata) self.assertNotIn('shelved_host', instance.system_metadata) @@ -309,7 +317,8 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase): self.assertFalse(instance.auto_disk_config) @mock.patch('nova.utils.get_image_from_system_metadata') - def test_unshelve_volume_backed(self, mock_image_meta): + @mock.patch('nova.compute.utils.notify_about_instance_action') + def test_unshelve_volume_backed(self, mock_notify, mock_image_meta): instance = self._create_fake_instance_obj() node = test_compute.NODENAME limits = {}