]> xenbits.xensource.com Git - osstest/openstack-nova.git/commitdiff
Transform instance.create notification
authorGábor Antal <antal@inf.u-szeged.hu>
Mon, 10 Oct 2016 16:14:52 +0000 (18:14 +0200)
committerMatt Riedemann <mriedem@us.ibm.com>
Tue, 22 Nov 2016 20:03:47 +0000 (15:03 -0500)
We don't need image_name as an extra usage information, because
in the versioned notification, we have image_uuid which can be used
to get the name of the image from glance, if needed.

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

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

diff --git a/doc/notification_samples/instance-create-end.json b/doc/notification_samples/instance-create-end.json
new file mode 100644 (file)
index 0000000..39b1d5b
--- /dev/null
@@ -0,0 +1,62 @@
+{
+    "event_type":"instance.create.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"
+}
\ No newline at end of file
diff --git a/doc/notification_samples/instance-create-start.json b/doc/notification_samples/instance-create-start.json
new file mode 100644 (file)
index 0000000..441cb88
--- /dev/null
@@ -0,0 +1,49 @@
+{
+    "event_type":"instance.create.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": [],
+            "kernel_id":"",
+            "launched_at":null,
+            "image_uuid": "155d900f-4e14-4e4c-a73d-069cbf4541e6",
+            "metadata":{},
+            "node":null,
+            "os_type":null,
+            "progress":0,
+            "ramdisk_id":"",
+            "reservation_id":"r-npxv0e40",
+            "state":"building",
+            "task_state":null,
+            "power_state":"pending",
+            "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"
+}
\ No newline at end of file
index 67ce7b9d4f94b657383f57f5ee14addb98bd1ef1..ade99db527ece5034ba1439da9b6448d2808d4b4 100644 (file)
@@ -1887,6 +1887,10 @@ class ComputeManager(manager.Manager):
         image_name = image.get('name')
         self._notify_about_instance_usage(context, instance, 'create.start',
                 extra_usage_info={'image_name': image_name})
+        compute_utils.notify_about_instance_action(
+            context, instance, self.host,
+            action=fields.NotificationAction.CREATE,
+            phase=fields.NotificationPhase.START)
 
         self._check_device_tagging(requested_networks, block_device_mapping)
 
@@ -2008,6 +2012,9 @@ class ComputeManager(manager.Manager):
         self._notify_about_instance_usage(context, instance, 'create.end',
                 extra_usage_info={'message': _('Success')},
                 network_info=network_info)
+        compute_utils.notify_about_instance_action(context, instance,
+                self.host, action=fields.NotificationAction.CREATE,
+                phase=fields.NotificationPhase.END)
 
     @contextlib.contextmanager
     def _build_resources(self, context, instance, requested_networks,
index 189f6bef54718b25927069f64bd07c950c476ad3..ebf6b209e537fa04f5097ec89491f230001e9186 100644 (file)
@@ -304,6 +304,8 @@ class InstanceStateUpdatePayload(base.NotificationPayloadBase):
 # @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-create-start.json')
+@base.notification_sample('instance-create-end.json')
 @nova_base.NovaObjectRegistry.register_notification
 class InstanceActionNotification(base.NotificationBase):
     # Version 1.0: Initial version
index 9c94a30aac38642c3e2fb54d377005c1ffdec9dc..4984218014432b13399197457939618887d54b2c 100644 (file)
@@ -81,31 +81,24 @@ class TestInstanceNotificationSample(
             extra_params={'networks': [{'port': self.neutron.port_1['id']}]})
         self.api.delete_server(server['id'])
         self._wait_until_deleted(server)
-        self.assertEqual(4, len(fake_notifier.VERSIONED_NOTIFICATIONS))
-        self._verify_notification(
+        self.assertEqual(6, len(fake_notifier.VERSIONED_NOTIFICATIONS))
+
+        # This list needs to be in order.
+        expected_notifications = [
+            'instance-create-start',
+            'instance-create-end',
             'instance-delete-start',
-            replacements={
-                'reservation_id': server['reservation_id'],
-                'uuid': server['id']},
-            actual=fake_notifier.VERSIONED_NOTIFICATIONS[0])
-        self._verify_notification(
             'instance-shutdown-start',
-            replacements={
-                'reservation_id': server['reservation_id'],
-                'uuid': server['id']},
-            actual=fake_notifier.VERSIONED_NOTIFICATIONS[1])
-        self._verify_notification(
             'instance-shutdown-end',
-            replacements={
-                'reservation_id': server['reservation_id'],
-                'uuid': server['id']},
-            actual=fake_notifier.VERSIONED_NOTIFICATIONS[2])
-        self._verify_notification(
-            'instance-delete-end',
-            replacements={
-                'reservation_id': server['reservation_id'],
-                'uuid': server['id']},
-            actual=fake_notifier.VERSIONED_NOTIFICATIONS[3])
+            'instance-delete-end'
+        ]
+        for idx, notification in enumerate(expected_notifications):
+            self._verify_notification(
+                notification,
+                replacements={
+                    'reservation_id': server['reservation_id'],
+                    'uuid': server['id']},
+                actual=fake_notifier.VERSIONED_NOTIFICATIONS[idx])
 
     def _verify_instance_update_steps(self, steps, notifications,
                                       initial=None):
@@ -515,19 +508,19 @@ class TestInstanceNotificationSample(
                                  self.cinder.SWAP_NEW_VOL)
         self._wait_until_swap_volume(server, self.cinder.SWAP_NEW_VOL)
 
-        self.assertEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS))
+        self.assertEqual(4, len(fake_notifier.VERSIONED_NOTIFICATIONS))
         self._verify_notification(
             'instance-volume_swap-start',
             replacements={
                 'reservation_id': server['reservation_id'],
                 'uuid': server['id']},
-            actual=fake_notifier.VERSIONED_NOTIFICATIONS[0])
+            actual=fake_notifier.VERSIONED_NOTIFICATIONS[2])
         self._verify_notification(
             'instance-volume_swap-end',
             replacements={
                 'reservation_id': server['reservation_id'],
                 'uuid': server['id']},
-            actual=fake_notifier.VERSIONED_NOTIFICATIONS[1])
+            actual=fake_notifier.VERSIONED_NOTIFICATIONS[3])
 
     def test_volume_swap_server_with_error(self):
         server = self._boot_a_server(
@@ -540,11 +533,13 @@ class TestInstanceNotificationSample(
                                  self.cinder.SWAP_ERR_NEW_VOL)
         self._wait_until_swap_volume_error()
 
-        # Three versioned notifications are generated.
-        # 0. instance-volume_swap-start
-        # 1. instance-volume_swap-error
-        # 2. compute.exception
-        self.assertEqual(3, len(fake_notifier.VERSIONED_NOTIFICATIONS))
+        # Five versioned notifications are generated.
+        # 0. instance-create-start
+        # 1. instance-create-start
+        # 2. instance-volume_swap-start
+        # 3. instance-volume_swap-error
+        # 4. compute.exception
+        self.assertEqual(5, len(fake_notifier.VERSIONED_NOTIFICATIONS))
         self._verify_notification(
             'instance-volume_swap-start',
             replacements={
@@ -552,10 +547,10 @@ class TestInstanceNotificationSample(
                 'old_volume_id': self.cinder.SWAP_ERR_OLD_VOL,
                 'reservation_id': server['reservation_id'],
                 'uuid': server['id']},
-            actual=fake_notifier.VERSIONED_NOTIFICATIONS[0])
+            actual=fake_notifier.VERSIONED_NOTIFICATIONS[2])
         self._verify_notification(
             'instance-volume_swap-error',
             replacements={
                 'reservation_id': server['reservation_id'],
                 'uuid': server['id']},
-            actual=fake_notifier.VERSIONED_NOTIFICATIONS[1])
+            actual=fake_notifier.VERSIONED_NOTIFICATIONS[3])
index 93a2bf894ddc5dd0717cda8147a98468cad2e0f2..1a00dd1c5df1c6ac44d3192047664e1465c44689 100755 (executable)
@@ -4448,9 +4448,10 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase):
                 self.context, mock.sentinel.instance,
                 requested_networks=requested_networks)
 
+    @mock.patch('nova.compute.utils.notify_about_instance_action')
     @mock.patch.object(manager.ComputeManager, '_instance_update')
     def test_launched_at_in_create_end_notification(self,
-            mock_instance_update):
+            mock_instance_update, mock_notify_instance_action):
 
         def fake_notify(*args, **kwargs):
             if args[2] == 'create.end':
@@ -4479,6 +4480,12 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase):
                     mock_notify.call_count - 1]
             self.assertEqual(expected_call, create_end_call)
 
+            mock_notify_instance_action.assert_has_calls([
+                mock.call(self.context, self.instance, 'fake-mini',
+                          action='create', phase='start'),
+                mock.call(self.context, self.instance, 'fake-mini',
+                          action='create', phase='end')])
+
     def test_access_ip_set_when_instance_set_to_active(self):
 
         self.flags(default_access_ip_network_name='test1')