diff --git a/doc/notification_samples/instance-resize_revert-end.json b/doc/notification_samples/instance-resize_revert-end.json new file mode 100644 index 000000000000..019c374f583a --- /dev/null +++ b/doc/notification_samples/instance-resize_revert-end.json @@ -0,0 +1,6 @@ +{ + "event_type":"instance.resize_revert.end", + "payload":{"$ref":"common_payloads/InstanceActionPayload.json#"}, + "priority":"INFO", + "publisher_id":"nova-compute:compute" +} diff --git a/doc/notification_samples/instance-resize_revert-start.json b/doc/notification_samples/instance-resize_revert-start.json new file mode 100644 index 000000000000..b4128ba1286b --- /dev/null +++ b/doc/notification_samples/instance-resize_revert-start.json @@ -0,0 +1,22 @@ +{ + "event_type":"instance.resize_revert.start", + "payload":{ + "$ref":"common_payloads/InstanceActionPayload.json#", + "nova_object.data": { + "flavor":{ + "nova_object.data": { + "flavorid": "d5a8bb54-365a-45ae-abdb-38d249df7845", + "name": "other_flavor", + "memory_mb": 256, + "extra_specs": { + "hw:watchdog_action": "reset" + } + } + }, + "state":"resized", + "task_state":"resize_reverting" + } + }, + "priority":"INFO", + "publisher_id":"nova-compute:compute" +} diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 0220a631cb13..379bbf7a86c8 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -3851,6 +3851,9 @@ class ComputeManager(manager.Manager): with self._error_out_instance_on_exception(context, instance): self._notify_about_instance_usage( context, instance, "resize.revert.start") + compute_utils.notify_about_instance_action(context, instance, + self.host, action=fields.NotificationAction.RESIZE_REVERT, + phase=fields.NotificationPhase.START) # NOTE(mriedem): delete stashed old_vm_state information; we # default to ACTIVE for backwards compatibility if old_vm_state @@ -3910,6 +3913,9 @@ class ComputeManager(manager.Manager): self._notify_about_instance_usage( context, instance, "resize.revert.end") + compute_utils.notify_about_instance_action(context, instance, + self.host, action=fields.NotificationAction.RESIZE_REVERT, + phase=fields.NotificationPhase.END) def _revert_allocation(self, context, instance, migration): """Revert an allocation that is held by migration to our instance.""" diff --git a/nova/notifications/objects/instance.py b/nova/notifications/objects/instance.py index 7b74b9da8dc4..aa84ca0048f0 100644 --- a/nova/notifications/objects/instance.py +++ b/nova/notifications/objects/instance.py @@ -443,8 +443,8 @@ class InstanceStateUpdatePayload(base.NotificationPayloadBase): # @base.notification_sample('instance-resize_confirm-start.json') # @base.notification_sample('instance-resize_confirm-end.json') # @base.notification_sample('instance-resize_prep-start.json') -# @base.notification_sample('instance-resize_revert-start.json') -# @base.notification_sample('instance-resize_revert-end.json') +@base.notification_sample('instance-resize_revert-start.json') +@base.notification_sample('instance-resize_revert-end.json') @base.notification_sample('instance-shelve_offload-start.json') @base.notification_sample('instance-shelve_offload-end.json') @base.notification_sample('instance-soft_delete-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 a3560fccf6d7..6068faad9fca 100644 --- a/nova/tests/functional/notification_sample_tests/test_instance.py +++ b/nova/tests/functional/notification_sample_tests/test_instance.py @@ -229,8 +229,7 @@ class TestInstanceNotificationSample( self._test_pause_unpause_server, self._test_shelve_and_shelve_offload_server, self._test_unshelve_server, - self._test_resize_server, - self._test_revert_server, + self._test_resize_and_revert_server, self._test_resize_confirm_server, self._test_snapshot_server, self._test_reboot_server, @@ -690,7 +689,7 @@ class TestInstanceNotificationSample( 'uuid': server['id']}, actual=fake_notifier.VERSIONED_NOTIFICATIONS[3]) - def _test_resize_server(self, server): + def _test_resize_and_revert_server(self, server): self.flags(allow_resize_to_same_host=True) other_flavor_body = { 'flavor': { @@ -734,8 +733,24 @@ class TestInstanceNotificationSample( 'uuid': server['id']}, actual=fake_notifier.VERSIONED_NOTIFICATIONS[idx]) + # the following is the revert server request post = {'revertResize': None} self.api.post_server_action(server['id'], post) + self._wait_for_state_change(self.api, server, 'ACTIVE') + + self.assertEqual(6, len(fake_notifier.VERSIONED_NOTIFICATIONS)) + self._verify_notification( + 'instance-resize_revert-start', + replacements={ + 'reservation_id': server['reservation_id'], + 'uuid': server['id']}, + actual=fake_notifier.VERSIONED_NOTIFICATIONS[4]) + self._verify_notification( + 'instance-resize_revert-end', + replacements={ + 'reservation_id': server['reservation_id'], + 'uuid': server['id']}, + actual=fake_notifier.VERSIONED_NOTIFICATIONS[5]) @mock.patch('nova.compute.manager.ComputeManager._reschedule', return_value=True) @@ -1109,9 +1124,6 @@ class TestInstanceNotificationSample( 'uuid': server['id']}, actual=fake_notifier.VERSIONED_NOTIFICATIONS[6]) - def _test_revert_server(self, server): - pass - def _test_resize_confirm_server(self, server): pass diff --git a/nova/tests/unit/compute/test_compute.py b/nova/tests/unit/compute/test_compute.py index 3b6395aa35e6..3bc179467683 100644 --- a/nova/tests/unit/compute/test_compute.py +++ b/nova/tests/unit/compute/test_compute.py @@ -5562,7 +5562,8 @@ class ComputeTestCase(BaseTestCase, self._test_resize_with_pci( self.compute.revert_resize, '0000:0b:00.1') - def _test_finish_revert_resize(self, power_on, + @mock.patch.object(nova.compute.utils, 'notify_about_instance_action') + def _test_finish_revert_resize(self, mock_notify, power_on, remove_old_vm_state=False, numa_topology=None): """Convenience method that does most of the work for the @@ -5689,6 +5690,11 @@ class ComputeTestCase(BaseTestCase, self.compute.finish_revert_resize(self.context, migration=migration, instance=instance, reservations=[]) + mock_notify.assert_has_calls([ + mock.call(self.context, instance, 'fake-mini', + action='resize_revert', phase='start'), + mock.call(self.context, instance, 'fake-mini', + action='resize_revert', phase='end')]) self.assertIsNone(instance.task_state)