From b4dc932c2a10c3d9c678cf759f94237504661348 Mon Sep 17 00:00:00 2001 From: Matthew Sherborne Date: Thu, 18 Apr 2013 17:51:52 +1000 Subject: Can now reboot rescued instances in xenapi This patch makes it possible to reboot an instance that is in rescue mode. It causes the reboot action to search first for rescue mode VM (the normal VMs name plus '-rescue') .. if it can't find it, it does a reboot of the normal VM. If it finds the rescue one first, it'll reboot the rescue instance. If there is more than one VM named 'myvm-rescue', it'll raise an exception just like it did if there were more than one VM named 'myvm'. Helps with bug: 1170237 Change-Id: I1858d86bf93546618eeaaec92d856f5236f3f090 --- nova/tests/test_xenapi.py | 14 ++++++++++++++ nova/virt/xenapi/vmops.py | 11 +++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 474fd1eb9..9919fc138 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -1103,6 +1103,20 @@ class XenAPIVMTestCase(stubs.XenAPITestBase): self.assertRaises(xenapi_fake.Failure, conn.reboot, self.context, instance, None, "SOFT") + def test_reboot_rescued(self): + instance = self._create_instance() + instance['vm_state'] = vm_states.RESCUED + conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False) + + real_result = vm_utils.lookup(conn._session, instance['name']) + + self.mox.StubOutWithMock(vm_utils, 'lookup') + vm_utils.lookup(conn._session, instance['name'], + True).AndReturn(real_result) + self.mox.ReplayAll() + + conn.reboot(self.context, instance, None, "SOFT") + def _test_maintenance_mode(self, find_host, find_aggregate): real_call_xenapi = self.conn._session.call_xenapi instance = self._create_instance(spawn=True) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index d8f750e0a..0be92c158 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -696,9 +696,12 @@ class VMOps(object): self._session.call_xenapi('VM.add_to_VCPUs_params', vm_ref, 'weight', str(vcpu_weight)) - def _get_vm_opaque_ref(self, instance): - """Get xapi OpaqueRef from a db record.""" - vm_ref = vm_utils.lookup(self._session, instance['name']) + def _get_vm_opaque_ref(self, instance, check_rescue=False): + """Get xapi OpaqueRef from a db record. + :param check_rescue: if True will return the 'name'-rescue vm if it + exists, instead of just 'name' + """ + vm_ref = vm_utils.lookup(self._session, instance['name'], check_rescue) if vm_ref is None: raise exception.NotFound(_('Could not find VM with name %s') % instance['name']) @@ -975,7 +978,7 @@ class VMOps(object): # Note (salvatore-orlando): security group rules are not re-enforced # upon reboot, since this action on the XenAPI drivers does not # remove existing filters - vm_ref = self._get_vm_opaque_ref(instance) + vm_ref = self._get_vm_opaque_ref(instance, check_rescue=True) try: if reboot_type == "HARD": -- cgit