]> xenbits.xensource.com Git - osstest/openstack-nova.git/commitdiff
Transform instance.unshelve notifications
authorstewie925 <st6218@att.com>
Wed, 5 Oct 2016 16:27:36 +0000 (09:27 -0700)
committerstewie925 <st6218@att.com>
Wed, 26 Oct 2016 17:33:53 +0000 (10:33 -0700)
The instance.unshelve.start and instance.unshelve.end
notifications are transformed to the versioned framework.

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

doc/notification_samples/instance-unshelve-end.json [new file with mode: 0644]
doc/notification_samples/instance-unshelve-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_shelve.py

diff --git a/doc/notification_samples/instance-unshelve-end.json b/doc/notification_samples/instance-unshelve-end.json
new file mode 100644 (file)
index 0000000..b581ea4
--- /dev/null
@@ -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 (file)
index 0000000..3dd1909
--- /dev/null
@@ -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"
+}
index 451c49bb8801ac483731b179a8f816d13522730d..5b0e67c20e7bde7551713b2700e76254a594ef37 100644 (file)
@@ -4325,6 +4325,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()
 
@@ -4379,6 +4383,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
index bd8f78dbc2e4d7354070b0dbfd9d9fe08e438978..6bc52ebd96fab8b346ce6ee24e96edf534aacacb 100644 (file)
@@ -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
index 472e9d0e7dad2a8bca8fc800205a90ed55ac6484..918f968a3210512265e091b8d7543e06d30a451e 100644 (file)
@@ -66,6 +66,7 @@ class TestInstanceNotificationSample(
             self._test_pause_server,
             self._test_shelve_server,
             self._test_shelve_offload_server,
+            self._test_unshelve_server,
             self._test_resize_server,
         ]
 
@@ -320,6 +321,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)
index 25be85885509c4cb950b7f4eb9b7591b3cfc3ed4..7a56cd88ff187ca13029570e245c9e174934c9bd 100644 (file)
@@ -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 = {}