]> xenbits.xensource.com Git - osstest/openstack-nova.git/commitdiff
Transform instance.power_off notifications
authorAndy Hsiang <yh418t@att.com>
Thu, 16 Jun 2016 19:27:06 +0000 (15:27 -0400)
committerJulian Sy <julian.sy@att.com>
Fri, 21 Oct 2016 13:04:36 +0000 (13:04 +0000)
The instance.power_off.start and instance.power_off.end notifications
are transformed to the versioned framework.

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

doc/notification_samples/instance-power_off-end.json [new file with mode: 0644]
doc/notification_samples/instance-power_off-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
nova/tests/unit/compute/test_compute_mgr.py

diff --git a/doc/notification_samples/instance-power_off-end.json b/doc/notification_samples/instance-power_off-end.json
new file mode 100644 (file)
index 0000000..f38392e
--- /dev/null
@@ -0,0 +1,62 @@
+{
+    "event_type":"instance.power_off.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":"stopped",
+            "task_state":null,
+            "power_state":"shutdown",
+            "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-power_off-start.json b/doc/notification_samples/instance-power_off-start.json
new file mode 100644 (file)
index 0000000..4b6481a
--- /dev/null
@@ -0,0 +1,62 @@
+{
+    "event_type":"instance.power_off.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":"powering-off",
+            "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 a9bb9998f301dfc81dfe612086b05e97bacafb6e..de8f8238a77e83667c3103d78f6328e5cafa3c2a 100644 (file)
@@ -2424,6 +2424,11 @@ class ComputeManager(manager.Manager):
 
             self._notify_about_instance_usage(context, instance,
                                               "power_off.start")
+
+            compute_utils.notify_about_instance_action(context, instance,
+                        self.host, action=fields.NotificationAction.POWER_OFF,
+                        phase=fields.NotificationPhase.START)
+
             self._power_off_instance(context, instance, clean_shutdown)
             instance.power_state = self._get_power_state(context, instance)
             instance.vm_state = vm_states.STOPPED
@@ -2432,6 +2437,10 @@ class ComputeManager(manager.Manager):
             self._notify_about_instance_usage(context, instance,
                                               "power_off.end")
 
+            compute_utils.notify_about_instance_action(context, instance,
+                        self.host, action=fields.NotificationAction.POWER_OFF,
+                        phase=fields.NotificationPhase.END)
+
         do_stop_instance()
 
     def _power_on(self, context, instance):
index 5efdd4571789ead613f7dce8f64532a1f1371d1d..8fc7a20c3d18c0f352473a88feb3bb0743f7e3cf 100644 (file)
@@ -233,8 +233,8 @@ class InstanceStateUpdatePayload(base.NotificationPayloadBase):
 @base.notification_sample('instance-suspend-end.json')
 @base.notification_sample('instance-power_on-start.json')
 @base.notification_sample('instance-power_on-end.json')
-@base.notification_sample('instance-power_off-start.json')
-@base.notification_sample('instance-power_off-end.json')
+@base.notification_sample('instance-power_off-start.json')
+@base.notification_sample('instance-power_off-end.json')
 # @base.notification_sample('instance-reboot-start.json')
 # @base.notification_sample('instance-reboot-end.json')
 # @base.notification_sample('instance-shutdown-start.json')
index 943df07aa5a8da316a809ee6283b7790d4572109..d42293722805ba26ba80b8cb7a444a570be92863 100644 (file)
@@ -39,7 +39,7 @@ class TestInstanceNotificationSample(
             extra_params={'networks': [{'port': self.neutron.port_1['id']}]})
 
         actions = [
-            self._test_power_on_server,
+            self._test_power_off_on_server,
             self._test_restore_server,
             self._test_suspend_server,
             self._test_pause_server,
@@ -212,7 +212,7 @@ class TestInstanceNotificationSample(
         self._verify_instance_update_steps(delete_steps, instance_updates,
                                            initial=replacements)
 
-    def _test_power_on_server(self, server):
+    def _test_power_off_on_server(self, server):
         self.api.post_server_action(server['id'], {'os-stop': {}})
         self._wait_for_state_change(self.api, server,
                                     expected_status='SHUTOFF')
@@ -220,20 +220,34 @@ class TestInstanceNotificationSample(
         self._wait_for_state_change(self.api, server,
                                     expected_status='ACTIVE')
 
-        self.assertEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS))
+        self.assertEqual(4, len(fake_notifier.VERSIONED_NOTIFICATIONS))
         self._verify_notification(
-            'instance-power_on-start',
+            'instance-power_off-start',
             replacements={
                 'reservation_id': server['reservation_id'],
                 'uuid': server['id']},
             actual=fake_notifier.VERSIONED_NOTIFICATIONS[0])
         self._verify_notification(
-            'instance-power_on-end',
+            'instance-power_off-end',
             replacements={
                 'reservation_id': server['reservation_id'],
+                'power_state': 'running',
                 'uuid': server['id']},
             actual=fake_notifier.VERSIONED_NOTIFICATIONS[1])
 
+        self._verify_notification(
+            'instance-power_on-start',
+            replacements={
+                'reservation_id': server['reservation_id'],
+                'uuid': server['id']},
+            actual=fake_notifier.VERSIONED_NOTIFICATIONS[2])
+        self._verify_notification(
+            'instance-power_on-end',
+            replacements={
+                'reservation_id': server['reservation_id'],
+                'uuid': server['id']},
+            actual=fake_notifier.VERSIONED_NOTIFICATIONS[3])
+
     def _test_shelve_server(self, server):
         self.flags(shelved_offload_time = -1)
 
index 19bfb83b85ad57c4199d51e77148db7520a08b75..6d7d09155114b357af1259d07c26ff7c3002fe6d 100644 (file)
@@ -2051,7 +2051,8 @@ class ComputeTestCase(BaseTestCase):
         instance = db.instance_get_by_uuid(self.context, instance['uuid'])
         self.assertEqual(instance['vm_state'], vm_states.ERROR)
 
-    def test_stop(self):
+    @mock.patch('nova.compute.utils.notify_about_instance_action')
+    def test_stop(self, mock_notify):
         # Ensure instance can be stopped.
         instance = self._create_fake_instance_obj()
         self.compute.build_and_run_instance(self.context, instance, {}, {},
@@ -2065,6 +2066,11 @@ class ComputeTestCase(BaseTestCase):
                                                 expected_attrs=extra)
         self.compute.stop_instance(self.context, instance=inst_obj,
                                    clean_shutdown=True)
+        mock_notify.assert_has_calls([
+            mock.call(self.context, inst_obj, 'fake-mini', action='power_off',
+                      phase='start'),
+            mock.call(self.context, inst_obj, 'fake-mini', action='power_off',
+                      phase='end')])
         self.compute.terminate_instance(self.context, instance, [], [])
 
     @mock.patch('nova.compute.utils.notify_about_instance_action')
index 18bb50cfd437cce215363386072c6563b34c78e1..c2c78ef86d663293091ebfd19ef0b59f142ad199 100755 (executable)
@@ -2852,12 +2852,13 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
 
         @mock.patch.object(self.compute, '_get_power_state',
                            return_value=power_state.SHUTDOWN)
+        @mock.patch.object(compute_utils, 'notify_about_instance_action')
         @mock.patch.object(self.compute, '_notify_about_instance_usage')
         @mock.patch.object(self.compute, '_power_off_instance')
         @mock.patch.object(instance, 'save')
         @mock.patch.object(compute_utils, 'EventReporter')
         def do_test(event_mock, save_mock, power_off_mock, notify_mock,
-                    get_state_mock):
+                    notify_action_mock, get_state_mock):
             # run the code
             self.compute.stop_instance(self.context, instance, True)
             # assert the calls
@@ -2866,6 +2867,12 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
                 mock.call(self.context, instance, 'power_off.start'),
                 mock.call(self.context, instance, 'power_off.end')
             ])
+            notify_action_mock.assert_has_calls([
+                mock.call(self.context, instance, 'fake-mini',
+                          action='power_off', phase='start'),
+                mock.call(self.context, instance, 'fake-mini',
+                          action='power_off', phase='end'),
+            ])
             power_off_mock.assert_called_once_with(
                 self.context, instance, True)
             save_mock.assert_called_once_with(