]> xenbits.xensource.com Git - osstest/openstack-nova.git/commitdiff
Transform instance.resume notifications
authorstewie925 <st6218@att.com>
Sat, 24 Sep 2016 01:06:32 +0000 (18:06 -0700)
committerstewie925 <st6218@att.com>
Tue, 25 Oct 2016 18:14:01 +0000 (11:14 -0700)
The instance.resume.start and instance.resume.end notifications
are transformed to the versioned framework using the generic
InstanceActionNotification and InstanceActionPayload class.

Implements: bp versioned-notification-transformation-ocata

Change-Id: I923971ea2f6c1f450ace27b246aa6f372a72bb30

doc/notification_samples/instance-resume-end.json [new file with mode: 0644]
doc/notification_samples/instance-resume-start.json [new file with mode: 0644]
nova/compute/manager.py
nova/notifications/objects/instance.py
nova/tests/functional/notification_sample_tests/test_instance.py
nova/tests/unit/compute/test_compute.py

diff --git a/doc/notification_samples/instance-resume-end.json b/doc/notification_samples/instance-resume-end.json
new file mode 100644 (file)
index 0000000..bf2b189
--- /dev/null
@@ -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 (file)
index 0000000..18236fe
--- /dev/null
@@ -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"
+}
index 82aa298f99ffa3cdbaabde70c1b99da23c2f69d5..7cca067f4bb1405d607058397d4a9925142790a4 100644 (file)
@@ -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
index d15c490dd8a0f3482bdd126f4c05d9c8d0250cb6..a7eb9ab44545ff7baaff5e8ff7d4faa21c735c49 100644 (file)
@@ -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')
index f3fc1f5a19ec09db71d0cb08e2d49273287ff565..87753da29b88ef13a01aece5400c6316d445c2f1 100644 (file)
@@ -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')
index 19bfb83b85ad57c4199d51e77148db7520a08b75..254b0989cc85750381a670e05e9f627dddfe6a20 100644 (file)
@@ -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):