convert virt drivers to fully dynamic loading
Progress on bp:virt-driver-cleanup This series of patches converts the virt drivers to loading via importutils making it possible to add a virt driver without changing core code. It deprecates the use of connection_type in favor of a full driver name in compute_driver. Based on email thread with Vish and Jay Pipes on approaches to do this. Change-Id: I48366ec7efc7b095859988e5e6ac5a853b98b8a7
This commit is contained in:
@@ -152,10 +152,6 @@ class TestCase(unittest.TestCase):
|
|||||||
self.mox.VerifyAll()
|
self.mox.VerifyAll()
|
||||||
super(TestCase, self).tearDown()
|
super(TestCase, self).tearDown()
|
||||||
finally:
|
finally:
|
||||||
if FLAGS.connection_type == 'fake':
|
|
||||||
if hasattr(fake.FakeConnection, '_instance'):
|
|
||||||
del fake.FakeConnection._instance
|
|
||||||
|
|
||||||
if FLAGS.image_service == 'nova.image.fake.FakeImageService':
|
if FLAGS.image_service == 'nova.image.fake.FakeImageService':
|
||||||
nova.image.fake.FakeImageService_reset()
|
nova.image.fake.FakeImageService_reset()
|
||||||
|
|
||||||
|
@@ -260,7 +260,7 @@ class ProxyBareMetalTestCase(test.TestCase):
|
|||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
# Code under test
|
# Code under test
|
||||||
conn = proxy.get_connection(True)
|
conn = proxy.ProxyConnection(True)
|
||||||
# TODO(mikalstill): this is not a very good fake instance
|
# TODO(mikalstill): this is not a very good fake instance
|
||||||
info = conn.get_info({'name': 'instance-00000001'})
|
info = conn.get_info({'name': 'instance-00000001'})
|
||||||
|
|
||||||
|
@@ -33,6 +33,7 @@ flags.DECLARE('volume_driver', 'nova.volume.manager')
|
|||||||
def set_defaults(conf):
|
def set_defaults(conf):
|
||||||
conf.set_default('api_paste_config', '$state_path/etc/nova/api-paste.ini')
|
conf.set_default('api_paste_config', '$state_path/etc/nova/api-paste.ini')
|
||||||
conf.set_default('auth_driver', 'nova.auth.dbdriver.DbDriver')
|
conf.set_default('auth_driver', 'nova.auth.dbdriver.DbDriver')
|
||||||
|
conf.set_default('compute_driver', 'nova.virt.fake.FakeDriver')
|
||||||
conf.set_default('connection_type', 'fake')
|
conf.set_default('connection_type', 'fake')
|
||||||
conf.set_default('fake_network', True)
|
conf.set_default('fake_network', True)
|
||||||
conf.set_default('fake_rabbit', True)
|
conf.set_default('fake_rabbit', True)
|
||||||
|
@@ -91,7 +91,7 @@ class _AuthManagerBaseTestCase(test.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(_AuthManagerBaseTestCase, self).setUp()
|
super(_AuthManagerBaseTestCase, self).setUp()
|
||||||
self.flags(auth_driver=self.auth_driver,
|
self.flags(auth_driver=self.auth_driver,
|
||||||
connection_type='fake')
|
compute_driver='nova.virt.fake.FakeDriver')
|
||||||
self.manager = manager.AuthManager(new=True)
|
self.manager = manager.AuthManager(new=True)
|
||||||
self.manager.mc.cache = {}
|
self.manager.mc.cache = {}
|
||||||
|
|
||||||
|
@@ -48,7 +48,7 @@ class UsageInfoTestCase(test.TestCase):
|
|||||||
self.stubs.Set(nova.network.API, 'get_instance_nw_info',
|
self.stubs.Set(nova.network.API, 'get_instance_nw_info',
|
||||||
fake_get_nw_info)
|
fake_get_nw_info)
|
||||||
|
|
||||||
self.flags(connection_type='fake',
|
self.flags(compute_driver='nova.virt.fake.FakeDriver',
|
||||||
stub_network=True,
|
stub_network=True,
|
||||||
notification_driver='nova.notifier.test_notifier',
|
notification_driver='nova.notifier.test_notifier',
|
||||||
network_manager='nova.network.manager.FlatManager')
|
network_manager='nova.network.manager.FlatManager')
|
||||||
|
@@ -57,6 +57,9 @@ try:
|
|||||||
import libvirt
|
import libvirt
|
||||||
connection.libvirt = libvirt
|
connection.libvirt = libvirt
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
# TODO(sdague): there should be a cleaner way to handle this
|
||||||
|
# in the case where libvirt python isn't installed
|
||||||
|
connection.libvirt = ""
|
||||||
libvirt = None
|
libvirt = None
|
||||||
|
|
||||||
|
|
||||||
@@ -129,7 +132,7 @@ class LibvirtVolumeTestCase(test.TestCase):
|
|||||||
|
|
||||||
self.stubs.Set(utils, 'execute', fake_execute)
|
self.stubs.Set(utils, 'execute', fake_execute)
|
||||||
|
|
||||||
class FakeLibvirtConnection(object):
|
class FakeLibvirtDriver(object):
|
||||||
def __init__(self, hyperv="QEMU"):
|
def __init__(self, hyperv="QEMU"):
|
||||||
self.hyperv = hyperv
|
self.hyperv = hyperv
|
||||||
|
|
||||||
@@ -139,7 +142,7 @@ class LibvirtVolumeTestCase(test.TestCase):
|
|||||||
def get_all_block_devices(self):
|
def get_all_block_devices(self):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
self.fake_conn = FakeLibvirtConnection()
|
self.fake_conn = FakeLibvirtDriver()
|
||||||
self.connr = {
|
self.connr = {
|
||||||
'ip': '127.0.0.1',
|
'ip': '127.0.0.1',
|
||||||
'initiator': 'fake_initiator',
|
'initiator': 'fake_initiator',
|
||||||
@@ -349,7 +352,7 @@ class CacheConcurrencyTestCase(test.TestCase):
|
|||||||
|
|
||||||
def test_same_fname_concurrency(self):
|
def test_same_fname_concurrency(self):
|
||||||
"""Ensures that the same fname cache runs at a sequentially"""
|
"""Ensures that the same fname cache runs at a sequentially"""
|
||||||
conn = connection.LibvirtConnection
|
conn = connection.LibvirtDriver
|
||||||
wait1 = eventlet.event.Event()
|
wait1 = eventlet.event.Event()
|
||||||
done1 = eventlet.event.Event()
|
done1 = eventlet.event.Event()
|
||||||
eventlet.spawn(conn._cache_image, _concurrency,
|
eventlet.spawn(conn._cache_image, _concurrency,
|
||||||
@@ -370,7 +373,7 @@ class CacheConcurrencyTestCase(test.TestCase):
|
|||||||
|
|
||||||
def test_different_fname_concurrency(self):
|
def test_different_fname_concurrency(self):
|
||||||
"""Ensures that two different fname caches are concurrent"""
|
"""Ensures that two different fname caches are concurrent"""
|
||||||
conn = connection.LibvirtConnection
|
conn = connection.LibvirtDriver
|
||||||
wait1 = eventlet.event.Event()
|
wait1 = eventlet.event.Event()
|
||||||
done1 = eventlet.event.Event()
|
done1 = eventlet.event.Event()
|
||||||
eventlet.spawn(conn._cache_image, _concurrency,
|
eventlet.spawn(conn._cache_image, _concurrency,
|
||||||
@@ -440,17 +443,17 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
'instance_type_id': '5'} # m1.small
|
'instance_type_id': '5'} # m1.small
|
||||||
|
|
||||||
def create_fake_libvirt_mock(self, **kwargs):
|
def create_fake_libvirt_mock(self, **kwargs):
|
||||||
"""Defining mocks for LibvirtConnection(libvirt is not used)."""
|
"""Defining mocks for LibvirtDriver(libvirt is not used)."""
|
||||||
|
|
||||||
# A fake libvirt.virConnect
|
# A fake libvirt.virConnect
|
||||||
class FakeLibvirtConnection(object):
|
class FakeLibvirtDriver(object):
|
||||||
def defineXML(self, xml):
|
def defineXML(self, xml):
|
||||||
return FakeVirtDomain()
|
return FakeVirtDomain()
|
||||||
|
|
||||||
# Creating mocks
|
# Creating mocks
|
||||||
volume_driver = 'iscsi=nova.tests.test_libvirt.FakeVolumeDriver'
|
volume_driver = 'iscsi=nova.tests.test_libvirt.FakeVolumeDriver'
|
||||||
self.flags(libvirt_volume_drivers=[volume_driver])
|
self.flags(libvirt_volume_drivers=[volume_driver])
|
||||||
fake = FakeLibvirtConnection()
|
fake = FakeLibvirtDriver()
|
||||||
# Customizing above fake if necessary
|
# Customizing above fake if necessary
|
||||||
for key, val in kwargs.items():
|
for key, val in kwargs.items():
|
||||||
fake.__setattr__(key, val)
|
fake.__setattr__(key, val)
|
||||||
@@ -458,8 +461,8 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
self.flags(image_service='nova.image.fake.FakeImageService')
|
self.flags(image_service='nova.image.fake.FakeImageService')
|
||||||
self.flags(libvirt_vif_driver="nova.tests.fake_network.FakeVIFDriver")
|
self.flags(libvirt_vif_driver="nova.tests.fake_network.FakeVIFDriver")
|
||||||
|
|
||||||
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
|
self.mox.StubOutWithMock(connection.LibvirtDriver, '_conn')
|
||||||
connection.LibvirtConnection._conn = fake
|
connection.LibvirtDriver._conn = fake
|
||||||
|
|
||||||
def fake_lookup(self, instance_name):
|
def fake_lookup(self, instance_name):
|
||||||
return FakeVirtDomain()
|
return FakeVirtDomain()
|
||||||
@@ -483,7 +486,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
self.flags(my_ip=ip)
|
self.flags(my_ip=ip)
|
||||||
self.flags(host=host)
|
self.flags(host=host)
|
||||||
|
|
||||||
conn = connection.LibvirtConnection(True)
|
conn = connection.LibvirtDriver(True)
|
||||||
expected = {
|
expected = {
|
||||||
'ip': ip,
|
'ip': ip,
|
||||||
'initiator': initiator,
|
'initiator': initiator,
|
||||||
@@ -496,7 +499,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
self.assertDictMatch(expected, result)
|
self.assertDictMatch(expected, result)
|
||||||
|
|
||||||
def test_get_guest_config(self):
|
def test_get_guest_config(self):
|
||||||
conn = connection.LibvirtConnection(True)
|
conn = connection.LibvirtDriver(True)
|
||||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||||
|
|
||||||
cfg = conn.get_guest_config(instance_ref,
|
cfg = conn.get_guest_config(instance_ref,
|
||||||
@@ -525,7 +528,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
config.LibvirtConfigGuestGraphics)
|
config.LibvirtConfigGuestGraphics)
|
||||||
|
|
||||||
def test_get_guest_config_with_two_nics(self):
|
def test_get_guest_config_with_two_nics(self):
|
||||||
conn = connection.LibvirtConnection(True)
|
conn = connection.LibvirtDriver(True)
|
||||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||||
|
|
||||||
cfg = conn.get_guest_config(instance_ref,
|
cfg = conn.get_guest_config(instance_ref,
|
||||||
@@ -557,7 +560,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
|
|
||||||
def test_get_guest_config_with_root_device_name(self):
|
def test_get_guest_config_with_root_device_name(self):
|
||||||
self.flags(libvirt_type='uml')
|
self.flags(libvirt_type='uml')
|
||||||
conn = connection.LibvirtConnection(True)
|
conn = connection.LibvirtDriver(True)
|
||||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||||
|
|
||||||
cfg = conn.get_guest_config(instance_ref, [], None, False,
|
cfg = conn.get_guest_config(instance_ref, [], None, False,
|
||||||
@@ -632,12 +635,12 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
"cdrom", "ide")
|
"cdrom", "ide")
|
||||||
|
|
||||||
def test_list_instances(self):
|
def test_list_instances(self):
|
||||||
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
|
self.mox.StubOutWithMock(connection.LibvirtDriver, '_conn')
|
||||||
connection.LibvirtConnection._conn.lookupByID = self.fake_lookup
|
connection.LibvirtDriver._conn.lookupByID = self.fake_lookup
|
||||||
connection.LibvirtConnection._conn.listDomainsID = lambda: [0, 1]
|
connection.LibvirtDriver._conn.listDomainsID = lambda: [0, 1]
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtDriver(False)
|
||||||
instances = conn.list_instances()
|
instances = conn.list_instances()
|
||||||
# Only one should be listed, since domain with ID 0 must be skiped
|
# Only one should be listed, since domain with ID 0 must be skiped
|
||||||
self.assertEquals(len(instances), 1)
|
self.assertEquals(len(instances), 1)
|
||||||
@@ -684,12 +687,12 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
def fake_lookup(id):
|
def fake_lookup(id):
|
||||||
return FakeVirtDomain(xml[id])
|
return FakeVirtDomain(xml[id])
|
||||||
|
|
||||||
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
|
self.mox.StubOutWithMock(connection.LibvirtDriver, '_conn')
|
||||||
connection.LibvirtConnection._conn.listDomainsID = lambda: range(4)
|
connection.LibvirtDriver._conn.listDomainsID = lambda: range(4)
|
||||||
connection.LibvirtConnection._conn.lookupByID = fake_lookup
|
connection.LibvirtDriver._conn.lookupByID = fake_lookup
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtDriver(False)
|
||||||
devices = conn.get_all_block_devices()
|
devices = conn.get_all_block_devices()
|
||||||
self.assertEqual(devices, ['/path/to/dev/1', '/path/to/dev/3'])
|
self.assertEqual(devices, ['/path/to/dev/1', '/path/to/dev/3'])
|
||||||
|
|
||||||
@@ -743,13 +746,13 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
def fake_lookup_name(name):
|
def fake_lookup_name(name):
|
||||||
return FakeVirtDomain(xml[1])
|
return FakeVirtDomain(xml[1])
|
||||||
|
|
||||||
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
|
self.mox.StubOutWithMock(connection.LibvirtDriver, '_conn')
|
||||||
connection.LibvirtConnection._conn.listDomainsID = lambda: range(4)
|
connection.LibvirtDriver._conn.listDomainsID = lambda: range(4)
|
||||||
connection.LibvirtConnection._conn.lookupByID = fake_lookup
|
connection.LibvirtDriver._conn.lookupByID = fake_lookup
|
||||||
connection.LibvirtConnection._conn.lookupByName = fake_lookup_name
|
connection.LibvirtDriver._conn.lookupByName = fake_lookup_name
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtDriver(False)
|
||||||
devices = conn.get_disks(conn.list_instances()[0])
|
devices = conn.get_disks(conn.list_instances()[0])
|
||||||
self.assertEqual(devices, ['vda', 'vdb'])
|
self.assertEqual(devices, ['vda', 'vdb'])
|
||||||
|
|
||||||
@@ -775,14 +778,14 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
# To work with it from snapshot, the single image_service is needed
|
# To work with it from snapshot, the single image_service is needed
|
||||||
recv_meta = image_service.create(context, sent_meta)
|
recv_meta = image_service.create(context, sent_meta)
|
||||||
|
|
||||||
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
|
self.mox.StubOutWithMock(connection.LibvirtDriver, '_conn')
|
||||||
connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
|
connection.LibvirtDriver._conn.lookupByName = self.fake_lookup
|
||||||
self.mox.StubOutWithMock(connection.utils, 'execute')
|
self.mox.StubOutWithMock(connection.utils, 'execute')
|
||||||
connection.utils.execute = self.fake_execute
|
connection.utils.execute = self.fake_execute
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtDriver(False)
|
||||||
conn.snapshot(self.context, instance_ref, recv_meta['id'])
|
conn.snapshot(self.context, instance_ref, recv_meta['id'])
|
||||||
|
|
||||||
snapshot = image_service.show(context, recv_meta['id'])
|
snapshot = image_service.show(context, recv_meta['id'])
|
||||||
@@ -809,14 +812,14 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
# To work with it from snapshot, the single image_service is needed
|
# To work with it from snapshot, the single image_service is needed
|
||||||
recv_meta = image_service.create(context, sent_meta)
|
recv_meta = image_service.create(context, sent_meta)
|
||||||
|
|
||||||
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
|
self.mox.StubOutWithMock(connection.LibvirtDriver, '_conn')
|
||||||
connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
|
connection.LibvirtDriver._conn.lookupByName = self.fake_lookup
|
||||||
self.mox.StubOutWithMock(connection.utils, 'execute')
|
self.mox.StubOutWithMock(connection.utils, 'execute')
|
||||||
connection.utils.execute = self.fake_execute
|
connection.utils.execute = self.fake_execute
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtDriver(False)
|
||||||
conn.snapshot(self.context, instance_ref, recv_meta['id'])
|
conn.snapshot(self.context, instance_ref, recv_meta['id'])
|
||||||
|
|
||||||
snapshot = image_service.show(context, recv_meta['id'])
|
snapshot = image_service.show(context, recv_meta['id'])
|
||||||
@@ -844,14 +847,14 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
# To work with it from snapshot, the single image_service is needed
|
# To work with it from snapshot, the single image_service is needed
|
||||||
recv_meta = image_service.create(context, sent_meta)
|
recv_meta = image_service.create(context, sent_meta)
|
||||||
|
|
||||||
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
|
self.mox.StubOutWithMock(connection.LibvirtDriver, '_conn')
|
||||||
connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
|
connection.LibvirtDriver._conn.lookupByName = self.fake_lookup
|
||||||
self.mox.StubOutWithMock(connection.utils, 'execute')
|
self.mox.StubOutWithMock(connection.utils, 'execute')
|
||||||
connection.utils.execute = self.fake_execute
|
connection.utils.execute = self.fake_execute
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtDriver(False)
|
||||||
conn.snapshot(self.context, instance_ref, recv_meta['id'])
|
conn.snapshot(self.context, instance_ref, recv_meta['id'])
|
||||||
|
|
||||||
snapshot = image_service.show(context, recv_meta['id'])
|
snapshot = image_service.show(context, recv_meta['id'])
|
||||||
@@ -883,14 +886,14 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
# To work with it from snapshot, the single image_service is needed
|
# To work with it from snapshot, the single image_service is needed
|
||||||
recv_meta = image_service.create(context, sent_meta)
|
recv_meta = image_service.create(context, sent_meta)
|
||||||
|
|
||||||
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
|
self.mox.StubOutWithMock(connection.LibvirtDriver, '_conn')
|
||||||
connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
|
connection.LibvirtDriver._conn.lookupByName = self.fake_lookup
|
||||||
self.mox.StubOutWithMock(connection.utils, 'execute')
|
self.mox.StubOutWithMock(connection.utils, 'execute')
|
||||||
connection.utils.execute = self.fake_execute
|
connection.utils.execute = self.fake_execute
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtDriver(False)
|
||||||
conn.snapshot(self.context, instance_ref, recv_meta['id'])
|
conn.snapshot(self.context, instance_ref, recv_meta['id'])
|
||||||
|
|
||||||
snapshot = image_service.show(context, recv_meta['id'])
|
snapshot = image_service.show(context, recv_meta['id'])
|
||||||
@@ -917,14 +920,14 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
'status': 'creating', 'properties': properties}
|
'status': 'creating', 'properties': properties}
|
||||||
recv_meta = image_service.create(context, sent_meta)
|
recv_meta = image_service.create(context, sent_meta)
|
||||||
|
|
||||||
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
|
self.mox.StubOutWithMock(connection.LibvirtDriver, '_conn')
|
||||||
connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
|
connection.LibvirtDriver._conn.lookupByName = self.fake_lookup
|
||||||
self.mox.StubOutWithMock(connection.utils, 'execute')
|
self.mox.StubOutWithMock(connection.utils, 'execute')
|
||||||
connection.utils.execute = self.fake_execute
|
connection.utils.execute = self.fake_execute
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtDriver(False)
|
||||||
conn.snapshot(self.context, instance_ref, recv_meta['id'])
|
conn.snapshot(self.context, instance_ref, recv_meta['id'])
|
||||||
|
|
||||||
snapshot = image_service.show(context, recv_meta['id'])
|
snapshot = image_service.show(context, recv_meta['id'])
|
||||||
@@ -934,9 +937,9 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
|
|
||||||
def test_attach_invalid_volume_type(self):
|
def test_attach_invalid_volume_type(self):
|
||||||
self.create_fake_libvirt_mock()
|
self.create_fake_libvirt_mock()
|
||||||
connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
|
connection.LibvirtDriver._conn.lookupByName = self.fake_lookup
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtDriver(False)
|
||||||
self.assertRaises(exception.VolumeDriverNotFound,
|
self.assertRaises(exception.VolumeDriverNotFound,
|
||||||
conn.attach_volume,
|
conn.attach_volume,
|
||||||
{"driver_volume_type": "badtype"},
|
{"driver_volume_type": "badtype"},
|
||||||
@@ -946,7 +949,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
def test_multi_nic(self):
|
def test_multi_nic(self):
|
||||||
instance_data = dict(self.test_instance)
|
instance_data = dict(self.test_instance)
|
||||||
network_info = _fake_network_info(self.stubs, 2)
|
network_info = _fake_network_info(self.stubs, 2)
|
||||||
conn = connection.LibvirtConnection(True)
|
conn = connection.LibvirtDriver(True)
|
||||||
instance_ref = db.instance_create(self.context, instance_data)
|
instance_ref = db.instance_create(self.context, instance_data)
|
||||||
xml = conn.to_xml(instance_ref, network_info, None, False)
|
xml = conn.to_xml(instance_ref, network_info, None, False)
|
||||||
tree = etree.fromstring(xml)
|
tree = etree.fromstring(xml)
|
||||||
@@ -963,7 +966,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
instance_ref = db.instance_create(user_context, instance)
|
instance_ref = db.instance_create(user_context, instance)
|
||||||
|
|
||||||
self.flags(libvirt_type='lxc')
|
self.flags(libvirt_type='lxc')
|
||||||
conn = connection.LibvirtConnection(True)
|
conn = connection.LibvirtDriver(True)
|
||||||
|
|
||||||
self.assertEquals(conn.uri, 'lxc:///')
|
self.assertEquals(conn.uri, 'lxc:///')
|
||||||
|
|
||||||
@@ -1006,7 +1009,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
|
|
||||||
for (libvirt_type, checks) in type_disk_map.iteritems():
|
for (libvirt_type, checks) in type_disk_map.iteritems():
|
||||||
self.flags(libvirt_type=libvirt_type)
|
self.flags(libvirt_type=libvirt_type)
|
||||||
conn = connection.LibvirtConnection(True)
|
conn = connection.LibvirtDriver(True)
|
||||||
|
|
||||||
network_info = _fake_network_info(self.stubs, 1)
|
network_info = _fake_network_info(self.stubs, 1)
|
||||||
xml = conn.to_xml(instance_ref, network_info)
|
xml = conn.to_xml(instance_ref, network_info)
|
||||||
@@ -1035,14 +1038,14 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
def connection_supports_direct_io_stub(*args, **kwargs):
|
def connection_supports_direct_io_stub(*args, **kwargs):
|
||||||
return directio_supported
|
return directio_supported
|
||||||
|
|
||||||
self.stubs.Set(connection.LibvirtConnection,
|
self.stubs.Set(connection.LibvirtDriver,
|
||||||
'_supports_direct_io', connection_supports_direct_io_stub)
|
'_supports_direct_io', connection_supports_direct_io_stub)
|
||||||
|
|
||||||
user_context = context.RequestContext(self.user_id, self.project_id)
|
user_context = context.RequestContext(self.user_id, self.project_id)
|
||||||
instance_ref = db.instance_create(user_context, self.test_instance)
|
instance_ref = db.instance_create(user_context, self.test_instance)
|
||||||
network_info = _fake_network_info(self.stubs, 1)
|
network_info = _fake_network_info(self.stubs, 1)
|
||||||
|
|
||||||
xml = connection.LibvirtConnection(True).to_xml(instance_ref,
|
xml = connection.LibvirtDriver(True).to_xml(instance_ref,
|
||||||
network_info,
|
network_info,
|
||||||
image_meta)
|
image_meta)
|
||||||
tree = etree.fromstring(xml)
|
tree = etree.fromstring(xml)
|
||||||
@@ -1053,8 +1056,8 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
directio_supported = False
|
directio_supported = False
|
||||||
|
|
||||||
# The O_DIRECT availability is cached on first use in
|
# The O_DIRECT availability is cached on first use in
|
||||||
# LibvirtConnection, hence we re-create it here
|
# LibvirtDriver, hence we re-create it here
|
||||||
xml = connection.LibvirtConnection(True).to_xml(instance_ref,
|
xml = connection.LibvirtDriver(True).to_xml(instance_ref,
|
||||||
network_info,
|
network_info,
|
||||||
image_meta)
|
image_meta)
|
||||||
tree = etree.fromstring(xml)
|
tree = etree.fromstring(xml)
|
||||||
@@ -1067,7 +1070,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
instance_ref = db.instance_create(user_context, self.test_instance)
|
instance_ref = db.instance_create(user_context, self.test_instance)
|
||||||
network_info = _fake_network_info(self.stubs, 1)
|
network_info = _fake_network_info(self.stubs, 1)
|
||||||
|
|
||||||
xml = connection.LibvirtConnection(True).to_xml(instance_ref,
|
xml = connection.LibvirtDriver(True).to_xml(instance_ref,
|
||||||
network_info,
|
network_info,
|
||||||
image_meta)
|
image_meta)
|
||||||
tree = etree.fromstring(xml)
|
tree = etree.fromstring(xml)
|
||||||
@@ -1080,7 +1083,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
instance_ref = db.instance_create(user_context, self.test_instance)
|
instance_ref = db.instance_create(user_context, self.test_instance)
|
||||||
network_info = _fake_network_info(self.stubs, 1)
|
network_info = _fake_network_info(self.stubs, 1)
|
||||||
|
|
||||||
xml = connection.LibvirtConnection(True).to_xml(instance_ref,
|
xml = connection.LibvirtDriver(True).to_xml(instance_ref,
|
||||||
network_info,
|
network_info,
|
||||||
image_meta)
|
image_meta)
|
||||||
tree = etree.fromstring(xml)
|
tree = etree.fromstring(xml)
|
||||||
@@ -1173,7 +1176,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
|
|
||||||
for (libvirt_type, (expected_uri, checks)) in type_uri_map.iteritems():
|
for (libvirt_type, (expected_uri, checks)) in type_uri_map.iteritems():
|
||||||
self.flags(libvirt_type=libvirt_type)
|
self.flags(libvirt_type=libvirt_type)
|
||||||
conn = connection.LibvirtConnection(True)
|
conn = connection.LibvirtDriver(True)
|
||||||
|
|
||||||
self.assertEquals(conn.uri, expected_uri)
|
self.assertEquals(conn.uri, expected_uri)
|
||||||
|
|
||||||
@@ -1202,7 +1205,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
self.flags(libvirt_uri=testuri)
|
self.flags(libvirt_uri=testuri)
|
||||||
for (libvirt_type, (expected_uri, checks)) in type_uri_map.iteritems():
|
for (libvirt_type, (expected_uri, checks)) in type_uri_map.iteritems():
|
||||||
self.flags(libvirt_type=libvirt_type)
|
self.flags(libvirt_type=libvirt_type)
|
||||||
conn = connection.LibvirtConnection(True)
|
conn = connection.LibvirtDriver(True)
|
||||||
self.assertEquals(conn.uri, testuri)
|
self.assertEquals(conn.uri, testuri)
|
||||||
db.instance_destroy(user_context, instance_ref['id'])
|
db.instance_destroy(user_context, instance_ref['id'])
|
||||||
|
|
||||||
@@ -1235,7 +1238,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
# Start test
|
# Start test
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
try:
|
try:
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtDriver(False)
|
||||||
self.stubs.Set(conn.firewall_driver,
|
self.stubs.Set(conn.firewall_driver,
|
||||||
'setup_basic_filtering',
|
'setup_basic_filtering',
|
||||||
fake_none)
|
fake_none)
|
||||||
@@ -1295,7 +1298,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
|
|
||||||
#start test
|
#start test
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtDriver(False)
|
||||||
self.assertRaises(libvirt.libvirtError,
|
self.assertRaises(libvirt.libvirtError,
|
||||||
conn._live_migration,
|
conn._live_migration,
|
||||||
self.context, instance_ref, 'dest', False,
|
self.context, instance_ref, 'dest', False,
|
||||||
@@ -1316,7 +1319,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
vol = {'block_device_mapping': [
|
vol = {'block_device_mapping': [
|
||||||
{'connection_info': 'dummy', 'mount_device': '/dev/sda'},
|
{'connection_info': 'dummy', 'mount_device': '/dev/sda'},
|
||||||
{'connection_info': 'dummy', 'mount_device': '/dev/sdb'}]}
|
{'connection_info': 'dummy', 'mount_device': '/dev/sdb'}]}
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtDriver(False)
|
||||||
|
|
||||||
# Creating mocks
|
# Creating mocks
|
||||||
self.mox.StubOutWithMock(driver, "block_device_info_get_mapping")
|
self.mox.StubOutWithMock(driver, "block_device_info_get_mapping")
|
||||||
@@ -1347,7 +1350,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
# qemu-img should be mockd since test environment might not have
|
# qemu-img should be mockd since test environment might not have
|
||||||
# large disk space.
|
# large disk space.
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtDriver(False)
|
||||||
conn.pre_block_migration(self.context, instance_ref,
|
conn.pre_block_migration(self.context, instance_ref,
|
||||||
dummyjson % tmpdir)
|
dummyjson % tmpdir)
|
||||||
|
|
||||||
@@ -1403,7 +1406,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
os.path.getsize('/test/disk.local').AndReturn((21474836480))
|
os.path.getsize('/test/disk.local').AndReturn((21474836480))
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtDriver(False)
|
||||||
info = conn.get_instance_disk_info(instance_ref.name)
|
info = conn.get_instance_disk_info(instance_ref.name)
|
||||||
info = jsonutils.loads(info)
|
info = jsonutils.loads(info)
|
||||||
self.assertEquals(info[0]['type'], 'raw')
|
self.assertEquals(info[0]['type'], 'raw')
|
||||||
@@ -1435,7 +1438,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
|
|
||||||
# Start test
|
# Start test
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtDriver(False)
|
||||||
self.stubs.Set(conn.firewall_driver,
|
self.stubs.Set(conn.firewall_driver,
|
||||||
'setup_basic_filtering',
|
'setup_basic_filtering',
|
||||||
fake_none)
|
fake_none)
|
||||||
@@ -1493,10 +1496,10 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
return FakeVirtDomain(fake_dom_xml)
|
return FakeVirtDomain(fake_dom_xml)
|
||||||
|
|
||||||
self.create_fake_libvirt_mock()
|
self.create_fake_libvirt_mock()
|
||||||
connection.LibvirtConnection._conn.lookupByName = fake_lookup
|
connection.LibvirtDriver._conn.lookupByName = fake_lookup
|
||||||
connection.libvirt_utils = fake_libvirt_utils
|
connection.libvirt_utils = fake_libvirt_utils
|
||||||
|
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtDriver(False)
|
||||||
output = conn.get_console_output(instance)
|
output = conn.get_console_output(instance)
|
||||||
self.assertEquals("foo", output)
|
self.assertEquals("foo", output)
|
||||||
|
|
||||||
@@ -1537,16 +1540,16 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
return fp.read()
|
return fp.read()
|
||||||
|
|
||||||
self.create_fake_libvirt_mock()
|
self.create_fake_libvirt_mock()
|
||||||
connection.LibvirtConnection._conn.lookupByName = fake_lookup
|
connection.LibvirtDriver._conn.lookupByName = fake_lookup
|
||||||
connection.LibvirtConnection._flush_libvirt_console = _fake_flush
|
connection.LibvirtDriver._flush_libvirt_console = _fake_flush
|
||||||
connection.libvirt_utils = fake_libvirt_utils
|
connection.libvirt_utils = fake_libvirt_utils
|
||||||
|
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtDriver(False)
|
||||||
output = conn.get_console_output(instance)
|
output = conn.get_console_output(instance)
|
||||||
self.assertEquals("foo", output)
|
self.assertEquals("foo", output)
|
||||||
|
|
||||||
def test_get_host_ip_addr(self):
|
def test_get_host_ip_addr(self):
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtDriver(False)
|
||||||
ip = conn.get_host_ip_addr()
|
ip = conn.get_host_ip_addr()
|
||||||
self.assertEquals(ip, FLAGS.my_ip)
|
self.assertEquals(ip, FLAGS.my_ip)
|
||||||
|
|
||||||
@@ -1556,7 +1559,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
(libvirt.VIR_ERR_SYSTEM_ERROR, libvirt.VIR_FROM_REMOTE),
|
(libvirt.VIR_ERR_SYSTEM_ERROR, libvirt.VIR_FROM_REMOTE),
|
||||||
(libvirt.VIR_ERR_SYSTEM_ERROR, libvirt.VIR_FROM_RPC)):
|
(libvirt.VIR_ERR_SYSTEM_ERROR, libvirt.VIR_FROM_RPC)):
|
||||||
|
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtDriver(False)
|
||||||
|
|
||||||
self.mox.StubOutWithMock(conn, "_wrapped_conn")
|
self.mox.StubOutWithMock(conn, "_wrapped_conn")
|
||||||
self.mox.StubOutWithMock(conn._wrapped_conn, "getCapabilities")
|
self.mox.StubOutWithMock(conn._wrapped_conn, "getCapabilities")
|
||||||
@@ -1576,7 +1579,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
self.mox.UnsetStubs()
|
self.mox.UnsetStubs()
|
||||||
|
|
||||||
def test_volume_in_mapping(self):
|
def test_volume_in_mapping(self):
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtDriver(False)
|
||||||
swap = {'device_name': '/dev/sdb',
|
swap = {'device_name': '/dev/sdb',
|
||||||
'swap_size': 1}
|
'swap_size': 1}
|
||||||
ephemerals = [{'num': 0,
|
ephemerals = [{'num': 0,
|
||||||
@@ -1613,9 +1616,9 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
|
|
||||||
@test.skip_if(missing_libvirt(), "Test requires libvirt")
|
@test.skip_if(missing_libvirt(), "Test requires libvirt")
|
||||||
def test_immediate_delete(self):
|
def test_immediate_delete(self):
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtDriver(False)
|
||||||
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
|
self.mox.StubOutWithMock(connection.LibvirtDriver, '_conn')
|
||||||
connection.LibvirtConnection._conn.lookupByName = lambda x: None
|
connection.LibvirtDriver._conn.lookupByName = lambda x: None
|
||||||
|
|
||||||
instance = db.instance_create(self.context, self.test_instance)
|
instance = db.instance_create(self.context, self.test_instance)
|
||||||
conn.destroy(instance, {})
|
conn.destroy(instance, {})
|
||||||
@@ -1634,7 +1637,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
def fake_lookup_by_name(instance_name):
|
def fake_lookup_by_name(instance_name):
|
||||||
return mock
|
return mock
|
||||||
|
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtDriver(False)
|
||||||
self.stubs.Set(conn, '_lookup_by_name', fake_lookup_by_name)
|
self.stubs.Set(conn, '_lookup_by_name', fake_lookup_by_name)
|
||||||
instance = {"name": "instancename", "id": "instanceid",
|
instance = {"name": "instancename", "id": "instanceid",
|
||||||
"uuid": "875a8070-d0b9-4949-8b31-104d125c9a64"}
|
"uuid": "875a8070-d0b9-4949-8b31-104d125c9a64"}
|
||||||
@@ -1642,7 +1645,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
|
|
||||||
def test_available_least_handles_missing(self):
|
def test_available_least_handles_missing(self):
|
||||||
"""Ensure destroy calls managedSaveRemove for saved instance"""
|
"""Ensure destroy calls managedSaveRemove for saved instance"""
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtDriver(False)
|
||||||
|
|
||||||
def list_instances():
|
def list_instances():
|
||||||
return ['fake']
|
return ['fake']
|
||||||
@@ -1702,8 +1705,8 @@ class HostStateTestCase(test.TestCase):
|
|||||||
return 13091
|
return 13091
|
||||||
|
|
||||||
def test_update_status(self):
|
def test_update_status(self):
|
||||||
self.mox.StubOutWithMock(connection, 'get_connection')
|
self.mox.StubOutWithMock(connection, 'LibvirtDriver')
|
||||||
connection.get_connection(True).AndReturn(self.FakeConnection())
|
connection.LibvirtDriver(True).AndReturn(self.FakeConnection())
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
hs = connection.HostState(True)
|
hs = connection.HostState(True)
|
||||||
@@ -1760,11 +1763,11 @@ class IptablesFirewallTestCase(test.TestCase):
|
|||||||
self.project_id = 'fake'
|
self.project_id = 'fake'
|
||||||
self.context = context.RequestContext(self.user_id, self.project_id)
|
self.context = context.RequestContext(self.user_id, self.project_id)
|
||||||
|
|
||||||
class FakeLibvirtConnection(object):
|
class FakeLibvirtDriver(object):
|
||||||
def nwfilterDefineXML(*args, **kwargs):
|
def nwfilterDefineXML(*args, **kwargs):
|
||||||
"""setup_basic_rules in nwfilter calls this."""
|
"""setup_basic_rules in nwfilter calls this."""
|
||||||
pass
|
pass
|
||||||
self.fake_libvirt_connection = FakeLibvirtConnection()
|
self.fake_libvirt_connection = FakeLibvirtDriver()
|
||||||
self.fw = firewall.IptablesFirewallDriver(
|
self.fw = firewall.IptablesFirewallDriver(
|
||||||
get_connection=lambda: self.fake_libvirt_connection)
|
get_connection=lambda: self.fake_libvirt_connection)
|
||||||
|
|
||||||
@@ -2453,11 +2456,11 @@ disk size: 4.4M''', ''))
|
|||||||
self.assertEqual(out, 'c')
|
self.assertEqual(out, 'c')
|
||||||
|
|
||||||
|
|
||||||
class LibvirtConnectionTestCase(test.TestCase):
|
class LibvirtDriverTestCase(test.TestCase):
|
||||||
"""Test for nova.virt.libvirt.connection.LibvirtConnection."""
|
"""Test for nova.virt.libvirt.connection.LibvirtDriver."""
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(LibvirtConnectionTestCase, self).setUp()
|
super(LibvirtDriverTestCase, self).setUp()
|
||||||
self.libvirtconnection = connection.LibvirtConnection(read_only=True)
|
self.libvirtconnection = connection.LibvirtDriver(read_only=True)
|
||||||
|
|
||||||
def _create_instance(self, params=None):
|
def _create_instance(self, params=None):
|
||||||
"""Create a test instance"""
|
"""Create a test instance"""
|
||||||
@@ -2694,5 +2697,5 @@ class LibvirtNonblockingTestCase(test.TestCase):
|
|||||||
def test_connection_to_primitive(self):
|
def test_connection_to_primitive(self):
|
||||||
"""Test bug 962840"""
|
"""Test bug 962840"""
|
||||||
import nova.virt.libvirt.connection
|
import nova.virt.libvirt.connection
|
||||||
connection = nova.virt.libvirt.connection.get_connection('')
|
connection = nova.virt.libvirt.connection.LibvirtDriver('')
|
||||||
jsonutils.to_primitive(connection._conn, convert_instances=True)
|
jsonutils.to_primitive(connection._conn, convert_instances=True)
|
||||||
|
@@ -23,6 +23,7 @@ from nova import exception
|
|||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import image
|
from nova import image
|
||||||
from nova import log as logging
|
from nova import log as logging
|
||||||
|
from nova.openstack.common import importutils
|
||||||
from nova import test
|
from nova import test
|
||||||
from nova.tests import utils as test_utils
|
from nova.tests import utils as test_utils
|
||||||
|
|
||||||
@@ -55,7 +56,7 @@ def catch_notimplementederror(f):
|
|||||||
class _VirtDriverTestCase(test.TestCase):
|
class _VirtDriverTestCase(test.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(_VirtDriverTestCase, self).setUp()
|
super(_VirtDriverTestCase, self).setUp()
|
||||||
self.connection = self.driver_module.get_connection('')
|
self.connection = importutils.import_object(self.driver_module, '')
|
||||||
self.ctxt = test_utils.get_test_admin_context()
|
self.ctxt = test_utils.get_test_admin_context()
|
||||||
self.image_service = image.get_default_image_service()
|
self.image_service = image.get_default_image_service()
|
||||||
|
|
||||||
@@ -400,21 +401,23 @@ class _VirtDriverTestCase(test.TestCase):
|
|||||||
|
|
||||||
class AbstractDriverTestCase(_VirtDriverTestCase):
|
class AbstractDriverTestCase(_VirtDriverTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
import nova.virt.driver
|
from nova.virt.driver import ComputeDriver
|
||||||
|
|
||||||
self.driver_module = nova.virt.driver
|
self.driver_module = "nova.virt.driver.ComputeDriver"
|
||||||
|
|
||||||
def get_driver_connection(_):
|
# TODO(sdague): the abstract driver doesn't have a constructor,
|
||||||
return nova.virt.driver.ComputeDriver()
|
# add one now that the loader loads classes directly
|
||||||
|
def __new_init__(self, read_only=False):
|
||||||
|
super(ComputeDriver, self).__init__()
|
||||||
|
|
||||||
|
ComputeDriver.__init__ = __new_init__
|
||||||
|
|
||||||
self.driver_module.get_connection = get_driver_connection
|
|
||||||
super(AbstractDriverTestCase, self).setUp()
|
super(AbstractDriverTestCase, self).setUp()
|
||||||
|
|
||||||
|
|
||||||
class FakeConnectionTestCase(_VirtDriverTestCase):
|
class FakeConnectionTestCase(_VirtDriverTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
import nova.virt.fake
|
self.driver_module = 'nova.virt.fake.FakeDriver'
|
||||||
self.driver_module = nova.virt.fake
|
|
||||||
super(FakeConnectionTestCase, self).setUp()
|
super(FakeConnectionTestCase, self).setUp()
|
||||||
|
|
||||||
|
|
||||||
@@ -444,7 +447,7 @@ class LibvirtConnTestCase(_VirtDriverTestCase):
|
|||||||
FLAGS.instances_path = ''
|
FLAGS.instances_path = ''
|
||||||
|
|
||||||
# Point _VirtDriverTestCase at the right module
|
# Point _VirtDriverTestCase at the right module
|
||||||
self.driver_module = nova.virt.libvirt.connection
|
self.driver_module = 'nova.virt.libvirt.connection.LibvirtDriver'
|
||||||
super(LibvirtConnTestCase, self).setUp()
|
super(LibvirtConnTestCase, self).setUp()
|
||||||
self.flags(firewall_driver=nova.virt.libvirt.firewall.drivers[0],
|
self.flags(firewall_driver=nova.virt.libvirt.firewall.drivers[0],
|
||||||
rescue_image_id="2",
|
rescue_image_id="2",
|
||||||
|
@@ -51,7 +51,7 @@ class VMWareAPIVMTestCase(test.TestCase):
|
|||||||
db_fakes.stub_out_db_instance_api(self.stubs)
|
db_fakes.stub_out_db_instance_api(self.stubs)
|
||||||
stubs.set_stubs(self.stubs)
|
stubs.set_stubs(self.stubs)
|
||||||
glance_stubs.stubout_glance_client(self.stubs)
|
glance_stubs.stubout_glance_client(self.stubs)
|
||||||
self.conn = vmwareapi_conn.get_connection(False)
|
self.conn = vmwareapi_conn.VMWareESXDriver(False)
|
||||||
# NOTE(vish): none of the network plugging code is actually
|
# NOTE(vish): none of the network plugging code is actually
|
||||||
# being tested
|
# being tested
|
||||||
self.network_info = [({'bridge': 'fa0',
|
self.network_info = [({'bridge': 'fa0',
|
||||||
|
@@ -48,7 +48,7 @@ class VolumeTestCase(test.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(VolumeTestCase, self).setUp()
|
super(VolumeTestCase, self).setUp()
|
||||||
self.compute = importutils.import_object(FLAGS.compute_manager)
|
self.compute = importutils.import_object(FLAGS.compute_manager)
|
||||||
self.flags(connection_type='fake')
|
self.flags(compute_driver='nova.virt.fake.FakeDriver')
|
||||||
self.stubs.Set(nova.flags.FLAGS, 'notification_driver',
|
self.stubs.Set(nova.flags.FLAGS, 'notification_driver',
|
||||||
'nova.notifier.test_notifier')
|
'nova.notifier.test_notifier')
|
||||||
self.volume = importutils.import_object(FLAGS.volume_manager)
|
self.volume = importutils.import_object(FLAGS.volume_manager)
|
||||||
|
@@ -36,7 +36,7 @@ class UsageInfoTestCase(test.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(UsageInfoTestCase, self).setUp()
|
super(UsageInfoTestCase, self).setUp()
|
||||||
self.flags(connection_type='fake',
|
self.flags(compute_driver='nova.virt.fake.FakeDriver',
|
||||||
stub_network=True,
|
stub_network=True,
|
||||||
host='fake')
|
host='fake')
|
||||||
self.stubs.Set(nova.flags.FLAGS, 'notification_driver',
|
self.stubs.Set(nova.flags.FLAGS, 'notification_driver',
|
||||||
|
@@ -178,7 +178,7 @@ class XenAPIVolumeTestCase(test.TestCase):
|
|||||||
def test_attach_volume(self):
|
def test_attach_volume(self):
|
||||||
"""This shows how to test Ops classes' methods."""
|
"""This shows how to test Ops classes' methods."""
|
||||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVolumeTests)
|
stubs.stubout_session(self.stubs, stubs.FakeSessionForVolumeTests)
|
||||||
conn = xenapi_conn.get_connection(False)
|
conn = xenapi_conn.XenAPIDriver(False)
|
||||||
volume = self._create_volume()
|
volume = self._create_volume()
|
||||||
instance = db.instance_create(self.context, self.instance_values)
|
instance = db.instance_create(self.context, self.instance_values)
|
||||||
vm = xenapi_fake.create_vm(instance.name, 'Running')
|
vm = xenapi_fake.create_vm(instance.name, 'Running')
|
||||||
@@ -196,7 +196,7 @@ class XenAPIVolumeTestCase(test.TestCase):
|
|||||||
"""This shows how to test when exceptions are raised."""
|
"""This shows how to test when exceptions are raised."""
|
||||||
stubs.stubout_session(self.stubs,
|
stubs.stubout_session(self.stubs,
|
||||||
stubs.FakeSessionForVolumeFailedTests)
|
stubs.FakeSessionForVolumeFailedTests)
|
||||||
conn = xenapi_conn.get_connection(False)
|
conn = xenapi_conn.XenAPIDriver(False)
|
||||||
volume = self._create_volume()
|
volume = self._create_volume()
|
||||||
instance = db.instance_create(self.context, self.instance_values)
|
instance = db.instance_create(self.context, self.instance_values)
|
||||||
xenapi_fake.create_vm(instance.name, 'Running')
|
xenapi_fake.create_vm(instance.name, 'Running')
|
||||||
@@ -232,7 +232,7 @@ class XenAPIVMTestCase(test.TestCase):
|
|||||||
self.user_id = 'fake'
|
self.user_id = 'fake'
|
||||||
self.project_id = 'fake'
|
self.project_id = 'fake'
|
||||||
self.context = context.RequestContext(self.user_id, self.project_id)
|
self.context = context.RequestContext(self.user_id, self.project_id)
|
||||||
self.conn = xenapi_conn.get_connection(False)
|
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||||
|
|
||||||
def test_init_host(self):
|
def test_init_host(self):
|
||||||
session = xenapi_conn.XenAPISession('test_url', 'root', 'test_pass')
|
session = xenapi_conn.XenAPISession('test_url', 'root', 'test_pass')
|
||||||
@@ -708,7 +708,7 @@ class XenAPIVMTestCase(test.TestCase):
|
|||||||
xenapi_fake.create_vbd(vm_ref, "swap", userdevice=1)
|
xenapi_fake.create_vbd(vm_ref, "swap", userdevice=1)
|
||||||
xenapi_fake.create_vbd(vm_ref, "rootfs", userdevice=0)
|
xenapi_fake.create_vbd(vm_ref, "rootfs", userdevice=0)
|
||||||
|
|
||||||
conn = xenapi_conn.get_connection(False)
|
conn = xenapi_conn.XenAPIDriver(False)
|
||||||
image_meta = {'id': glance_stubs.FakeGlance.IMAGE_VHD,
|
image_meta = {'id': glance_stubs.FakeGlance.IMAGE_VHD,
|
||||||
'disk_format': 'vhd'}
|
'disk_format': 'vhd'}
|
||||||
conn.rescue(self.context, instance, [], image_meta)
|
conn.rescue(self.context, instance, [], image_meta)
|
||||||
@@ -725,7 +725,7 @@ class XenAPIVMTestCase(test.TestCase):
|
|||||||
|
|
||||||
def test_unrescue(self):
|
def test_unrescue(self):
|
||||||
instance = self._create_instance()
|
instance = self._create_instance()
|
||||||
conn = xenapi_conn.get_connection(False)
|
conn = xenapi_conn.XenAPIDriver(False)
|
||||||
# Unrescue expects the original instance to be powered off
|
# Unrescue expects the original instance to be powered off
|
||||||
conn.power_off(instance)
|
conn.power_off(instance)
|
||||||
rescue_vm = xenapi_fake.create_vm(instance.name + '-rescue', 'Running')
|
rescue_vm = xenapi_fake.create_vm(instance.name + '-rescue', 'Running')
|
||||||
@@ -733,7 +733,7 @@ class XenAPIVMTestCase(test.TestCase):
|
|||||||
|
|
||||||
def test_unrescue_not_in_rescue(self):
|
def test_unrescue_not_in_rescue(self):
|
||||||
instance = self._create_instance()
|
instance = self._create_instance()
|
||||||
conn = xenapi_conn.get_connection(False)
|
conn = xenapi_conn.XenAPIDriver(False)
|
||||||
# Ensure that it will not unrescue a non-rescued instance.
|
# Ensure that it will not unrescue a non-rescued instance.
|
||||||
self.assertRaises(exception.InstanceNotInRescueMode, conn.unrescue,
|
self.assertRaises(exception.InstanceNotInRescueMode, conn.unrescue,
|
||||||
instance, None)
|
instance, None)
|
||||||
@@ -749,7 +749,7 @@ class XenAPIVMTestCase(test.TestCase):
|
|||||||
def finish_revert_migration(self, instance):
|
def finish_revert_migration(self, instance):
|
||||||
self.finish_revert_migration_called = True
|
self.finish_revert_migration_called = True
|
||||||
|
|
||||||
conn = xenapi_conn.get_connection(False)
|
conn = xenapi_conn.XenAPIDriver(False)
|
||||||
conn._vmops = VMOpsMock()
|
conn._vmops = VMOpsMock()
|
||||||
conn.finish_revert_migration(instance, None)
|
conn.finish_revert_migration(instance, None)
|
||||||
self.assertTrue(conn._vmops.finish_revert_migration_called)
|
self.assertTrue(conn._vmops.finish_revert_migration_called)
|
||||||
@@ -873,7 +873,7 @@ class XenAPIMigrateInstance(test.TestCase):
|
|||||||
"VDI_resize", fake_vdi_resize)
|
"VDI_resize", fake_vdi_resize)
|
||||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests,
|
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests,
|
||||||
product_version=(6, 0, 0))
|
product_version=(6, 0, 0))
|
||||||
conn = xenapi_conn.get_connection(False)
|
conn = xenapi_conn.XenAPIDriver(False)
|
||||||
vdi_ref = xenapi_fake.create_vdi('hurr', 'fake')
|
vdi_ref = xenapi_fake.create_vdi('hurr', 'fake')
|
||||||
vdi_uuid = xenapi_fake.get_record('VDI', vdi_ref)['uuid']
|
vdi_uuid = xenapi_fake.get_record('VDI', vdi_ref)['uuid']
|
||||||
conn._vmops._resize_instance(instance, vdi_uuid)
|
conn._vmops._resize_instance(instance, vdi_uuid)
|
||||||
@@ -883,7 +883,7 @@ class XenAPIMigrateInstance(test.TestCase):
|
|||||||
instance = db.instance_create(self.context, self.instance_values)
|
instance = db.instance_create(self.context, self.instance_values)
|
||||||
xenapi_fake.create_vm(instance.name, 'Running')
|
xenapi_fake.create_vm(instance.name, 'Running')
|
||||||
instance_type = db.instance_type_get_by_name(self.context, 'm1.large')
|
instance_type = db.instance_type_get_by_name(self.context, 'm1.large')
|
||||||
conn = xenapi_conn.get_connection(False)
|
conn = xenapi_conn.XenAPIDriver(False)
|
||||||
conn.migrate_disk_and_power_off(self.context, instance,
|
conn.migrate_disk_and_power_off(self.context, instance,
|
||||||
'127.0.0.1', instance_type, None)
|
'127.0.0.1', instance_type, None)
|
||||||
|
|
||||||
@@ -896,7 +896,7 @@ class XenAPIMigrateInstance(test.TestCase):
|
|||||||
raise exception.MigrationError(reason='test failure')
|
raise exception.MigrationError(reason='test failure')
|
||||||
self.stubs.Set(vmops.VMOps, "_migrate_vhd", fake_raise)
|
self.stubs.Set(vmops.VMOps, "_migrate_vhd", fake_raise)
|
||||||
|
|
||||||
conn = xenapi_conn.get_connection(False)
|
conn = xenapi_conn.XenAPIDriver(False)
|
||||||
self.assertRaises(exception.MigrationError,
|
self.assertRaises(exception.MigrationError,
|
||||||
conn.migrate_disk_and_power_off,
|
conn.migrate_disk_and_power_off,
|
||||||
self.context, instance,
|
self.context, instance,
|
||||||
@@ -923,7 +923,7 @@ class XenAPIMigrateInstance(test.TestCase):
|
|||||||
self.stubs.Set(vmops.VMOps, 'finish_revert_migration',
|
self.stubs.Set(vmops.VMOps, 'finish_revert_migration',
|
||||||
fake_finish_revert_migration)
|
fake_finish_revert_migration)
|
||||||
|
|
||||||
conn = xenapi_conn.get_connection(False)
|
conn = xenapi_conn.XenAPIDriver(False)
|
||||||
network_info = fake_network.fake_get_instance_nw_info(self.stubs,
|
network_info = fake_network.fake_get_instance_nw_info(self.stubs,
|
||||||
spectacular=True)
|
spectacular=True)
|
||||||
image_meta = {'id': instance.image_ref, 'disk_format': 'vhd'}
|
image_meta = {'id': instance.image_ref, 'disk_format': 'vhd'}
|
||||||
@@ -955,7 +955,7 @@ class XenAPIMigrateInstance(test.TestCase):
|
|||||||
self.stubs.Set(stubs.FakeSessionForVMTests,
|
self.stubs.Set(stubs.FakeSessionForVMTests,
|
||||||
"VDI_resize_online", fake_vdi_resize)
|
"VDI_resize_online", fake_vdi_resize)
|
||||||
|
|
||||||
conn = xenapi_conn.get_connection(False)
|
conn = xenapi_conn.XenAPIDriver(False)
|
||||||
network_info = fake_network.fake_get_instance_nw_info(self.stubs,
|
network_info = fake_network.fake_get_instance_nw_info(self.stubs,
|
||||||
spectacular=True)
|
spectacular=True)
|
||||||
image_meta = {'id': instance.image_ref, 'disk_format': 'vhd'}
|
image_meta = {'id': instance.image_ref, 'disk_format': 'vhd'}
|
||||||
@@ -977,7 +977,7 @@ class XenAPIMigrateInstance(test.TestCase):
|
|||||||
|
|
||||||
self.stubs.Set(stubs.FakeSessionForVMTests,
|
self.stubs.Set(stubs.FakeSessionForVMTests,
|
||||||
"VDI_resize_online", fake_vdi_resize)
|
"VDI_resize_online", fake_vdi_resize)
|
||||||
conn = xenapi_conn.get_connection(False)
|
conn = xenapi_conn.XenAPIDriver(False)
|
||||||
network_info = fake_network.fake_get_instance_nw_info(self.stubs,
|
network_info = fake_network.fake_get_instance_nw_info(self.stubs,
|
||||||
spectacular=True)
|
spectacular=True)
|
||||||
image_meta = {'id': instance.image_ref, 'disk_format': 'vhd'}
|
image_meta = {'id': instance.image_ref, 'disk_format': 'vhd'}
|
||||||
@@ -993,7 +993,7 @@ class XenAPIMigrateInstance(test.TestCase):
|
|||||||
|
|
||||||
self.stubs.Set(stubs.FakeSessionForVMTests,
|
self.stubs.Set(stubs.FakeSessionForVMTests,
|
||||||
"VDI_resize_online", fake_vdi_resize)
|
"VDI_resize_online", fake_vdi_resize)
|
||||||
conn = xenapi_conn.get_connection(False)
|
conn = xenapi_conn.XenAPIDriver(False)
|
||||||
network_info = fake_network.fake_get_instance_nw_info(self.stubs,
|
network_info = fake_network.fake_get_instance_nw_info(self.stubs,
|
||||||
spectacular=True)
|
spectacular=True)
|
||||||
# Resize instance would be determined by the compute call
|
# Resize instance would be determined by the compute call
|
||||||
@@ -1083,7 +1083,7 @@ class XenAPIHostTestCase(test.TestCase):
|
|||||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||||
xenapi_fake.reset()
|
xenapi_fake.reset()
|
||||||
xenapi_fake.create_local_srs()
|
xenapi_fake.create_local_srs()
|
||||||
self.conn = xenapi_conn.get_connection(False)
|
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||||
|
|
||||||
def test_host_state(self):
|
def test_host_state(self):
|
||||||
stats = self.conn.get_host_stats()
|
stats = self.conn.get_host_stats()
|
||||||
@@ -1135,7 +1135,7 @@ class XenAPIAutoDiskConfigTestCase(test.TestCase):
|
|||||||
'Dom0IptablesFirewallDriver')
|
'Dom0IptablesFirewallDriver')
|
||||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||||
xenapi_fake.reset()
|
xenapi_fake.reset()
|
||||||
self.conn = xenapi_conn.get_connection(False)
|
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||||
|
|
||||||
self.user_id = 'fake'
|
self.user_id = 'fake'
|
||||||
self.project_id = 'fake'
|
self.project_id = 'fake'
|
||||||
@@ -1228,7 +1228,7 @@ class XenAPIGenerateLocal(test.TestCase):
|
|||||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||||
db_fakes.stub_out_db_instance_api(self.stubs)
|
db_fakes.stub_out_db_instance_api(self.stubs)
|
||||||
xenapi_fake.reset()
|
xenapi_fake.reset()
|
||||||
self.conn = xenapi_conn.get_connection(False)
|
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||||
|
|
||||||
self.user_id = 'fake'
|
self.user_id = 'fake'
|
||||||
self.project_id = 'fake'
|
self.project_id = 'fake'
|
||||||
@@ -1307,7 +1307,7 @@ class XenAPIBWUsageTestCase(test.TestCase):
|
|||||||
'Dom0IptablesFirewallDriver')
|
'Dom0IptablesFirewallDriver')
|
||||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||||
xenapi_fake.reset()
|
xenapi_fake.reset()
|
||||||
self.conn = xenapi_conn.get_connection(False)
|
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _fake_compile_metrics(cls, start_time, stop_time=None):
|
def _fake_compile_metrics(cls, start_time, stop_time=None):
|
||||||
@@ -1384,7 +1384,7 @@ class XenAPIDom0IptablesFirewallTestCase(test.TestCase):
|
|||||||
test_case=self)
|
test_case=self)
|
||||||
self.context = context.RequestContext(self.user_id, self.project_id)
|
self.context = context.RequestContext(self.user_id, self.project_id)
|
||||||
self.network = importutils.import_object(FLAGS.network_manager)
|
self.network = importutils.import_object(FLAGS.network_manager)
|
||||||
self.conn = xenapi_conn.get_connection(False)
|
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||||
self.fw = self.conn._vmops.firewall_driver
|
self.fw = self.conn._vmops.firewall_driver
|
||||||
|
|
||||||
def _create_instance_ref(self):
|
def _create_instance_ref(self):
|
||||||
@@ -1699,7 +1699,7 @@ class XenAPIAggregateTestCase(test.TestCase):
|
|||||||
host_ref = xenapi_fake.get_all('host')[0]
|
host_ref = xenapi_fake.get_all('host')[0]
|
||||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||||
self.context = context.get_admin_context()
|
self.context = context.get_admin_context()
|
||||||
self.conn = xenapi_conn.get_connection(False)
|
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||||
self.fake_metadata = {'master_compute': 'host',
|
self.fake_metadata = {'master_compute': 'host',
|
||||||
'host': xenapi_fake.get_record('host',
|
'host': xenapi_fake.get_record('host',
|
||||||
host_ref)['uuid']}
|
host_ref)['uuid']}
|
||||||
|
Reference in New Issue
Block a user