Change the return from glance to be a list of dictionaries describing VDIs
Fix the rest of the code to account for this Add a test for swap
This commit is contained in:
@@ -395,6 +395,29 @@ class XenAPIVMTestCase(test.TestCase):
|
|||||||
os_type="linux")
|
os_type="linux")
|
||||||
self.check_vm_params_for_linux()
|
self.check_vm_params_for_linux()
|
||||||
|
|
||||||
|
def test_spawn_vhd_glance_swapdisk(self):
|
||||||
|
# Change the default host_call_plugin to one that'll return
|
||||||
|
# a swap disk
|
||||||
|
orig_func = stubs.FakeSessionForVMTests.host_call_plugin
|
||||||
|
|
||||||
|
stubs.FakeSessionForVMTests.host_call_plugin = \
|
||||||
|
stubs.FakeSessionForVMTests.host_call_plugin_swap
|
||||||
|
|
||||||
|
try:
|
||||||
|
# We'll steal the above glance linux test
|
||||||
|
self.test_spawn_vhd_glance_linux()
|
||||||
|
finally:
|
||||||
|
# Make sure to put this back
|
||||||
|
stubs.FakeSessionForVMTests.host_call_plugin = orig_func
|
||||||
|
|
||||||
|
# We should have 2 VBDs.
|
||||||
|
self.assertEqual(len(self.vm['VBDs']), 2)
|
||||||
|
# Now test that we have 1.
|
||||||
|
self.tearDown()
|
||||||
|
self.setUp()
|
||||||
|
self.test_spawn_vhd_glance_linux()
|
||||||
|
self.assertEqual(len(self.vm['VBDs']), 1)
|
||||||
|
|
||||||
def test_spawn_vhd_glance_windows(self):
|
def test_spawn_vhd_glance_windows(self):
|
||||||
FLAGS.xenapi_image_service = 'glance'
|
FLAGS.xenapi_image_service = 'glance'
|
||||||
self._test_spawn(glance_stubs.FakeGlance.IMAGE_VHD, None, None,
|
self._test_spawn(glance_stubs.FakeGlance.IMAGE_VHD, None, None,
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ def stubout_instance_snapshot(stubs):
|
|||||||
sr_ref=sr_ref, sharable=False)
|
sr_ref=sr_ref, sharable=False)
|
||||||
vdi_rec = session.get_xenapi().VDI.get_record(vdi_ref)
|
vdi_rec = session.get_xenapi().VDI.get_record(vdi_ref)
|
||||||
vdi_uuid = vdi_rec['uuid']
|
vdi_uuid = vdi_rec['uuid']
|
||||||
return {'primary_vdi_uuid': vdi_uuid}
|
return [dict(vdi_type='os', vdi_uuid=vdi_uuid)]
|
||||||
|
|
||||||
stubs.Set(vm_utils.VMHelper, 'fetch_image', fake_fetch_image)
|
stubs.Set(vm_utils.VMHelper, 'fetch_image', fake_fetch_image)
|
||||||
|
|
||||||
@@ -134,16 +134,29 @@ class FakeSessionForVMTests(fake.SessionBase):
|
|||||||
super(FakeSessionForVMTests, self).__init__(uri)
|
super(FakeSessionForVMTests, self).__init__(uri)
|
||||||
|
|
||||||
def host_call_plugin(self, _1, _2, plugin, method, _5):
|
def host_call_plugin(self, _1, _2, plugin, method, _5):
|
||||||
|
sr_ref = fake.get_all('SR')[0]
|
||||||
|
vdi_ref = fake.create_vdi('', False, sr_ref, False)
|
||||||
|
vdi_rec = fake.get_record('VDI', vdi_ref)
|
||||||
|
if plugin == "glance" and method == "download_vhd":
|
||||||
|
ret_str = json.dumps([dict(vdi_type='os',
|
||||||
|
vdi_uuid=vdi_rec['uuid'])])
|
||||||
|
else:
|
||||||
|
ret_str = vdi_rec['uuid']
|
||||||
|
return '<string>%s</string>' % ret_str
|
||||||
|
|
||||||
|
def host_call_plugin_swap(self, _1, _2, plugin, method, _5):
|
||||||
sr_ref = fake.get_all('SR')[0]
|
sr_ref = fake.get_all('SR')[0]
|
||||||
vdi_ref = fake.create_vdi('', False, sr_ref, False)
|
vdi_ref = fake.create_vdi('', False, sr_ref, False)
|
||||||
vdi_rec = fake.get_record('VDI', vdi_ref)
|
vdi_rec = fake.get_record('VDI', vdi_ref)
|
||||||
if plugin == "glance" and method == "download_vhd":
|
if plugin == "glance" and method == "download_vhd":
|
||||||
swap_vdi_ref = fake.create_vdi('', False, sr_ref, False)
|
swap_vdi_ref = fake.create_vdi('', False, sr_ref, False)
|
||||||
swap_vdi_rec = fake.get_record('VDI', swap_vdi_ref)
|
swap_vdi_rec = fake.get_record('VDI', swap_vdi_ref)
|
||||||
return '<string>%s</string>' % json.dumps(
|
ret_str = json.dumps(
|
||||||
{'primary_vdi_uuid': vdi_rec['uuid'],
|
[dict(vdi_type='os', vdi_uuid=vdi_rec['uuid']),
|
||||||
'swap_vdi_uuid': swap_vdi_rec['uuid']})
|
dict(vdi_type='swap', vdi_uuid=swap_vdi_rec['uuid'])])
|
||||||
return '<string>%s</string>' % vdi_rec['uuid']
|
else:
|
||||||
|
ret_str = vdi_rec['uuid']
|
||||||
|
return '<string>%s</string>' % ret_str
|
||||||
|
|
||||||
def VM_start(self, _1, ref, _2, _3):
|
def VM_start(self, _1, ref, _2, _3):
|
||||||
vm = fake.get_record('VM', ref)
|
vm = fake.get_record('VM', ref)
|
||||||
|
|||||||
Reference in New Issue
Block a user