summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSalvatore Orlando <salvatore.orlando@eu.citrix.com>2011-06-15 12:31:20 +0100
committerSalvatore Orlando <salvatore.orlando@eu.citrix.com>2011-06-15 12:31:20 +0100
commite722689c7b82bbf895213c2ebf9afaf34f292662 (patch)
tree209d93daa991e3b7e8fbaedb7b0e01120e3882e0
parent1f717118f364d06eb9c1fc88548eb3bbc9f7b8eb (diff)
Fixing code to ensure unit tests for objectstore, vhd & snapshots pass
-rw-r--r--nova/tests/test_xenapi.py12
-rw-r--r--nova/tests/xenapi/stubs.py2
-rw-r--r--nova/virt/xenapi/vm_utils.py19
-rw-r--r--nova/virt/xenapi/vmops.py6
4 files changed, 30 insertions, 9 deletions
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py
index 7b6ceeb37..cddade0ce 100644
--- a/nova/tests/test_xenapi.py
+++ b/nova/tests/test_xenapi.py
@@ -350,6 +350,18 @@ class XenAPIVMTestCase(test.TestCase):
self.assertEquals(self.vm['HVM_boot_params'], {})
self.assertEquals(self.vm['HVM_boot_policy'], '')
+ def _list_vdis(self):
+ url = FLAGS.xenapi_connection_url
+ username = FLAGS.xenapi_connection_username
+ password = FLAGS.xenapi_connection_password
+ session = xenapi_conn.XenAPISession(url, username, password)
+ return session.call_xenapi('VDI.get_all')
+
+ def _check_vdis(self, start_list, end_list):
+ for vdi_ref in end_list:
+ if not vdi_ref in start_list:
+ self.fail('Found unexpected VDI:%s' % vdi_ref)
+
def _test_spawn(self, image_ref, kernel_id, ramdisk_id,
instance_type_id="3", os_type="linux",
instance_id=1, check_injection=False):
diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py
index 0ecf83187..91731ad01 100644
--- a/nova/tests/xenapi/stubs.py
+++ b/nova/tests/xenapi/stubs.py
@@ -151,7 +151,7 @@ class FakeSessionForVMTests(fake.SessionBase):
def host_call_plugin(self, _1, _2, plugin, method, _5):
# copy_kernel_vdi returns nothing
- if fn == 'copy_kernel_vdi':
+ if method == 'copy_kernel_vdi':
return
sr_ref = fake.get_all('SR')[0]
vdi_ref = fake.create_vdi('', False, sr_ref, False)
diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py
index 43621cf2f..322f258b4 100644
--- a/nova/virt/xenapi/vm_utils.py
+++ b/nova/virt/xenapi/vm_utils.py
@@ -503,6 +503,7 @@ class VMHelper(HelperBase):
# VHD disk, it may be worth using the plugin for both VHD and RAW and
# DISK restores
LOG.debug(_("Fetching image %(image)s") % locals())
+ LOG.debug(_("Image Type: %s"), ImageType.pretty_format(image_type))
sr_ref = safe_find_sr(session)
glance_client, image_id = nova.image.get_glance_client(image)
@@ -512,7 +513,6 @@ class VMHelper(HelperBase):
#vdi_type = 'file' # will be set to os if image_type==ImageType.DISK
LOG.debug(_("Size for image %(image)s:" +
"%(virtual_size)d") % locals())
-
if image_type == ImageType.DISK:
# Make room for MBR.
vdi_size += MBR_SIZE_BYTES
@@ -531,6 +531,7 @@ class VMHelper(HelperBase):
try:
filename = None
vdi_uuid = session.get_xenapi().VDI.get_uuid(vdi_ref)
+ LOG.debug("HERE-1")
with_vdi_attached_here(session, vdi_ref, False,
lambda dev:
_stream_disk(dev, image_type,
@@ -538,6 +539,7 @@ class VMHelper(HelperBase):
if image_type in (ImageType.KERNEL, ImageType.RAMDISK):
#we need to invoke a plugin for copying VDI's
#content into proper path
+ LOG.debug("HERE-2")
LOG.debug(_("Copying VDI %s to /boot/guest on dom0"), vdi_ref)
fn = "copy_kernel_vdi"
args = {}
@@ -563,7 +565,7 @@ class VMHelper(HelperBase):
e.args = e.args + ([dict(vdi_type=ImageType.
pretty_format(image_type),
vdi_uuid=vdi_uuid,
- file=filename)],)
+ file=filename)],)
raise e
@classmethod
@@ -663,10 +665,15 @@ class VMHelper(HelperBase):
if image_type == ImageType.DISK_RAW:
args['raw'] = 'true'
task = session.async_call_plugin('objectstore', fn, args)
- uuid_or_fn = session.wait_for_task(task, instance_id)
- if not image_type in (ImageType.KERNEL, ImageType.RAMDISK):
- return [dict(vdi_type='os', vdi_uuid=uuid_or_fn)]
- return uuid_or_fn
+ vdi_uuid = None
+ filename = None
+ if image_type in (ImageType.KERNEL, ImageType.RAMDISK):
+ filename = session.wait_for_task(task, instance_id)
+ else:
+ vdi_uuid = session.wait_for_task(task, instance_id)
+ return [dict(vdi_type=ImageType.pretty_format(image_type),
+ vdi_uuid=vdi_uuid,
+ file=filename)]
@classmethod
def determine_is_pv(cls, session, instance_id, vdi_ref, disk_image_type,
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index c198bee4a..e3e32a266 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -166,7 +166,6 @@ class VMOps(object):
ramdisk = VMHelper.fetch_image(self._session, instance.id,
instance.ramdisk_id, user, project,
ImageType.RAMDISK)[0]
-
# Create the VM ref and attach the first disk
first_vdi_ref = self._session.call_xenapi('VDI.get_by_uuid',
vdis[0]['vdi_uuid'])
@@ -174,7 +173,9 @@ class VMOps(object):
instance.id, first_vdi_ref, disk_image_type,
instance.os_type)
vm_ref = VMHelper.create_vm(self._session, instance,
- kernel['file'], ramdisk['file'], use_pv_kernel)
+ kernel and kernel.get('file', None) or None,
+ ramdisk and ramdisk.get('file', None) or None,
+ use_pv_kernel)
except (self.XenAPI.Failure, OSError, IOError) as vm_create_error:
# collect resources to clean up
# _handle_spawn_error will remove unused resources
@@ -288,6 +289,7 @@ class VMOps(object):
def _handle_spawn_error(self, vdis, spawn_error):
# extract resource dictionary from spawn error
+ resources = []
if spawn_error.args:
last_arg = spawn_error.args[-1]
resources = last_arg