Added unit tests for the xenapi-glance integration. This adds a glance
simulator that can stub in place of glance.client.Client, and enhances the xapi simulator to add the additional calls that the Glance-specific path requires. The test itself is just the spawn test, but now we run through with xenapi_image_service set to "objectstore", and then again set to "glance".
This commit is contained in:
@@ -33,6 +33,7 @@ from nova.virt.xenapi import fake as xenapi_fake
|
|||||||
from nova.virt.xenapi import volume_utils
|
from nova.virt.xenapi import volume_utils
|
||||||
from nova.tests.db import fakes as db_fakes
|
from nova.tests.db import fakes as db_fakes
|
||||||
from nova.tests.xenapi import stubs
|
from nova.tests.xenapi import stubs
|
||||||
|
from nova.tests.glance import stubs as glance_stubs
|
||||||
|
|
||||||
FLAGS = flags.FLAGS
|
FLAGS = flags.FLAGS
|
||||||
|
|
||||||
@@ -107,18 +108,16 @@ class XenAPIVolumeTestCase(test.TestCase):
|
|||||||
conn = xenapi_conn.get_connection(False)
|
conn = xenapi_conn.get_connection(False)
|
||||||
volume = self._create_volume()
|
volume = self._create_volume()
|
||||||
instance = db.instance_create(self.values)
|
instance = db.instance_create(self.values)
|
||||||
xenapi_fake.create_vm(instance.name, 'Running')
|
vm = xenapi_fake.create_vm(instance.name, 'Running')
|
||||||
result = conn.attach_volume(instance.name, volume['id'], '/dev/sdc')
|
result = conn.attach_volume(instance.name, volume['id'], '/dev/sdc')
|
||||||
|
|
||||||
def check():
|
def check():
|
||||||
# check that the VM has a VBD attached to it
|
# check that the VM has a VBD attached to it
|
||||||
# Get XenAPI reference for the VM
|
|
||||||
vms = xenapi_fake.get_all('VM')
|
|
||||||
# Get XenAPI record for VBD
|
# Get XenAPI record for VBD
|
||||||
vbds = xenapi_fake.get_all('VBD')
|
vbds = xenapi_fake.get_all('VBD')
|
||||||
vbd = xenapi_fake.get_record('VBD', vbds[0])
|
vbd = xenapi_fake.get_record('VBD', vbds[0])
|
||||||
vm_ref = vbd['VM']
|
vm_ref = vbd['VM']
|
||||||
self.assertEqual(vm_ref, vms[0])
|
self.assertEqual(vm_ref, vm)
|
||||||
|
|
||||||
check()
|
check()
|
||||||
|
|
||||||
@@ -156,9 +155,14 @@ class XenAPIVMTestCase(test.TestCase):
|
|||||||
FLAGS.xenapi_connection_url = 'test_url'
|
FLAGS.xenapi_connection_url = 'test_url'
|
||||||
FLAGS.xenapi_connection_password = 'test_pass'
|
FLAGS.xenapi_connection_password = 'test_pass'
|
||||||
xenapi_fake.reset()
|
xenapi_fake.reset()
|
||||||
|
xenapi_fake.create_local_srs()
|
||||||
db_fakes.stub_out_db_instance_api(self.stubs)
|
db_fakes.stub_out_db_instance_api(self.stubs)
|
||||||
xenapi_fake.create_network('fake', FLAGS.flat_network_bridge)
|
xenapi_fake.create_network('fake', FLAGS.flat_network_bridge)
|
||||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||||
|
stubs.stubout_get_this_vm_uuid(self.stubs)
|
||||||
|
stubs.stubout_stream_disk(self.stubs)
|
||||||
|
glance_stubs.stubout_glance_client(self.stubs,
|
||||||
|
glance_stubs.FakeGlance)
|
||||||
self.conn = xenapi_conn.get_connection(False)
|
self.conn = xenapi_conn.get_connection(False)
|
||||||
|
|
||||||
def test_list_instances_0(self):
|
def test_list_instances_0(self):
|
||||||
@@ -206,7 +210,15 @@ class XenAPIVMTestCase(test.TestCase):
|
|||||||
|
|
||||||
check()
|
check()
|
||||||
|
|
||||||
def test_spawn(self):
|
def test_spawn_glance(self):
|
||||||
|
FLAGS.xenapi_image_service = 'glance'
|
||||||
|
self._test_spawn()
|
||||||
|
|
||||||
|
def test_spawn_objectstore(self):
|
||||||
|
FLAGS.xenapi_image_service = 'objectstore'
|
||||||
|
self._test_spawn()
|
||||||
|
|
||||||
|
def _test_spawn(self):
|
||||||
instance = self._create_instance()
|
instance = self._create_instance()
|
||||||
|
|
||||||
def check():
|
def check():
|
||||||
@@ -217,8 +229,10 @@ class XenAPIVMTestCase(test.TestCase):
|
|||||||
vm_info = self.conn.get_info(1)
|
vm_info = self.conn.get_info(1)
|
||||||
|
|
||||||
# Get XenAPI record for VM
|
# Get XenAPI record for VM
|
||||||
vms = xenapi_fake.get_all('VM')
|
vms = [rec for ref, rec
|
||||||
vm = xenapi_fake.get_record('VM', vms[0])
|
in xenapi_fake.get_all_records('VM').iteritems()
|
||||||
|
if not rec['is_control_domain']]
|
||||||
|
vm = vms[0]
|
||||||
|
|
||||||
# Check that m1.large above turned into the right thing.
|
# Check that m1.large above turned into the right thing.
|
||||||
instance_type = instance_types.INSTANCE_TYPES['m1.large']
|
instance_type = instance_types.INSTANCE_TYPES['m1.large']
|
||||||
|
|||||||
@@ -91,6 +91,21 @@ def stub_out_get_target(stubs):
|
|||||||
stubs.Set(volume_utils, '_get_target', fake_get_target)
|
stubs.Set(volume_utils, '_get_target', fake_get_target)
|
||||||
|
|
||||||
|
|
||||||
|
def stubout_get_this_vm_uuid(stubs):
|
||||||
|
def f():
|
||||||
|
vms = [rec['uuid'] for ref, rec
|
||||||
|
in fake.get_all_records('VM').iteritems()
|
||||||
|
if rec['is_control_domain']]
|
||||||
|
return vms[0]
|
||||||
|
stubs.Set(vm_utils, 'get_this_vm_uuid', f)
|
||||||
|
|
||||||
|
|
||||||
|
def stubout_stream_disk(stubs):
|
||||||
|
def f(_):
|
||||||
|
pass
|
||||||
|
stubs.Set(vm_utils, '_stream_disk', f)
|
||||||
|
|
||||||
|
|
||||||
class FakeSessionForVMTests(fake.SessionBase):
|
class FakeSessionForVMTests(fake.SessionBase):
|
||||||
""" Stubs out a XenAPISession for VM tests """
|
""" Stubs out a XenAPISession for VM tests """
|
||||||
def __init__(self, uri):
|
def __init__(self, uri):
|
||||||
@@ -100,7 +115,10 @@ class FakeSessionForVMTests(fake.SessionBase):
|
|||||||
return self.xenapi.network.get_all_records()
|
return self.xenapi.network.get_all_records()
|
||||||
|
|
||||||
def host_call_plugin(self, _1, _2, _3, _4, _5):
|
def host_call_plugin(self, _1, _2, _3, _4, _5):
|
||||||
return ''
|
sr_ref = fake.get_all('SR')[0]
|
||||||
|
vdi_ref = fake.create_vdi('', False, sr_ref, False)
|
||||||
|
vdi_rec = fake.get_record('VDI', vdi_ref)
|
||||||
|
return '<string>%s</string>' % vdi_rec['uuid']
|
||||||
|
|
||||||
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)
|
||||||
@@ -135,10 +153,6 @@ class FakeSessionForVolumeTests(fake.SessionBase):
|
|||||||
def __init__(self, uri):
|
def __init__(self, uri):
|
||||||
super(FakeSessionForVolumeTests, self).__init__(uri)
|
super(FakeSessionForVolumeTests, self).__init__(uri)
|
||||||
|
|
||||||
def VBD_plug(self, _1, ref):
|
|
||||||
rec = fake.get_record('VBD', ref)
|
|
||||||
rec['currently-attached'] = True
|
|
||||||
|
|
||||||
def VDI_introduce(self, _1, uuid, _2, _3, _4, _5,
|
def VDI_introduce(self, _1, uuid, _2, _3, _4, _5,
|
||||||
_6, _7, _8, _9, _10, _11):
|
_6, _7, _8, _9, _10, _11):
|
||||||
valid_vdi = False
|
valid_vdi = False
|
||||||
|
|||||||
Reference in New Issue
Block a user