diff --git a/doc/notification_samples/instance-resume-end.json b/doc/notification_samples/instance-resume-end.json new file mode 100644 index 000000000000..bf2b189acba2 --- /dev/null +++ b/doc/notification_samples/instance-resume-end.json @@ -0,0 +1,62 @@ +{ + "event_type":"instance.resume.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-resume-start.json b/doc/notification_samples/instance-resume-start.json new file mode 100644 index 000000000000..18236fe3e11c --- /dev/null +++ b/doc/notification_samples/instance-resume-start.json @@ -0,0 +1,62 @@ +{ + "event_type":"instance.resume.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":"suspended", + "task_state":"resuming", + "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 82aa298f99ff..7cca067f4bb1 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -4131,6 +4131,10 @@ class ComputeManager(manager.Manager): LOG.info(_LI('Resuming'), instance=instance) self._notify_about_instance_usage(context, instance, 'resume.start') + compute_utils.notify_about_instance_action(context, instance, + self.host, action=fields.NotificationAction.RESUME, + phase=fields.NotificationPhase.START) + network_info = self.network_api.get_instance_nw_info(context, instance) block_device_info = self._get_instance_block_device_info( context, instance) @@ -4149,6 +4153,9 @@ class ComputeManager(manager.Manager): instance.task_state = None instance.save(expected_task_state=task_states.RESUMING) self._notify_about_instance_usage(context, instance, 'resume.end') + compute_utils.notify_about_instance_action(context, instance, + self.host, action=fields.NotificationAction.RESUME, + phase=fields.NotificationPhase.END) @wrap_exception() @reverts_task_state diff --git a/nova/notifications/objects/instance.py b/nova/notifications/objects/instance.py index d15c490dd8a0..a7eb9ab44545 100644 --- a/nova/notifications/objects/instance.py +++ b/nova/notifications/objects/instance.py @@ -267,8 +267,8 @@ class InstanceStateUpdatePayload(base.NotificationPayloadBase): # @base.notification_sample('instance-add_fixed_ip-end.json') @base.notification_sample('instance-shelve-start.json') @base.notification_sample('instance-shelve-end.json') -# @base.notification_sample('instance-resume-start.json') -# @base.notification_sample('instance-resume-end.json') +@base.notification_sample('instance-resume-start.json') +@base.notification_sample('instance-resume-end.json') @base.notification_sample('instance-restore-start.json') @base.notification_sample('instance-restore-end.json') # @base.notification_sample('instance-evacuate.json') diff --git a/nova/tests/functional/notification_sample_tests/test_instance.py b/nova/tests/functional/notification_sample_tests/test_instance.py index f3fc1f5a19ec..87753da29b88 100644 --- a/nova/tests/functional/notification_sample_tests/test_instance.py +++ b/nova/tests/functional/notification_sample_tests/test_instance.py @@ -63,6 +63,7 @@ class TestInstanceNotificationSample( self._test_power_on_server, self._test_restore_server, self._test_suspend_server, + self._test_resume_server, self._test_pause_server, self._test_shelve_server, self._test_resize_server, @@ -299,10 +300,27 @@ class TestInstanceNotificationSample( 'uuid': server['id']}, actual=fake_notifier.VERSIONED_NOTIFICATIONS[1]) + def _test_resume_server(self, server): post = {'resume': None} self.api.post_server_action(server['id'], post) self._wait_for_state_change(self.admin_api, server, 'ACTIVE') + self.assertEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS)) + self._verify_notification( + 'instance-resume-start', + replacements={ + 'reservation_id': server['reservation_id'], + 'uuid': server['id']}, + actual=fake_notifier.VERSIONED_NOTIFICATIONS[0]) + self._verify_notification( + 'instance-resume-end', + replacements={ + 'reservation_id': server['reservation_id'], + 'uuid': server['id']}, + actual=fake_notifier.VERSIONED_NOTIFICATIONS[1]) + + self.flags(reclaim_instance_interval=0) + def _test_pause_server(self, server): self.api.post_server_action(server['id'], {'pause': {}}) self._wait_for_state_change(self.api, server, 'PAUSED') diff --git a/nova/tests/unit/compute/test_compute.py b/nova/tests/unit/compute/test_compute.py index 19bfb83b85ad..254b0989cc85 100644 --- a/nova/tests/unit/compute/test_compute.py +++ b/nova/tests/unit/compute/test_compute.py @@ -2518,8 +2518,12 @@ class ComputeTestCase(BaseTestCase): self.compute.terminate_instance(self.context, instance, [], []) - def test_resume_notifications(self): + @mock.patch.object(nova.compute.utils, 'notify_about_instance_action') + @mock.patch('nova.context.RequestContext.elevated') + def test_resume_notifications(self, mock_context, mock_notify): # ensure instance can be suspended and resumed. + context = self.context + mock_context.return_value = context instance = self._create_fake_instance_obj() self.compute.build_and_run_instance(self.context, instance, {}, {}, {}, block_device_mapping=[]) @@ -2536,6 +2540,11 @@ class ComputeTestCase(BaseTestCase): msg = fake_notifier.NOTIFICATIONS[5] self.assertEqual(msg.event_type, 'compute.instance.resume.end') + mock_notify.assert_has_calls([ + mock.call(context, instance, 'fake-mini', + action='resume', phase='start'), + mock.call(context, instance, 'fake-mini', + action='resume', phase='end')]) self.compute.terminate_instance(self.context, instance, [], []) def test_resume_no_old_state(self):