diff --git a/doc/notification_samples/instance-pause-end.json b/doc/notification_samples/instance-pause-end.json new file mode 100644 index 000000000000..f277828c4b45 --- /dev/null +++ b/doc/notification_samples/instance-pause-end.json @@ -0,0 +1,63 @@ +{ + "event_type":"instance.pause.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":"paused", + "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-pause-start.json b/doc/notification_samples/instance-pause-start.json new file mode 100644 index 000000000000..cf9739f178b3 --- /dev/null +++ b/doc/notification_samples/instance-pause-start.json @@ -0,0 +1,63 @@ +{ + "event_type":"instance.pause.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":"pausing", + "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 6cfc4d49bb5a..04e2160c9c9c 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -3983,12 +3983,18 @@ class ComputeManager(manager.Manager): context = context.elevated() LOG.info(_LI('Pausing'), context=context, instance=instance) self._notify_about_instance_usage(context, instance, 'pause.start') + compute_utils.notify_about_instance_action(context, instance, + self.host, action=fields.NotificationAction.PAUSE, + phase=fields.NotificationPhase.START) self.driver.pause(instance) instance.power_state = self._get_power_state(context, instance) instance.vm_state = vm_states.PAUSED instance.task_state = None instance.save(expected_task_state=task_states.PAUSING) self._notify_about_instance_usage(context, instance, 'pause.end') + compute_utils.notify_about_instance_action(context, instance, + self.host, action=fields.NotificationAction.PAUSE, + phase=fields.NotificationPhase.END) @wrap_exception() @reverts_task_state diff --git a/nova/notifications/objects/instance.py b/nova/notifications/objects/instance.py index 9a53157574d9..eb240f58617c 100644 --- a/nova/notifications/objects/instance.py +++ b/nova/notifications/objects/instance.py @@ -223,8 +223,8 @@ class InstanceStateUpdatePayload(base.NotificationPayloadBase): @base.notification_sample('instance-delete-start.json') @base.notification_sample('instance-delete-end.json') -# @base.notification_sample('instance-pause-start.json') -# @base.notification_sample('instance-pause-end.json') +@base.notification_sample('instance-pause-start.json') +@base.notification_sample('instance-pause-end.json') # @base.notification_sample('instance-unpause-start.json') # @base.notification_sample('instance-unpause-end.json') # @base.notification_sample('instance-resize-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 a28cc5675c4b..18cadc92083e 100644 --- a/nova/tests/functional/notification_sample_tests/test_instance.py +++ b/nova/tests/functional/notification_sample_tests/test_instance.py @@ -243,8 +243,7 @@ class TestInstanceNotificationSample( 'uuid': server['id']}, actual=fake_notifier.VERSIONED_NOTIFICATIONS[1]) - -def test_create_suspend_server(self): + def test_create_suspend_server(self): server = self._boot_a_server( extra_params={'networks': [{'port': self.neutron.port_1['id']}]}) @@ -267,3 +266,26 @@ def test_create_suspend_server(self): notification_sample_base.NotificationSampleTestBase.ANY, 'uuid': server['id']}, actual=fake_notifier.VERSIONED_NOTIFICATIONS[1]) + + def test_create_pause_server(self): + server = self._boot_a_server( + extra_params={'networks': + [{'port': self.neutron.port_1['id']}]}) + self.api.post_server_action(server['id'], {'pause': {}}) + self._wait_for_state_change(self.api, server, 'PAUSED') + + self.assertEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS)) + self._verify_notification( + 'instance-pause-start', + replacements={ + 'reservation_id': + notification_sample_base.NotificationSampleTestBase.ANY, + 'uuid': server['id']}, + actual=fake_notifier.VERSIONED_NOTIFICATIONS[0]) + self._verify_notification( + 'instance-pause-end', + replacements={ + 'reservation_id': + notification_sample_base.NotificationSampleTestBase.ANY, + 'uuid': server['id']}, + actual=fake_notifier.VERSIONED_NOTIFICATIONS[1]) diff --git a/nova/tests/unit/compute/test_compute.py b/nova/tests/unit/compute/test_compute.py index 6b6b7101026c..b938952313f1 100644 --- a/nova/tests/unit/compute/test_compute.py +++ b/nova/tests/unit/compute/test_compute.py @@ -2350,15 +2350,24 @@ class ComputeTestCase(BaseTestCase): self.assertTrue(called['power_off']) self.compute.terminate_instance(self.context, inst_obj, [], []) - def test_pause(self): + @mock.patch('nova.compute.utils.notify_about_instance_action') + @mock.patch.object(nova.context.RequestContext, 'elevated') + def test_pause(self, mock_context, mock_notify): # Ensure instance can be paused and unpaused. instance = self._create_fake_instance_obj() + ctxt = context.get_admin_context() + mock_context.return_value = ctxt self.compute.build_and_run_instance(self.context, instance, {}, {}, {}, block_device_mapping=[]) instance.task_state = task_states.PAUSING instance.save() fake_notifier.NOTIFICATIONS = [] self.compute.pause_instance(self.context, instance=instance) + mock_notify.assert_has_calls([ + mock.call(ctxt, instance, 'fake-mini', + action='pause', phase='start'), + mock.call(ctxt, instance, 'fake-mini', + action='pause', phase='end')]) self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2) msg = fake_notifier.NOTIFICATIONS[0] self.assertEqual(msg.event_type,