From 4ef69baf6b7e4cf2b971acefff8372ba68a234e2 Mon Sep 17 00:00:00 2001 From: Armando Migliaccio Date: Fri, 7 Dec 2012 21:06:43 +0000 Subject: [PATCH] Fixes KeyError: 'sr_uuid' when booting from volume on xenapi This change fixes the capability for a XenServer/XCP hypervisor to boot instances from an iscsi volume running on Cinder. This patch takes into account that Cinder can be configured with an iscsi back-end, instead of a xensm one, where keys like sr_uuid are not being specified. It works through the magic of determining the SR, and the vdi associated with the iscsi target and lun. This patch also does a bit of clean-up of code/comments that no longer apply. Addresses bug #1087308 Change-Id: Ie7d65eeb965b3468e4407981788725e2b43bff5e --- nova/tests/xenapi/test_vm_utils.py | 52 ++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/nova/tests/xenapi/test_vm_utils.py b/nova/tests/xenapi/test_vm_utils.py index 3a8c9a640..a12c0f268 100644 --- a/nova/tests/xenapi/test_vm_utils.py +++ b/nova/tests/xenapi/test_vm_utils.py @@ -10,6 +10,29 @@ from nova.virt.xenapi import volume_utils import unittest +XENSM_TYPE = 'xensm' +ISCSI_TYPE = 'iscsi' + + +def get_fake_dev_params(sr_type): + fakes = {XENSM_TYPE: {'sr_uuid': 'falseSR', + 'name_label': 'fake_storage', + 'name_description': 'test purposes', + 'server': 'myserver', + 'serverpath': '/local/scratch/myname', + 'sr_type': 'nfs', + 'introduce_sr_keys': ['server', + 'serverpath', + 'sr_type'], + 'vdi_uuid': 'falseVDI'}, + ISCSI_TYPE: {'volume_id': 'fake_volume_id', + 'target_lun': 1, + 'target_iqn': 'fake_iqn:volume-fake_volume_id', + 'target_portal': u'localhost:3260', + 'target_discovered': False}, } + return fakes[sr_type] + + class GetInstanceForVdisForSrTestCase(stubs.XenAPITestBase): def setUp(self): super(GetInstanceForVdisForSrTestCase, self).setUp() @@ -50,15 +73,8 @@ class GetInstanceForVdisForSrTestCase(stubs.XenAPITestBase): self.assertEquals([], result) - def test_get_vdis_for_boot_from_vol(self): - dev_params = {'sr_uuid': 'falseSR', - 'name_label': 'fake_storage', - 'name_description': 'test purposes', - 'server': 'myserver', - 'serverpath': '/local/scratch/myname', - 'sr_type': 'nfs', - 'introduce_sr_keys': ['server', 'serverpath', 'sr_type'], - 'vdi_uuid': 'falseVDI'} + def test_get_vdis_for_boot_from_vol_with_sr_uuid(self): + dev_params = get_fake_dev_params(XENSM_TYPE) stubs.stubout_session(self.stubs, fake.SessionBase) driver = xenapi_conn.XenAPIDriver(False) @@ -74,18 +90,20 @@ class GetInstanceForVdisForSrTestCase(stubs.XenAPITestBase): return None self.stubs.Set(volume_utils, 'introduce_sr', bad_introduce_sr) - dev_params = {'sr_uuid': 'falseSR', - 'name_label': 'fake_storage', - 'name_description': 'test purposes', - 'server': 'myserver', - 'serverpath': '/local/scratch/myname', - 'sr_type': 'nfs', - 'introduce_sr_keys': ['server', 'serverpath', 'sr_type'], - 'vdi_uuid': 'falseVDI'} + dev_params = get_fake_dev_params(XENSM_TYPE) self.assertRaises(exception.NovaException, vm_utils.get_vdis_for_boot_from_vol, driver._session, dev_params) + def test_get_vdis_for_boot_from_iscsi_vol_missing_sr_uuid(self): + dev_params = get_fake_dev_params(ISCSI_TYPE) + stubs.stubout_session(self.stubs, fake.SessionBase) + driver = xenapi_conn.XenAPIDriver(False) + + result = vm_utils.get_vdis_for_boot_from_vol(driver._session, + dev_params) + self.assertNotEquals(result['root']['uuid'], None) + class VMRefOrRaiseVMFoundTestCase(unittest.TestCase):