diff --git a/nova/api/openstack/compute/contrib/rescue.py b/nova/api/openstack/compute/contrib/rescue.py index fe31f2cd5e8a..0233be24e588 100644 --- a/nova/api/openstack/compute/contrib/rescue.py +++ b/nova/api/openstack/compute/contrib/rescue.py @@ -75,7 +75,7 @@ class RescueController(wsgi.Controller): """Unrescue an instance.""" context = req.environ["nova.context"] authorize(context) - instance = self._get_instance(context, id) + instance = self._get_instance(context, id, want_objects=True) try: self.compute_api.unrescue(context, instance) except exception.InstanceInvalidState as state_error: diff --git a/nova/api/openstack/compute/plugins/v3/rescue.py b/nova/api/openstack/compute/plugins/v3/rescue.py index 5ae876bd0f6a..66b4c175f2c4 100644 --- a/nova/api/openstack/compute/plugins/v3/rescue.py +++ b/nova/api/openstack/compute/plugins/v3/rescue.py @@ -77,7 +77,8 @@ class RescueController(wsgi.Controller): """Unrescue an instance.""" context = req.environ["nova.context"] authorize(context) - instance = common.get_instance(self.compute_api, context, id) + instance = common.get_instance(self.compute_api, context, id, + want_objects=True) try: self.compute_api.unrescue(context, instance) except exception.InstanceInvalidState as state_error: diff --git a/nova/compute/manager.py b/nova/compute/manager.py index dbb5e770328d..35e03da29210 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -412,7 +412,7 @@ class ComputeVirtAPI(virtapi.VirtAPI): class ComputeManager(manager.Manager): """Manages the running instances from creation to destruction.""" - target = messaging.Target(version='3.10') + target = messaging.Target(version='3.11') def __init__(self, compute_driver=None, *args, **kwargs): """Load configuration options and connect to the hypervisor.""" @@ -2746,6 +2746,7 @@ class ComputeManager(manager.Manager): "rescue.end", extra_usage_info=extra_usage_info, network_info=network_info) + @object_compat @wrap_exception() @reverts_task_state @wrap_instance_event @@ -2763,12 +2764,11 @@ class ComputeManager(manager.Manager): network_info) current_power_state = self._get_power_state(context, instance) - instance = self._instance_update(context, - instance['uuid'], - vm_state=vm_states.ACTIVE, - task_state=None, - expected_task_state=task_states.UNRESCUING, - power_state=current_power_state) + instance.vm_state = vm_states.ACTIVE + instance.task_state = None + instance.power_state = current_power_state + instance.save(expected_task_state=task_states.UNRESCUING) + self._notify_about_instance_usage(context, instance, "unrescue.end", diff --git a/nova/compute/rpcapi.py b/nova/compute/rpcapi.py index 2cdd409a989b..8ec1f2b76c5e 100644 --- a/nova/compute/rpcapi.py +++ b/nova/compute/rpcapi.py @@ -224,6 +224,7 @@ class ComputeAPI(object): 3.8 - Update set_admin_password() to take an instance object 3.9 - Update rescue_instance() to take an instance object 3.10 - Added get_rdp_console method + 3.11 - Update unrescue_instance() to take an object ''' VERSION_ALIASES = { @@ -826,12 +827,15 @@ class ComputeAPI(object): cctxt.cast(ctxt, 'unpause_instance', instance=instance) def unrescue_instance(self, ctxt, instance): - # NOTE(russellb) Havana compat - version = self._get_compat_version('3.0', '2.0') - instance_p = jsonutils.to_primitive(instance) + if self.client.can_send_version('3.11'): + version = '3.11' + else: + # NOTE(russellb) Havana compat + version = self._get_compat_version('3.0', '2.0') + instance = jsonutils.to_primitive(instance) cctxt = self.client.prepare(server=_compute_host(None, instance), version=version) - cctxt.cast(ctxt, 'unrescue_instance', instance=instance_p) + cctxt.cast(ctxt, 'unrescue_instance', instance=instance) def soft_delete_instance(self, ctxt, instance, reservations=None): # NOTE(russellb) Havana compat diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 4cf3751414bb..c31d293df426 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -1814,7 +1814,8 @@ class ComputeTestCase(BaseTestCase): self.assertTrue(called['rescued']) db.instance_update(self.context, instance_uuid, {"task_state": task_states.UNRESCUING}) - self.compute.unrescue_instance(self.context, instance=instance) + self.compute.unrescue_instance(self.context, + instance=self._objectify(instance)) self.assertTrue(called['unrescued']) self.compute.terminate_instance(self.context, @@ -1879,7 +1880,8 @@ class ComputeTestCase(BaseTestCase): fake_notifier.NOTIFICATIONS = [] db.instance_update(self.context, instance_uuid, {"task_state": task_states.UNRESCUING}) - self.compute.unrescue_instance(self.context, instance=instance) + self.compute.unrescue_instance(self.context, + instance=self._objectify(instance)) expected_notifications = ['compute.instance.unrescue.start', 'compute.instance.unrescue.end'] @@ -7008,7 +7010,7 @@ class ComputeAPITestCase(BaseTestCase): db.instance_update(self.context, instance_uuid, params) instance = db.instance_get_by_uuid(self.context, instance_uuid) - self.compute_api.unrescue(self.context, instance) + self.compute_api.unrescue(self.context, self._objectify(instance)) instance = db.instance_get_by_uuid(self.context, instance_uuid) self.assertEqual(instance['vm_state'], vm_states.RESCUED) diff --git a/nova/tests/compute/test_rpcapi.py b/nova/tests/compute/test_rpcapi.py index e48810eaa80f..54ccd5932cac 100644 --- a/nova/tests/compute/test_rpcapi.py +++ b/nova/tests/compute/test_rpcapi.py @@ -751,7 +751,7 @@ class ComputeRpcAPITestCase(test.TestCase): def test_unrescue_instance(self): self._test_compute_api('unrescue_instance', 'cast', - instance=self.fake_instance) + instance=self.fake_instance, version='3.11') # NOTE(russellb) Havana compat self.flags(compute='havana', group='upgrade_levels')