]> xenbits.xensource.com Git - osstest/openstack-nova.git/commitdiff
Transform instance.unpause notifications
authorMikeG451 <mg6596@att.com>
Fri, 30 Sep 2016 23:08:31 +0000 (23:08 +0000)
committerBalazs Gibizer <balazs.gibizer@ericsson.com>
Fri, 28 Oct 2016 10:09:35 +0000 (10:09 +0000)
The instance.unpause.start and instance.unpause.end notifications
are transformed to the versioned framework.

Change-Id: Ia11b63b93ac941bf6922abfe9c380c9647ee7f83
Implements: bp versioned-notification-transformation-ocata

doc/notification_samples/instance-unpause-end.json [new file with mode: 0644]
doc/notification_samples/instance-unpause-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-unpause-end.json b/doc/notification_samples/instance-unpause-end.json
new file mode 100644 (file)
index 0000000..6027557
--- /dev/null
@@ -0,0 +1,62 @@
+{
+    "event_type":"instance.unpause.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-unpause-start.json b/doc/notification_samples/instance-unpause-start.json
new file mode 100644 (file)
index 0000000..9f4c615
--- /dev/null
@@ -0,0 +1,62 @@
+{
+    "event_type":"instance.unpause.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":"paused",
+            "task_state":"unpausing",
+            "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 451c49bb8801ac483731b179a8f816d13522730d..7ffb096e480b00bd8d141a4490e9f69ce16024f0 100644 (file)
@@ -4033,12 +4033,18 @@ class ComputeManager(manager.Manager):
         context = context.elevated()
         LOG.info(_LI('Unpausing'), instance=instance)
         self._notify_about_instance_usage(context, instance, 'unpause.start')
+        compute_utils.notify_about_instance_action(context, instance,
+            self.host, action=fields.NotificationAction.UNPAUSE,
+            phase=fields.NotificationPhase.START)
         self.driver.unpause(instance)
         instance.power_state = self._get_power_state(context, instance)
         instance.vm_state = vm_states.ACTIVE
         instance.task_state = None
         instance.save(expected_task_state=task_states.UNPAUSING)
         self._notify_about_instance_usage(context, instance, 'unpause.end')
+        compute_utils.notify_about_instance_action(context, instance,
+            self.host, action=fields.NotificationAction.UNPAUSE,
+            phase=fields.NotificationPhase.END)
 
     @wrap_exception()
     def host_power_action(self, context, action):
index bd8f78dbc2e4d7354070b0dbfd9d9fe08e438978..caed684217a96ec784c8fd1e0cb3c036840724b6 100644 (file)
@@ -247,8 +247,8 @@ class InstanceStateUpdatePayload(base.NotificationPayloadBase):
 @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-unpause-start.json')
-@base.notification_sample('instance-unpause-end.json')
+@base.notification_sample('instance-unpause-start.json')
+@base.notification_sample('instance-unpause-end.json')
 @base.notification_sample('instance-resize-start.json')
 @base.notification_sample('instance-resize-end.json')
 @base.notification_sample('instance-suspend-start.json')
index 472e9d0e7dad2a8bca8fc800205a90ed55ac6484..7305bdbb3fa8209530bbead44842b71a1a142265 100644 (file)
@@ -64,6 +64,7 @@ class TestInstanceNotificationSample(
             self._test_restore_server,
             self._test_suspend_server,
             self._test_pause_server,
+            self._test_unpause_server,
             self._test_shelve_server,
             self._test_shelve_offload_server,
             self._test_resize_server,
@@ -361,9 +362,23 @@ class TestInstanceNotificationSample(
                 'uuid': server['id']},
             actual=fake_notifier.VERSIONED_NOTIFICATIONS[1])
 
-        post = {'unpause': None}
-        self.api.post_server_action(server['id'], post)
-        self._wait_for_state_change(self.admin_api, server, 'ACTIVE')
+    def _test_unpause_server(self, server):
+        self.api.post_server_action(server['id'], {'unpause': {}})
+        self._wait_for_state_change(self.api, server, 'ACTIVE')
+
+        self.assertEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS))
+        self._verify_notification(
+            'instance-unpause-start',
+            replacements={
+                'reservation_id': server['reservation_id'],
+                'uuid': server['id']},
+            actual=fake_notifier.VERSIONED_NOTIFICATIONS[0])
+        self._verify_notification(
+            'instance-unpause-end',
+            replacements={
+                'reservation_id': server['reservation_id'],
+                'uuid': server['id']},
+            actual=fake_notifier.VERSIONED_NOTIFICATIONS[1])
 
     def _test_resize_server(self, server):
         self.flags(allow_resize_to_same_host=True)
index 1a96c1d8b4ce0cac9ff6b980c338846cde056abd..dd4bdd7bc31099baa8b8edf761ba656fd6de2856 100644 (file)
@@ -2423,6 +2423,7 @@ class ComputeTestCase(BaseTestCase):
                          'compute.instance.pause.end')
         instance.task_state = task_states.UNPAUSING
         instance.save()
+        mock_notify.reset_mock()
         fake_notifier.NOTIFICATIONS = []
         self.compute.unpause_instance(self.context, instance=instance)
         self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
@@ -2432,6 +2433,11 @@ class ComputeTestCase(BaseTestCase):
         msg = fake_notifier.NOTIFICATIONS[1]
         self.assertEqual(msg.event_type,
                          'compute.instance.unpause.end')
+        mock_notify.assert_has_calls([
+            mock.call(ctxt, instance, 'fake-mini',
+                      action='unpause', phase='start'),
+            mock.call(ctxt, instance, 'fake-mini',
+                      action='unpause', phase='end')])
         self.compute.terminate_instance(self.context, instance, [], [])
 
     @mock.patch('nova.compute.utils.notify_about_instance_action')