Skip to content

Commit

Permalink
Fix booting a raw image on XenServer
Browse files Browse the repository at this point in the history
Fixes bug 1055413.

ImageType.from_string removed, as it was only used by its test.
Introduced ImageType.get_role, that returns the image's role within the
VM. In case of DISK_* image types, the role is always 'root'. Role
should be the key when accessing the vdis dictionary.

Change-Id: Ieb952a9246d06a8280510113a98b888237abcc65
  • Loading branch information
Mate Lakat authored and Chuck Short committed Oct 5, 2012
1 parent 9e20735 commit bddb06d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
22 changes: 18 additions & 4 deletions nova/tests/test_xenapi.py
Expand Up @@ -1172,11 +1172,25 @@ def test_to_string(self):
vm_utils.ImageType.to_string(vm_utils.ImageType.KERNEL),
vm_utils.ImageType.KERNEL_STR)

def test_from_string(self):
"""Can convert from string to type id."""
def _assert_role(self, expected_role, image_type_id):
self.assertEquals(
vm_utils.ImageType.from_string(vm_utils.ImageType.KERNEL_STR),
vm_utils.ImageType.KERNEL)
expected_role,
vm_utils.ImageType.get_role(image_type_id))

def test_get_image_role_kernel(self):
self._assert_role('kernel', vm_utils.ImageType.KERNEL)

def test_get_image_role_ramdisk(self):
self._assert_role('ramdisk', vm_utils.ImageType.RAMDISK)

def test_get_image_role_disk(self):
self._assert_role('root', vm_utils.ImageType.DISK)

def test_get_image_role_disk_raw(self):
self._assert_role('root', vm_utils.ImageType.DISK_RAW)

def test_get_image_role_disk_vhd(self):
self._assert_role('root', vm_utils.ImageType.DISK_VHD)


class XenAPIDetermineDiskImageTestCase(test.TestCase):
Expand Down
23 changes: 15 additions & 8 deletions nova/virt/xenapi/vm_utils.py
Expand Up @@ -134,8 +134,16 @@ def to_string(cls, image_type):
return dict(zip(ImageType._ids, ImageType._strs)).get(image_type)

@classmethod
def from_string(cls, image_type_str):
return dict(zip(ImageType._strs, ImageType._ids)).get(image_type_str)
def get_role(cls, image_type_id):
" Get the role played by the image, based on its type "
return {
cls.KERNEL: 'kernel',
cls.RAMDISK: 'ramdisk',
cls.DISK: 'root',
cls.DISK_RAW: 'root',
cls.DISK_VHD: 'root',
cls.DISK_ISO: 'iso'
}.get(image_type_id)


def create_vm(session, instance, name_label, kernel, ramdisk,
Expand Down Expand Up @@ -864,8 +872,7 @@ def _create_cached_image(context, session, instance, name_label,
session.call_xenapi('VDI.remove_from_other_config',
new_vdi_ref, 'image-id')

vdi_type = ("root" if image_type == ImageType.DISK_VHD
else ImageType.to_string(image_type))
vdi_type = ImageType.get_role(image_type)
vdi_uuid = session.call_xenapi('VDI.get_uuid', new_vdi_ref)
vdis[vdi_type] = dict(uuid=vdi_uuid, file=None)

Expand Down Expand Up @@ -1136,11 +1143,11 @@ def _fetch_disk_image(context, session, instance, name_label, image_id,
destroy_vdi(session, vdi_ref)
LOG.debug(_("Kernel/Ramdisk VDI %s destroyed"), vdi_ref,
instance=instance)
vdi_type = ImageType.to_string(image_type)
return {vdi_type: dict(uuid=None, file=filename)}
vdi_role = ImageType.get_role(image_type)
return {vdi_role: dict(uuid=None, file=filename)}
else:
vdi_type = ImageType.to_string(image_type)
return {vdi_type: dict(uuid=vdi_uuid, file=None)}
vdi_role = ImageType.get_role(image_type)
return {vdi_role: dict(uuid=vdi_uuid, file=None)}
except (session.XenAPI.Failure, IOError, OSError) as e:
# We look for XenAPI and OS failures.
LOG.exception(_("Failed to fetch glance image"),
Expand Down

0 comments on commit bddb06d

Please sign in to comment.