XenAPI: Don't hardcode userdevice for VBDs

Cleanup and refactor the way VBDs are allocated so it's clearer what
userdevice each VDI is allocated to. Also, use a dict of VDIs instead
of a list since it's nonsensical to have multiple VDIs of any type
and simplifies the code somewhat.

Change-Id: I46d6215dbd90822970a874af66f22c9a34529a40
This commit is contained in:
Johannes Erdfelt
2012-05-30 23:23:14 +00:00
parent b97744a445
commit 14dc493355
2 changed files with 31 additions and 19 deletions

View File

@@ -876,7 +876,8 @@ class XenAPIMigrateInstance(test.TestCase):
conn = xenapi_conn.get_connection(False)
vdi_ref = xenapi_fake.create_vdi('hurr', 'fake')
vdi_uuid = xenapi_fake.get_record('VDI', vdi_ref)['uuid']
conn._vmops._resize_instance(instance, vdi_uuid)
conn._vmops._resize_instance(instance,
{'uuid': vdi_uuid, 'ref': vdi_ref})
self.assertEqual(called['resize'], True)
def test_migrate_disk_and_power_off(self):
@@ -1170,14 +1171,18 @@ class XenAPIAutoDiskConfigTestCase(test.TestCase):
self.stubs.Set(vm_utils, "_resize_part_and_fs",
fake_resize_part_and_fs)
instance = db.instance_create(self.context, self.instance_values)
disk_image_type = vm_utils.ImageType.DISK_VHD
vm_ref = "blah"
first_vdi_ref = "blah"
vdis = ["blah"]
ctx = context.RequestContext(self.user_id, self.project_id)
session = xenapi_conn.XenAPISession('test_url', 'root', 'test_pass')
self.conn._vmops._attach_disks(
instance, disk_image_type, vm_ref, first_vdi_ref, vdis)
disk_image_type = vm_utils.ImageType.DISK_VHD
instance = db.instance_create(self.context, self.instance_values)
vm_ref = xenapi_fake.create_vm(instance['name'], 'Halted')
vdi_ref = xenapi_fake.create_vdi(instance['name'], 'fake')
vdi_uuid = session.call_xenapi('VDI.get_record', vdi_ref)['uuid']
vdis = {'root': {'uuid': vdi_uuid, 'ref': vdi_ref}}
self.conn._vmops._attach_disks(instance, disk_image_type, vm_ref, vdis)
self.assertEqual(marker["partition_called"], called)
@@ -1256,14 +1261,18 @@ class XenAPIGenerateLocal(test.TestCase):
fake_create_vbd)
def assertCalled(self, instance):
ctx = context.RequestContext(self.user_id, self.project_id)
session = xenapi_conn.XenAPISession('test_url', 'root', 'test_pass')
disk_image_type = vm_utils.ImageType.DISK_VHD
vm_ref = "blah"
first_vdi_ref = "blah"
vdis = ["blah"]
vm_ref = xenapi_fake.create_vm(instance['name'], 'Halted')
vdi_ref = xenapi_fake.create_vdi(instance['name'], 'fake')
vdi_uuid = session.call_xenapi('VDI.get_record', vdi_ref)['uuid']
vdis = {'root': {'uuid': vdi_uuid, 'ref': vdi_ref}}
self.called = False
self.conn._vmops._attach_disks(instance, disk_image_type,
vm_ref, first_vdi_ref, vdis)
self.conn._vmops._attach_disks(instance, disk_image_type, vm_ref, vdis)
self.assertTrue(self.called)
def test_generate_swap(self):

View File

@@ -39,7 +39,9 @@ def stubout_firewall_driver(stubs, conn):
def stubout_instance_snapshot(stubs):
@classmethod
def fake_fetch_image(cls, context, session, instance, image, type):
return [dict(vdi_type='root', vdi_uuid=_make_fake_vdi())]
return {'root': dict(uuid=_make_fake_vdi(), file=None),
'kernel': dict(uuid=_make_fake_vdi(), file=None),
'ramdisk': dict(uuid=_make_fake_vdi(), file=None)}
stubs.Set(vm_utils.VMHelper, 'fetch_image', fake_fetch_image)
@@ -134,9 +136,8 @@ def stubout_fetch_image_glance_disk(stubs, raise_failure=False):
else:
filename = "unknown"
return [dict(vdi_type=vm_utils.ImageType.to_string(image_type),
vdi_uuid=None,
file=filename)]
vdi_type = vm_utils.ImageType.to_string(image_type)
return {vdi_type: dict(uuid=None, file=filename)}
stubs.Set(vm_utils.VMHelper, '_fetch_image_glance_disk',
_fake_fetch_image_glance_disk)
@@ -338,8 +339,10 @@ def stub_out_migration_methods(stubs):
return 'vm_ref', dict(image='foo', snap='bar')
def fake_move_disks(self, instance, disk_info):
vdi_ref = fake.create_vdi('new', 'fake')
return fake.get_record('VDI', vdi_ref)['uuid']
vdi_ref = fake.create_vdi(instance['name'], 'fake')
vdi_rec = fake.get_record('VDI', vdi_ref)
vdi_rec['other_config']['nova_disk_type'] = 'root'
return {'uuid': vdi_rec['uuid'], 'ref': vdi_ref}
@classmethod
def fake_get_vdi(cls, session, vm_ref):