summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Lamar <brian.lamar@rackspace.com>2012-05-10 16:54:12 -0400
committerBrian Lamar <brian.lamar@rackspace.com>2012-05-22 17:47:50 -0400
commit1d7b4f1e5eb3d6e00eeaa927c67c765f726b9d77 (patch)
tree61f882fcc6a272a4fd96dbe8aceefcc498085b72
parentfea0ae767dd7d04f33b09c238d8063899bca6c70 (diff)
More accurate rescue mode testing for XenAPI
Update test_rescue to make sure the swap partition wasn't rescued. Since this test fails with the current code, I also updated the code so the test passed. Fixes bug 997835 Change-Id: I9f09b3bbbee0ddfcbfdb243a7dff0b9bae99925d
-rw-r--r--nova/tests/test_xenapi.py17
-rw-r--r--nova/virt/xenapi/fake.py4
-rw-r--r--nova/virt/xenapi/vmops.py15
3 files changed, 22 insertions, 14 deletions
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py
index 7e9265718..3056661b4 100644
--- a/nova/tests/test_xenapi.py
+++ b/nova/tests/test_xenapi.py
@@ -713,13 +713,26 @@ class XenAPIVMTestCase(test.TestCase):
def test_rescue(self):
instance = self._create_instance()
session = xenapi_conn.XenAPISession('test_url', 'root', 'test_pass')
- vm = vm_utils.VMHelper.lookup(session, instance.name)
- vbd = xenapi_fake.create_vbd(vm, None)
+ vm_ref = vm_utils.VMHelper.lookup(session, instance.name)
+
+ xenapi_fake.create_vbd(vm_ref, "swap", userdevice=1)
+ xenapi_fake.create_vbd(vm_ref, "rootfs", userdevice=0)
+
conn = xenapi_conn.get_connection(False)
image_meta = {'id': glance_stubs.FakeGlance.IMAGE_VHD,
'disk_format': 'vhd'}
conn.rescue(self.context, instance, [], image_meta)
+ vm = xenapi_fake.get_record('VM', vm_ref)
+ rescue_name = "%s-rescue" % vm["name_label"]
+ rescue_ref = vm_utils.VMHelper.lookup(session, rescue_name)
+ rescue_vm = xenapi_fake.get_record('VM', rescue_ref)
+
+ vdi_uuids = []
+ for vbd_uuid in rescue_vm["VBDs"]:
+ vdi_uuids.append(xenapi_fake.get_record('VBD', vbd_uuid)["VDI"])
+ self.assertTrue("swap" not in vdi_uuids)
+
def test_unrescue(self):
instance = self._create_instance()
conn = xenapi_conn.get_connection(False)
diff --git a/nova/virt/xenapi/fake.py b/nova/virt/xenapi/fake.py
index 26f1c0847..223f8b109 100644
--- a/nova/virt/xenapi/fake.py
+++ b/nova/virt/xenapi/fake.py
@@ -161,10 +161,10 @@ def create_vdi(name_label, sr_ref, **kwargs):
return _create_object('VDI', vdi_rec)
-def create_vbd(vm_ref, vdi_ref):
+def create_vbd(vm_ref, vdi_ref, userdevice=0):
vbd_rec = {'VM': vm_ref,
'VDI': vdi_ref,
- 'userdevice': '0',
+ 'userdevice': str(userdevice),
'currently_attached': False}
vbd_ref = _create_object('VBD', vbd_rec)
after_VBD_create(vbd_ref, vbd_rec)
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index d28b34f24..7ac455367 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -1014,17 +1014,12 @@ class VMOps(object):
vbd_refs = self._session.call_xenapi("VM.get_VBDs", vm_ref)
- if len(vbd_refs) == 0:
- raise Exception(_("Unable to find VBD for VM"))
- elif len(vbd_refs) == 1:
- # If we only have one VBD, assume it's the root fs
- vbd_ref = vbd_refs[0]
- else:
- # If we have more than one VBD, swap will be first by convention
- # with the root fs coming second
- vbd_ref = vbd_refs[1]
+ for vbd_uuid in vbd_refs:
+ vbd = self._session.call_xenapi("VBD.get_record", vbd_uuid)
+ if vbd["userdevice"] == "0":
+ return vbd["VDI"]
- return self._session.call_xenapi("VBD.get_record", vbd_ref)["VDI"]
+ raise exception.NotFound(_("Unable to find root VBD/VDI for VM"))
def _safe_destroy_vdis(self, vdi_refs):
"""Destroys the requested VDIs, logging any StorageError exceptions."""