diff options
| author | Johannes Erdfelt <johannes.erdfelt@rackspace.com> | 2012-05-30 23:23:14 +0000 |
|---|---|---|
| committer | Johannes Erdfelt <johannes.erdfelt@rackspace.com> | 2012-05-31 23:16:55 +0000 |
| commit | d1d99b3de22853d87548ba2a8fa680012945f960 (patch) | |
| tree | 1aa67ffdbfa391742beb08ac4b9efc7beb3d6f1d /nova/tests | |
| parent | 0dd15a784482f92ad5aca631c1dc26012b62e3eb (diff) | |
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
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/test_xenapi.py | 33 | ||||
| -rw-r--r-- | nova/tests/xenapi/stubs.py | 15 |
2 files changed, 30 insertions, 18 deletions
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 6572f6304..9314c947f 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -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) + 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"] + 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') - self.conn._vmops._attach_disks( - instance, disk_image_type, vm_ref, first_vdi_ref, vdis) + 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): diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index 7486c4d74..e36fd40e9 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -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): |
