diff --git a/doc/notification_samples/instance-resize_finish-end.json b/doc/notification_samples/instance-resize_finish-end.json new file mode 100644 index 000000000000..b59df652a57a --- /dev/null +++ b/doc/notification_samples/instance-resize_finish-end.json @@ -0,0 +1,62 @@ +{ + "event_type":"instance.resize_finish.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":"resized", + "task_state":null, + "power_state":"running", + "tenant_id":"6f70656e737461636b20342065766572", + "terminated_at":null, + "flavor": { + "nova_object.name": "FlavorPayload", + "nova_object.data": { + "flavorid": "d5a8bb54-365a-45ae-abdb-38d249df7845", + "root_gb": 1, + "vcpus": 1, + "ephemeral_gb": 0, + "memory_mb": 256 + }, + "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-resize_finish-start.json b/doc/notification_samples/instance-resize_finish-start.json new file mode 100644 index 000000000000..52f3b135f1ed --- /dev/null +++ b/doc/notification_samples/instance-resize_finish-start.json @@ -0,0 +1,62 @@ +{ + "event_type":"instance.resize_finish.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":"resize_finish", + "power_state":"running", + "tenant_id":"6f70656e737461636b20342065766572", + "terminated_at":null, + "flavor": { + "nova_object.name": "FlavorPayload", + "nova_object.data": { + "flavorid": "d5a8bb54-365a-45ae-abdb-38d249df7845", + "root_gb": 1, + "vcpus": 1, + "ephemeral_gb": 0, + "memory_mb": 256 + }, + "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/nova/compute/manager.py b/nova/compute/manager.py index f2589c1a6e59..b9e9795bc331 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -3946,6 +3946,9 @@ class ComputeManager(manager.Manager): self._notify_about_instance_usage( context, instance, "finish_resize.start", network_info=network_info) + compute_utils.notify_about_instance_action(context, instance, + self.host, action=fields.NotificationAction.RESIZE_FINISH, + phase=fields.NotificationPhase.START) block_device_info = self._get_instance_block_device_info( context, instance, refresh_conn_info=True) @@ -3979,6 +3982,9 @@ class ComputeManager(manager.Manager): self._notify_about_instance_usage( context, instance, "finish_resize.end", network_info=network_info) + compute_utils.notify_about_instance_action(context, instance, + self.host, action=fields.NotificationAction.RESIZE_FINISH, + phase=fields.NotificationPhase.END) @wrap_exception() @reverts_task_state diff --git a/nova/notifications/objects/instance.py b/nova/notifications/objects/instance.py index ebf6b209e537..1a6c96b4d3e0 100644 --- a/nova/notifications/objects/instance.py +++ b/nova/notifications/objects/instance.py @@ -272,8 +272,8 @@ class InstanceStateUpdatePayload(base.NotificationPayloadBase): @base.notification_sample('instance-restore-start.json') @base.notification_sample('instance-restore-end.json') # @base.notification_sample('instance-evacuate.json') -# @base.notification_sample('instance-resize_finish-start.json') -# @base.notification_sample('instance-resize_finish-end.json') +@base.notification_sample('instance-resize_finish-start.json') +@base.notification_sample('instance-resize_finish-end.json') # @base.notification_sample('instance-live_migration_pre-start.json') # @base.notification_sample('instance-live_migration_pre-end.json') # @base.notification_sample('instance-live_migration_abort-start.json') diff --git a/nova/tests/functional/notification_sample_tests/test_instance.py b/nova/tests/functional/notification_sample_tests/test_instance.py index f1f295e2e9d9..06bb4e45b364 100644 --- a/nova/tests/functional/notification_sample_tests/test_instance.py +++ b/nova/tests/functional/notification_sample_tests/test_instance.py @@ -472,23 +472,40 @@ class TestInstanceNotificationSample( def _test_resize_server(self, server): self.flags(allow_resize_to_same_host=True) - post = {'resize': {'flavorRef': '2'}} + other_flavor_body = { + 'flavor': { + 'name': 'other_flavor', + 'ram': 256, + 'vcpus': 1, + 'disk': 1, + 'id': 'd5a8bb54-365a-45ae-abdb-38d249df7845' + } + } + other_flavor_id = self.api.post_flavor(other_flavor_body)['id'] + + post = { + 'resize': { + 'flavorRef': other_flavor_id + } + } self.api.post_server_action(server['id'], post) self._wait_for_state_change(self.api, server, 'VERIFY_RESIZE') - self.assertEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS)) - self._verify_notification( + self.assertEqual(4, len(fake_notifier.VERSIONED_NOTIFICATIONS)) + # This list needs to be in order. + expected_notifications = [ 'instance-resize-start', - replacements={ - 'reservation_id': server['reservation_id'], - 'uuid': server['id']}, - actual=fake_notifier.VERSIONED_NOTIFICATIONS[0]) - self._verify_notification( 'instance-resize-end', - replacements={ - 'reservation_id': server['reservation_id'], - 'uuid': server['id']}, - actual=fake_notifier.VERSIONED_NOTIFICATIONS[1]) + 'instance-resize_finish-start', + 'instance-resize_finish-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]) post = {'revertResize': None} self.api.post_server_action(server['id'], post) diff --git a/nova/tests/unit/compute/test_compute.py b/nova/tests/unit/compute/test_compute.py index 78438db7d470..782376df0fc6 100644 --- a/nova/tests/unit/compute/test_compute.py +++ b/nova/tests/unit/compute/test_compute.py @@ -4450,14 +4450,15 @@ class ComputeTestCase(BaseTestCase): mock.patch.object(self.compute.network_api, 'get_instance_nw_info'), mock.patch.object(self.compute, '_notify_about_instance_usage'), + mock.patch.object(compute_utils, 'notify_about_instance_action'), mock.patch.object(self.compute.driver, 'finish_migration'), mock.patch.object(self.compute, '_get_instance_block_device_info'), mock.patch.object(migration, 'save'), mock.patch.object(instance, 'save'), mock.patch.object(nova.quota.QUOTAS, 'commit') ) as (mock_setup, mock_net_mig, mock_get_nw, mock_notify, - mock_virt_mig, mock_get_blk, mock_mig_save, mock_inst_save, - mock_commit): + mock_notify_action, mock_virt_mig, mock_get_blk, mock_mig_save, + mock_inst_save, mock_commit): def _mig_save(): self.assertEqual(migration.status, 'finished') self.assertEqual(vm_state, instance.vm_state) @@ -4516,6 +4517,11 @@ class ComputeTestCase(BaseTestCase): network_info='fake-nwinfo1'), mock.call(self.context, instance, 'finish_resize.end', network_info='fake-nwinfo1')]) + mock_notify_action.assert_has_calls([ + mock.call(self.context, instance, 'fake-mini', + action='resize_finish', phase='start'), + mock.call(self.context, instance, 'fake-mini', + action='resize_finish', phase='end')]) # nova.conf sets the default flavor to m1.small and the test # sets the default flavor to m1.tiny so they should be different # which makes this a resize