Merge "convert virt drivers to fully dynamic loading"
This commit is contained in:
commit
bf9fd420ae
@ -152,10 +152,6 @@ class TestCase(unittest.TestCase):
|
||||
self.mox.VerifyAll()
|
||||
super(TestCase, self).tearDown()
|
||||
finally:
|
||||
if FLAGS.connection_type == 'fake':
|
||||
if hasattr(fake.FakeConnection, '_instance'):
|
||||
del fake.FakeConnection._instance
|
||||
|
||||
if FLAGS.image_service == 'nova.image.fake.FakeImageService':
|
||||
nova.image.fake.FakeImageService_reset()
|
||||
|
||||
|
@ -90,7 +90,7 @@ def get_instances_with_cached_ips(orig_func, *args, **kwargs):
|
||||
class CloudTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
super(CloudTestCase, self).setUp()
|
||||
self.flags(connection_type='fake',
|
||||
self.flags(compute_driver='nova.virt.fake.FakeDriver',
|
||||
stub_network=True)
|
||||
|
||||
def dumb(*args, **kwargs):
|
||||
|
@ -41,7 +41,7 @@ FLAGS = flags.FLAGS
|
||||
class EC2ValidateTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
super(EC2ValidateTestCase, self).setUp()
|
||||
self.flags(connection_type='fake',
|
||||
self.flags(compute_driver='nova.virt.fake.FakeDriver',
|
||||
stub_network=True)
|
||||
|
||||
def dumb(*args, **kwargs):
|
||||
|
@ -260,7 +260,7 @@ class ProxyBareMetalTestCase(test.TestCase):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
# Code under test
|
||||
conn = proxy.get_connection(True)
|
||||
conn = proxy.ProxyConnection(True)
|
||||
# TODO(mikalstill): this is not a very good fake instance
|
||||
info = conn.get_info({'name': 'instance-00000001'})
|
||||
|
||||
|
@ -106,7 +106,7 @@ class BaseTestCase(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(BaseTestCase, self).setUp()
|
||||
self.flags(connection_type='fake',
|
||||
self.flags(compute_driver='nova.virt.fake.FakeDriver',
|
||||
stub_network=True,
|
||||
notification_driver='nova.notifier.test_notifier',
|
||||
network_manager='nova.network.manager.FlatManager')
|
||||
@ -420,12 +420,12 @@ class ComputeTestCase(BaseTestCase):
|
||||
def fake_rescue(self, context, instance_ref, network_info, image_meta):
|
||||
called['rescued'] = True
|
||||
|
||||
self.stubs.Set(nova.virt.fake.FakeConnection, 'rescue', fake_rescue)
|
||||
self.stubs.Set(nova.virt.fake.FakeDriver, 'rescue', fake_rescue)
|
||||
|
||||
def fake_unrescue(self, instance_ref, network_info):
|
||||
called['unrescued'] = True
|
||||
|
||||
self.stubs.Set(nova.virt.fake.FakeConnection, 'unrescue',
|
||||
self.stubs.Set(nova.virt.fake.FakeDriver, 'unrescue',
|
||||
fake_unrescue)
|
||||
|
||||
instance = self._create_fake_instance()
|
||||
@ -593,7 +593,7 @@ class ComputeTestCase(BaseTestCase):
|
||||
'num_cpu': 2,
|
||||
'cpu_time': 0}
|
||||
|
||||
self.stubs.Set(nova.virt.fake.FakeConnection, 'get_info',
|
||||
self.stubs.Set(nova.virt.fake.FakeDriver, 'get_info',
|
||||
fake_driver_get_info)
|
||||
|
||||
self.assertRaises(exception.Invalid,
|
||||
@ -613,7 +613,7 @@ class ComputeTestCase(BaseTestCase):
|
||||
def fake_driver_set_pass(self2, _instance, _pwd):
|
||||
raise exception.NotAuthorized(_('Internal error'))
|
||||
|
||||
self.stubs.Set(nova.virt.fake.FakeConnection, 'set_admin_password',
|
||||
self.stubs.Set(nova.virt.fake.FakeDriver, 'set_admin_password',
|
||||
fake_driver_set_pass)
|
||||
|
||||
instance = self._create_fake_instance()
|
||||
@ -647,7 +647,7 @@ class ComputeTestCase(BaseTestCase):
|
||||
self.assertEqual(contents, "File Contents")
|
||||
called['inject'] = True
|
||||
|
||||
self.stubs.Set(nova.virt.fake.FakeConnection, 'inject_file',
|
||||
self.stubs.Set(nova.virt.fake.FakeDriver, 'inject_file',
|
||||
fake_driver_inject_file)
|
||||
|
||||
instance = self._create_fake_instance()
|
||||
@ -664,7 +664,7 @@ class ComputeTestCase(BaseTestCase):
|
||||
def fake_driver_inject_network(self, instance, network_info):
|
||||
called['inject'] = True
|
||||
|
||||
self.stubs.Set(nova.virt.fake.FakeConnection, 'inject_network_info',
|
||||
self.stubs.Set(nova.virt.fake.FakeDriver, 'inject_network_info',
|
||||
fake_driver_inject_network)
|
||||
|
||||
instance = self._create_fake_instance()
|
||||
@ -681,7 +681,7 @@ class ComputeTestCase(BaseTestCase):
|
||||
def fake_driver_reset_network(self, instance):
|
||||
called['reset'] = True
|
||||
|
||||
self.stubs.Set(nova.virt.fake.FakeConnection, 'reset_network',
|
||||
self.stubs.Set(nova.virt.fake.FakeDriver, 'reset_network',
|
||||
fake_driver_reset_network)
|
||||
|
||||
instance = self._create_fake_instance()
|
||||
@ -700,7 +700,7 @@ class ComputeTestCase(BaseTestCase):
|
||||
self.assertEqual(url, 'http://fake/url/')
|
||||
self.assertEqual(md5hash, 'fakehash')
|
||||
|
||||
self.stubs.Set(nova.virt.fake.FakeConnection, 'agent_update',
|
||||
self.stubs.Set(nova.virt.fake.FakeDriver, 'agent_update',
|
||||
fake_driver_agent_update)
|
||||
|
||||
instance = self._create_fake_instance()
|
||||
|
@ -33,6 +33,7 @@ flags.DECLARE('volume_driver', 'nova.volume.manager')
|
||||
def set_defaults(conf):
|
||||
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('compute_driver', 'nova.virt.fake.FakeDriver')
|
||||
conf.set_default('connection_type', 'fake')
|
||||
conf.set_default('fake_network', True)
|
||||
conf.set_default('fake_rabbit', True)
|
||||
|
@ -56,7 +56,7 @@ class ServersTest(integrated_helpers._IntegratedTestBase):
|
||||
def throw_error(*_):
|
||||
raise Exception()
|
||||
|
||||
self.stubs.Set(nova.virt.fake.FakeConnection, 'spawn', throw_error)
|
||||
self.stubs.Set(nova.virt.fake.FakeDriver, 'spawn', throw_error)
|
||||
|
||||
server = self._build_minimal_create_server_request()
|
||||
created_server = self.api.post_server({"server": server})
|
||||
|
@ -91,7 +91,7 @@ class _AuthManagerBaseTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
super(_AuthManagerBaseTestCase, self).setUp()
|
||||
self.flags(auth_driver=self.auth_driver,
|
||||
connection_type='fake')
|
||||
compute_driver='nova.virt.fake.FakeDriver')
|
||||
self.manager = manager.AuthManager(new=True)
|
||||
self.manager.mc.cache = {}
|
||||
|
||||
|
@ -48,7 +48,7 @@ class UsageInfoTestCase(test.TestCase):
|
||||
self.stubs.Set(nova.network.API, 'get_instance_nw_info',
|
||||
fake_get_nw_info)
|
||||
|
||||
self.flags(connection_type='fake',
|
||||
self.flags(compute_driver='nova.virt.fake.FakeDriver',
|
||||
stub_network=True,
|
||||
notification_driver='nova.notifier.test_notifier',
|
||||
network_manager='nova.network.manager.FlatManager')
|
||||
|
@ -57,6 +57,9 @@ try:
|
||||
import libvirt
|
||||
connection.libvirt = libvirt
|
||||
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
|
||||
|
||||
|
||||
@ -129,7 +132,7 @@ class LibvirtVolumeTestCase(test.TestCase):
|
||||
|
||||
self.stubs.Set(utils, 'execute', fake_execute)
|
||||
|
||||
class FakeLibvirtConnection(object):
|
||||
class FakeLibvirtDriver(object):
|
||||
def __init__(self, hyperv="QEMU"):
|
||||
self.hyperv = hyperv
|
||||
|
||||
@ -139,7 +142,7 @@ class LibvirtVolumeTestCase(test.TestCase):
|
||||
def get_all_block_devices(self):
|
||||
return []
|
||||
|
||||
self.fake_conn = FakeLibvirtConnection()
|
||||
self.fake_conn = FakeLibvirtDriver()
|
||||
self.connr = {
|
||||
'ip': '127.0.0.1',
|
||||
'initiator': 'fake_initiator',
|
||||
@ -349,7 +352,7 @@ class CacheConcurrencyTestCase(test.TestCase):
|
||||
|
||||
def test_same_fname_concurrency(self):
|
||||
"""Ensures that the same fname cache runs at a sequentially"""
|
||||
conn = connection.LibvirtConnection
|
||||
conn = connection.LibvirtDriver
|
||||
wait1 = eventlet.event.Event()
|
||||
done1 = eventlet.event.Event()
|
||||
eventlet.spawn(conn._cache_image, _concurrency,
|
||||
@ -370,7 +373,7 @@ class CacheConcurrencyTestCase(test.TestCase):
|
||||
|
||||
def test_different_fname_concurrency(self):
|
||||
"""Ensures that two different fname caches are concurrent"""
|
||||
conn = connection.LibvirtConnection
|
||||
conn = connection.LibvirtDriver
|
||||
wait1 = eventlet.event.Event()
|
||||
done1 = eventlet.event.Event()
|
||||
eventlet.spawn(conn._cache_image, _concurrency,
|
||||
@ -440,17 +443,17 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
'instance_type_id': '5'} # m1.small
|
||||
|
||||
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
|
||||
class FakeLibvirtConnection(object):
|
||||
class FakeLibvirtDriver(object):
|
||||
def defineXML(self, xml):
|
||||
return FakeVirtDomain()
|
||||
|
||||
# Creating mocks
|
||||
volume_driver = 'iscsi=nova.tests.test_libvirt.FakeVolumeDriver'
|
||||
self.flags(libvirt_volume_drivers=[volume_driver])
|
||||
fake = FakeLibvirtConnection()
|
||||
fake = FakeLibvirtDriver()
|
||||
# Customizing above fake if necessary
|
||||
for key, val in kwargs.items():
|
||||
fake.__setattr__(key, val)
|
||||
@ -458,8 +461,8 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.flags(image_service='nova.image.fake.FakeImageService')
|
||||
self.flags(libvirt_vif_driver="nova.tests.fake_network.FakeVIFDriver")
|
||||
|
||||
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
|
||||
connection.LibvirtConnection._conn = fake
|
||||
self.mox.StubOutWithMock(connection.LibvirtDriver, '_conn')
|
||||
connection.LibvirtDriver._conn = fake
|
||||
|
||||
def fake_lookup(self, instance_name):
|
||||
return FakeVirtDomain()
|
||||
@ -483,7 +486,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.flags(my_ip=ip)
|
||||
self.flags(host=host)
|
||||
|
||||
conn = connection.LibvirtConnection(True)
|
||||
conn = connection.LibvirtDriver(True)
|
||||
expected = {
|
||||
'ip': ip,
|
||||
'initiator': initiator,
|
||||
@ -496,7 +499,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.assertDictMatch(expected, result)
|
||||
|
||||
def test_get_guest_config(self):
|
||||
conn = connection.LibvirtConnection(True)
|
||||
conn = connection.LibvirtDriver(True)
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
|
||||
cfg = conn.get_guest_config(instance_ref,
|
||||
@ -525,7 +528,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
config.LibvirtConfigGuestGraphics)
|
||||
|
||||
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)
|
||||
|
||||
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):
|
||||
self.flags(libvirt_type='uml')
|
||||
conn = connection.LibvirtConnection(True)
|
||||
conn = connection.LibvirtDriver(True)
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
|
||||
cfg = conn.get_guest_config(instance_ref, [], None, False,
|
||||
@ -632,12 +635,12 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
"cdrom", "ide")
|
||||
|
||||
def test_list_instances(self):
|
||||
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
|
||||
connection.LibvirtConnection._conn.lookupByID = self.fake_lookup
|
||||
connection.LibvirtConnection._conn.listDomainsID = lambda: [0, 1]
|
||||
self.mox.StubOutWithMock(connection.LibvirtDriver, '_conn')
|
||||
connection.LibvirtDriver._conn.lookupByID = self.fake_lookup
|
||||
connection.LibvirtDriver._conn.listDomainsID = lambda: [0, 1]
|
||||
|
||||
self.mox.ReplayAll()
|
||||
conn = connection.LibvirtConnection(False)
|
||||
conn = connection.LibvirtDriver(False)
|
||||
instances = conn.list_instances()
|
||||
# Only one should be listed, since domain with ID 0 must be skiped
|
||||
self.assertEquals(len(instances), 1)
|
||||
@ -684,12 +687,12 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
def fake_lookup(id):
|
||||
return FakeVirtDomain(xml[id])
|
||||
|
||||
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
|
||||
connection.LibvirtConnection._conn.listDomainsID = lambda: range(4)
|
||||
connection.LibvirtConnection._conn.lookupByID = fake_lookup
|
||||
self.mox.StubOutWithMock(connection.LibvirtDriver, '_conn')
|
||||
connection.LibvirtDriver._conn.listDomainsID = lambda: range(4)
|
||||
connection.LibvirtDriver._conn.lookupByID = fake_lookup
|
||||
|
||||
self.mox.ReplayAll()
|
||||
conn = connection.LibvirtConnection(False)
|
||||
conn = connection.LibvirtDriver(False)
|
||||
devices = conn.get_all_block_devices()
|
||||
self.assertEqual(devices, ['/path/to/dev/1', '/path/to/dev/3'])
|
||||
|
||||
@ -743,13 +746,13 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
def fake_lookup_name(name):
|
||||
return FakeVirtDomain(xml[1])
|
||||
|
||||
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
|
||||
connection.LibvirtConnection._conn.listDomainsID = lambda: range(4)
|
||||
connection.LibvirtConnection._conn.lookupByID = fake_lookup
|
||||
connection.LibvirtConnection._conn.lookupByName = fake_lookup_name
|
||||
self.mox.StubOutWithMock(connection.LibvirtDriver, '_conn')
|
||||
connection.LibvirtDriver._conn.listDomainsID = lambda: range(4)
|
||||
connection.LibvirtDriver._conn.lookupByID = fake_lookup
|
||||
connection.LibvirtDriver._conn.lookupByName = fake_lookup_name
|
||||
|
||||
self.mox.ReplayAll()
|
||||
conn = connection.LibvirtConnection(False)
|
||||
conn = connection.LibvirtDriver(False)
|
||||
devices = conn.get_disks(conn.list_instances()[0])
|
||||
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
|
||||
recv_meta = image_service.create(context, sent_meta)
|
||||
|
||||
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
|
||||
connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
|
||||
self.mox.StubOutWithMock(connection.LibvirtDriver, '_conn')
|
||||
connection.LibvirtDriver._conn.lookupByName = self.fake_lookup
|
||||
self.mox.StubOutWithMock(connection.utils, 'execute')
|
||||
connection.utils.execute = self.fake_execute
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
conn = connection.LibvirtConnection(False)
|
||||
conn = connection.LibvirtDriver(False)
|
||||
conn.snapshot(self.context, instance_ref, 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
|
||||
recv_meta = image_service.create(context, sent_meta)
|
||||
|
||||
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
|
||||
connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
|
||||
self.mox.StubOutWithMock(connection.LibvirtDriver, '_conn')
|
||||
connection.LibvirtDriver._conn.lookupByName = self.fake_lookup
|
||||
self.mox.StubOutWithMock(connection.utils, 'execute')
|
||||
connection.utils.execute = self.fake_execute
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
conn = connection.LibvirtConnection(False)
|
||||
conn = connection.LibvirtDriver(False)
|
||||
conn.snapshot(self.context, instance_ref, 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
|
||||
recv_meta = image_service.create(context, sent_meta)
|
||||
|
||||
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
|
||||
connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
|
||||
self.mox.StubOutWithMock(connection.LibvirtDriver, '_conn')
|
||||
connection.LibvirtDriver._conn.lookupByName = self.fake_lookup
|
||||
self.mox.StubOutWithMock(connection.utils, 'execute')
|
||||
connection.utils.execute = self.fake_execute
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
conn = connection.LibvirtConnection(False)
|
||||
conn = connection.LibvirtDriver(False)
|
||||
conn.snapshot(self.context, instance_ref, 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
|
||||
recv_meta = image_service.create(context, sent_meta)
|
||||
|
||||
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
|
||||
connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
|
||||
self.mox.StubOutWithMock(connection.LibvirtDriver, '_conn')
|
||||
connection.LibvirtDriver._conn.lookupByName = self.fake_lookup
|
||||
self.mox.StubOutWithMock(connection.utils, 'execute')
|
||||
connection.utils.execute = self.fake_execute
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
conn = connection.LibvirtConnection(False)
|
||||
conn = connection.LibvirtDriver(False)
|
||||
conn.snapshot(self.context, instance_ref, recv_meta['id'])
|
||||
|
||||
snapshot = image_service.show(context, recv_meta['id'])
|
||||
@ -917,14 +920,14 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
'status': 'creating', 'properties': properties}
|
||||
recv_meta = image_service.create(context, sent_meta)
|
||||
|
||||
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
|
||||
connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
|
||||
self.mox.StubOutWithMock(connection.LibvirtDriver, '_conn')
|
||||
connection.LibvirtDriver._conn.lookupByName = self.fake_lookup
|
||||
self.mox.StubOutWithMock(connection.utils, 'execute')
|
||||
connection.utils.execute = self.fake_execute
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
conn = connection.LibvirtConnection(False)
|
||||
conn = connection.LibvirtDriver(False)
|
||||
conn.snapshot(self.context, instance_ref, 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):
|
||||
self.create_fake_libvirt_mock()
|
||||
connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
|
||||
connection.LibvirtDriver._conn.lookupByName = self.fake_lookup
|
||||
self.mox.ReplayAll()
|
||||
conn = connection.LibvirtConnection(False)
|
||||
conn = connection.LibvirtDriver(False)
|
||||
self.assertRaises(exception.VolumeDriverNotFound,
|
||||
conn.attach_volume,
|
||||
{"driver_volume_type": "badtype"},
|
||||
@ -946,7 +949,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
def test_multi_nic(self):
|
||||
instance_data = dict(self.test_instance)
|
||||
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)
|
||||
xml = conn.to_xml(instance_ref, network_info, None, False)
|
||||
tree = etree.fromstring(xml)
|
||||
@ -963,7 +966,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
instance_ref = db.instance_create(user_context, instance)
|
||||
|
||||
self.flags(libvirt_type='lxc')
|
||||
conn = connection.LibvirtConnection(True)
|
||||
conn = connection.LibvirtDriver(True)
|
||||
|
||||
self.assertEquals(conn.uri, 'lxc:///')
|
||||
|
||||
@ -1006,7 +1009,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
for (libvirt_type, checks) in type_disk_map.iteritems():
|
||||
self.flags(libvirt_type=libvirt_type)
|
||||
conn = connection.LibvirtConnection(True)
|
||||
conn = connection.LibvirtDriver(True)
|
||||
|
||||
network_info = _fake_network_info(self.stubs, 1)
|
||||
xml = conn.to_xml(instance_ref, network_info)
|
||||
@ -1035,14 +1038,14 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
def connection_supports_direct_io_stub(*args, **kwargs):
|
||||
return directio_supported
|
||||
|
||||
self.stubs.Set(connection.LibvirtConnection,
|
||||
self.stubs.Set(connection.LibvirtDriver,
|
||||
'_supports_direct_io', connection_supports_direct_io_stub)
|
||||
|
||||
user_context = context.RequestContext(self.user_id, self.project_id)
|
||||
instance_ref = db.instance_create(user_context, self.test_instance)
|
||||
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,
|
||||
image_meta)
|
||||
tree = etree.fromstring(xml)
|
||||
@ -1053,8 +1056,8 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
directio_supported = False
|
||||
|
||||
# The O_DIRECT availability is cached on first use in
|
||||
# LibvirtConnection, hence we re-create it here
|
||||
xml = connection.LibvirtConnection(True).to_xml(instance_ref,
|
||||
# LibvirtDriver, hence we re-create it here
|
||||
xml = connection.LibvirtDriver(True).to_xml(instance_ref,
|
||||
network_info,
|
||||
image_meta)
|
||||
tree = etree.fromstring(xml)
|
||||
@ -1067,7 +1070,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
instance_ref = db.instance_create(user_context, self.test_instance)
|
||||
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,
|
||||
image_meta)
|
||||
tree = etree.fromstring(xml)
|
||||
@ -1080,7 +1083,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
instance_ref = db.instance_create(user_context, self.test_instance)
|
||||
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,
|
||||
image_meta)
|
||||
tree = etree.fromstring(xml)
|
||||
@ -1173,7 +1176,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
for (libvirt_type, (expected_uri, checks)) in type_uri_map.iteritems():
|
||||
self.flags(libvirt_type=libvirt_type)
|
||||
conn = connection.LibvirtConnection(True)
|
||||
conn = connection.LibvirtDriver(True)
|
||||
|
||||
self.assertEquals(conn.uri, expected_uri)
|
||||
|
||||
@ -1202,7 +1205,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.flags(libvirt_uri=testuri)
|
||||
for (libvirt_type, (expected_uri, checks)) in type_uri_map.iteritems():
|
||||
self.flags(libvirt_type=libvirt_type)
|
||||
conn = connection.LibvirtConnection(True)
|
||||
conn = connection.LibvirtDriver(True)
|
||||
self.assertEquals(conn.uri, testuri)
|
||||
db.instance_destroy(user_context, instance_ref['id'])
|
||||
|
||||
@ -1235,7 +1238,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
# Start test
|
||||
self.mox.ReplayAll()
|
||||
try:
|
||||
conn = connection.LibvirtConnection(False)
|
||||
conn = connection.LibvirtDriver(False)
|
||||
self.stubs.Set(conn.firewall_driver,
|
||||
'setup_basic_filtering',
|
||||
fake_none)
|
||||
@ -1295,7 +1298,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
#start test
|
||||
self.mox.ReplayAll()
|
||||
conn = connection.LibvirtConnection(False)
|
||||
conn = connection.LibvirtDriver(False)
|
||||
self.assertRaises(libvirt.libvirtError,
|
||||
conn._live_migration,
|
||||
self.context, instance_ref, 'dest', False,
|
||||
@ -1316,7 +1319,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
vol = {'block_device_mapping': [
|
||||
{'connection_info': 'dummy', 'mount_device': '/dev/sda'},
|
||||
{'connection_info': 'dummy', 'mount_device': '/dev/sdb'}]}
|
||||
conn = connection.LibvirtConnection(False)
|
||||
conn = connection.LibvirtDriver(False)
|
||||
|
||||
# Creating mocks
|
||||
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
|
||||
# large disk space.
|
||||
self.mox.ReplayAll()
|
||||
conn = connection.LibvirtConnection(False)
|
||||
conn = connection.LibvirtDriver(False)
|
||||
conn.pre_block_migration(self.context, instance_ref,
|
||||
dummyjson % tmpdir)
|
||||
|
||||
@ -1403,7 +1406,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
os.path.getsize('/test/disk.local').AndReturn((21474836480))
|
||||
|
||||
self.mox.ReplayAll()
|
||||
conn = connection.LibvirtConnection(False)
|
||||
conn = connection.LibvirtDriver(False)
|
||||
info = conn.get_instance_disk_info(instance_ref.name)
|
||||
info = jsonutils.loads(info)
|
||||
self.assertEquals(info[0]['type'], 'raw')
|
||||
@ -1435,7 +1438,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
# Start test
|
||||
self.mox.ReplayAll()
|
||||
conn = connection.LibvirtConnection(False)
|
||||
conn = connection.LibvirtDriver(False)
|
||||
self.stubs.Set(conn.firewall_driver,
|
||||
'setup_basic_filtering',
|
||||
fake_none)
|
||||
@ -1493,10 +1496,10 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
return FakeVirtDomain(fake_dom_xml)
|
||||
|
||||
self.create_fake_libvirt_mock()
|
||||
connection.LibvirtConnection._conn.lookupByName = fake_lookup
|
||||
connection.LibvirtDriver._conn.lookupByName = fake_lookup
|
||||
connection.libvirt_utils = fake_libvirt_utils
|
||||
|
||||
conn = connection.LibvirtConnection(False)
|
||||
conn = connection.LibvirtDriver(False)
|
||||
output = conn.get_console_output(instance)
|
||||
self.assertEquals("foo", output)
|
||||
|
||||
@ -1537,16 +1540,16 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
return fp.read()
|
||||
|
||||
self.create_fake_libvirt_mock()
|
||||
connection.LibvirtConnection._conn.lookupByName = fake_lookup
|
||||
connection.LibvirtConnection._flush_libvirt_console = _fake_flush
|
||||
connection.LibvirtDriver._conn.lookupByName = fake_lookup
|
||||
connection.LibvirtDriver._flush_libvirt_console = _fake_flush
|
||||
connection.libvirt_utils = fake_libvirt_utils
|
||||
|
||||
conn = connection.LibvirtConnection(False)
|
||||
conn = connection.LibvirtDriver(False)
|
||||
output = conn.get_console_output(instance)
|
||||
self.assertEquals("foo", output)
|
||||
|
||||
def test_get_host_ip_addr(self):
|
||||
conn = connection.LibvirtConnection(False)
|
||||
conn = connection.LibvirtDriver(False)
|
||||
ip = conn.get_host_ip_addr()
|
||||
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_RPC)):
|
||||
|
||||
conn = connection.LibvirtConnection(False)
|
||||
conn = connection.LibvirtDriver(False)
|
||||
|
||||
self.mox.StubOutWithMock(conn, "_wrapped_conn")
|
||||
self.mox.StubOutWithMock(conn._wrapped_conn, "getCapabilities")
|
||||
@ -1576,7 +1579,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.mox.UnsetStubs()
|
||||
|
||||
def test_volume_in_mapping(self):
|
||||
conn = connection.LibvirtConnection(False)
|
||||
conn = connection.LibvirtDriver(False)
|
||||
swap = {'device_name': '/dev/sdb',
|
||||
'swap_size': 1}
|
||||
ephemerals = [{'num': 0,
|
||||
@ -1613,9 +1616,9 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
@test.skip_if(missing_libvirt(), "Test requires libvirt")
|
||||
def test_immediate_delete(self):
|
||||
conn = connection.LibvirtConnection(False)
|
||||
self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
|
||||
connection.LibvirtConnection._conn.lookupByName = lambda x: None
|
||||
conn = connection.LibvirtDriver(False)
|
||||
self.mox.StubOutWithMock(connection.LibvirtDriver, '_conn')
|
||||
connection.LibvirtDriver._conn.lookupByName = lambda x: None
|
||||
|
||||
instance = db.instance_create(self.context, self.test_instance)
|
||||
conn.destroy(instance, {})
|
||||
@ -1634,7 +1637,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
def fake_lookup_by_name(instance_name):
|
||||
return mock
|
||||
|
||||
conn = connection.LibvirtConnection(False)
|
||||
conn = connection.LibvirtDriver(False)
|
||||
self.stubs.Set(conn, '_lookup_by_name', fake_lookup_by_name)
|
||||
instance = {"name": "instancename", "id": "instanceid",
|
||||
"uuid": "875a8070-d0b9-4949-8b31-104d125c9a64"}
|
||||
@ -1642,7 +1645,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
def test_available_least_handles_missing(self):
|
||||
"""Ensure destroy calls managedSaveRemove for saved instance"""
|
||||
conn = connection.LibvirtConnection(False)
|
||||
conn = connection.LibvirtDriver(False)
|
||||
|
||||
def list_instances():
|
||||
return ['fake']
|
||||
@ -1702,8 +1705,8 @@ class HostStateTestCase(test.TestCase):
|
||||
return 13091
|
||||
|
||||
def test_update_status(self):
|
||||
self.mox.StubOutWithMock(connection, 'get_connection')
|
||||
connection.get_connection(True).AndReturn(self.FakeConnection())
|
||||
self.mox.StubOutWithMock(connection, 'LibvirtDriver')
|
||||
connection.LibvirtDriver(True).AndReturn(self.FakeConnection())
|
||||
|
||||
self.mox.ReplayAll()
|
||||
hs = connection.HostState(True)
|
||||
@ -1760,11 +1763,11 @@ class IptablesFirewallTestCase(test.TestCase):
|
||||
self.project_id = 'fake'
|
||||
self.context = context.RequestContext(self.user_id, self.project_id)
|
||||
|
||||
class FakeLibvirtConnection(object):
|
||||
class FakeLibvirtDriver(object):
|
||||
def nwfilterDefineXML(*args, **kwargs):
|
||||
"""setup_basic_rules in nwfilter calls this."""
|
||||
pass
|
||||
self.fake_libvirt_connection = FakeLibvirtConnection()
|
||||
self.fake_libvirt_connection = FakeLibvirtDriver()
|
||||
self.fw = firewall.IptablesFirewallDriver(
|
||||
get_connection=lambda: self.fake_libvirt_connection)
|
||||
|
||||
@ -2453,11 +2456,11 @@ disk size: 4.4M''', ''))
|
||||
self.assertEqual(out, 'c')
|
||||
|
||||
|
||||
class LibvirtConnectionTestCase(test.TestCase):
|
||||
"""Test for nova.virt.libvirt.connection.LibvirtConnection."""
|
||||
class LibvirtDriverTestCase(test.TestCase):
|
||||
"""Test for nova.virt.libvirt.connection.LibvirtDriver."""
|
||||
def setUp(self):
|
||||
super(LibvirtConnectionTestCase, self).setUp()
|
||||
self.libvirtconnection = connection.LibvirtConnection(read_only=True)
|
||||
super(LibvirtDriverTestCase, self).setUp()
|
||||
self.libvirtconnection = connection.LibvirtDriver(read_only=True)
|
||||
|
||||
def _create_instance(self, params=None):
|
||||
"""Create a test instance"""
|
||||
@ -2694,5 +2697,5 @@ class LibvirtNonblockingTestCase(test.TestCase):
|
||||
def test_connection_to_primitive(self):
|
||||
"""Test bug 962840"""
|
||||
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)
|
||||
|
@ -50,7 +50,7 @@ class NotificationsTestCase(test.TestCase):
|
||||
self.stubs.Set(nova.network.API, 'get_instance_nw_info',
|
||||
fake_get_nw_info)
|
||||
|
||||
self.flags(connection_type='fake',
|
||||
self.flags(compute_driver='nova.virt.fake.FakeDriver',
|
||||
stub_network=True,
|
||||
notification_driver='nova.notifier.test_notifier',
|
||||
network_manager='nova.network.manager.FlatManager',
|
||||
|
@ -46,7 +46,7 @@ class QuotaIntegrationTestCase(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(QuotaIntegrationTestCase, self).setUp()
|
||||
self.flags(connection_type='fake',
|
||||
self.flags(compute_driver='nova.virt.fake.FakeDriver',
|
||||
quota_instances=2,
|
||||
quota_cores=4,
|
||||
quota_volumes=2,
|
||||
|
@ -23,6 +23,7 @@ from nova import exception
|
||||
from nova import flags
|
||||
from nova import image
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import importutils
|
||||
from nova import test
|
||||
from nova.tests import utils as test_utils
|
||||
|
||||
@ -55,7 +56,7 @@ def catch_notimplementederror(f):
|
||||
class _VirtDriverTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
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.image_service = image.get_default_image_service()
|
||||
|
||||
@ -395,21 +396,23 @@ class _VirtDriverTestCase(test.TestCase):
|
||||
|
||||
class AbstractDriverTestCase(_VirtDriverTestCase):
|
||||
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(_):
|
||||
return nova.virt.driver.ComputeDriver()
|
||||
# TODO(sdague): the abstract driver doesn't have a constructor,
|
||||
# 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()
|
||||
|
||||
|
||||
class FakeConnectionTestCase(_VirtDriverTestCase):
|
||||
def setUp(self):
|
||||
import nova.virt.fake
|
||||
self.driver_module = nova.virt.fake
|
||||
self.driver_module = 'nova.virt.fake.FakeDriver'
|
||||
super(FakeConnectionTestCase, self).setUp()
|
||||
|
||||
|
||||
@ -439,7 +442,7 @@ class LibvirtConnTestCase(_VirtDriverTestCase):
|
||||
FLAGS.instances_path = ''
|
||||
|
||||
# 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()
|
||||
self.flags(firewall_driver=nova.virt.libvirt.firewall.drivers[0],
|
||||
rescue_image_id="2",
|
||||
|
@ -51,7 +51,7 @@ class VMWareAPIVMTestCase(test.TestCase):
|
||||
db_fakes.stub_out_db_instance_api(self.stubs)
|
||||
stubs.set_stubs(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
|
||||
# being tested
|
||||
self.network_info = [({'bridge': 'fa0',
|
||||
|
@ -48,7 +48,7 @@ class VolumeTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
super(VolumeTestCase, self).setUp()
|
||||
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',
|
||||
'nova.notifier.test_notifier')
|
||||
self.volume = importutils.import_object(FLAGS.volume_manager)
|
||||
|
@ -36,7 +36,7 @@ class UsageInfoTestCase(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(UsageInfoTestCase, self).setUp()
|
||||
self.flags(connection_type='fake',
|
||||
self.flags(compute_driver='nova.virt.fake.FakeDriver',
|
||||
stub_network=True,
|
||||
host='fake')
|
||||
self.stubs.Set(nova.flags.FLAGS, 'notification_driver',
|
||||
|
@ -178,7 +178,7 @@ class XenAPIVolumeTestCase(test.TestCase):
|
||||
def test_attach_volume(self):
|
||||
"""This shows how to test Ops classes' methods."""
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVolumeTests)
|
||||
conn = xenapi_conn.get_connection(False)
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
volume = self._create_volume()
|
||||
instance = db.instance_create(self.context, self.instance_values)
|
||||
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."""
|
||||
stubs.stubout_session(self.stubs,
|
||||
stubs.FakeSessionForVolumeFailedTests)
|
||||
conn = xenapi_conn.get_connection(False)
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
volume = self._create_volume()
|
||||
instance = db.instance_create(self.context, self.instance_values)
|
||||
xenapi_fake.create_vm(instance.name, 'Running')
|
||||
@ -232,7 +232,7 @@ class XenAPIVMTestCase(test.TestCase):
|
||||
self.user_id = 'fake'
|
||||
self.project_id = 'fake'
|
||||
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):
|
||||
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, "rootfs", userdevice=0)
|
||||
|
||||
conn = xenapi_conn.get_connection(False)
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
image_meta = {'id': glance_stubs.FakeGlance.IMAGE_VHD,
|
||||
'disk_format': 'vhd'}
|
||||
conn.rescue(self.context, instance, [], image_meta)
|
||||
@ -725,7 +725,7 @@ class XenAPIVMTestCase(test.TestCase):
|
||||
|
||||
def test_unrescue(self):
|
||||
instance = self._create_instance()
|
||||
conn = xenapi_conn.get_connection(False)
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
# Unrescue expects the original instance to be powered off
|
||||
conn.power_off(instance)
|
||||
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):
|
||||
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.
|
||||
self.assertRaises(exception.InstanceNotInRescueMode, conn.unrescue,
|
||||
instance, None)
|
||||
@ -749,7 +749,7 @@ class XenAPIVMTestCase(test.TestCase):
|
||||
def finish_revert_migration(self, instance):
|
||||
self.finish_revert_migration_called = True
|
||||
|
||||
conn = xenapi_conn.get_connection(False)
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
conn._vmops = VMOpsMock()
|
||||
conn.finish_revert_migration(instance, None)
|
||||
self.assertTrue(conn._vmops.finish_revert_migration_called)
|
||||
@ -873,7 +873,7 @@ class XenAPIMigrateInstance(test.TestCase):
|
||||
"VDI_resize", fake_vdi_resize)
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests,
|
||||
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_uuid = xenapi_fake.get_record('VDI', vdi_ref)['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)
|
||||
xenapi_fake.create_vm(instance.name, 'Running')
|
||||
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,
|
||||
'127.0.0.1', instance_type, None)
|
||||
|
||||
@ -896,7 +896,7 @@ class XenAPIMigrateInstance(test.TestCase):
|
||||
raise exception.MigrationError(reason='test failure')
|
||||
self.stubs.Set(vmops.VMOps, "_migrate_vhd", fake_raise)
|
||||
|
||||
conn = xenapi_conn.get_connection(False)
|
||||
conn = xenapi_conn.XenAPIDriver(False)
|
||||
self.assertRaises(exception.MigrationError,
|
||||
conn.migrate_disk_and_power_off,
|
||||
self.context, instance,
|
||||
@ -923,7 +923,7 @@ class XenAPIMigrateInstance(test.TestCase):
|
||||
self.stubs.Set(vmops.VMOps, '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,
|
||||
spectacular=True)
|
||||
image_meta = {'id': instance.image_ref, 'disk_format': 'vhd'}
|
||||
@ -955,7 +955,7 @@ class XenAPIMigrateInstance(test.TestCase):
|
||||
self.stubs.Set(stubs.FakeSessionForVMTests,
|
||||
"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,
|
||||
spectacular=True)
|
||||
image_meta = {'id': instance.image_ref, 'disk_format': 'vhd'}
|
||||
@ -977,7 +977,7 @@ class XenAPIMigrateInstance(test.TestCase):
|
||||
|
||||
self.stubs.Set(stubs.FakeSessionForVMTests,
|
||||
"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,
|
||||
spectacular=True)
|
||||
image_meta = {'id': instance.image_ref, 'disk_format': 'vhd'}
|
||||
@ -993,7 +993,7 @@ class XenAPIMigrateInstance(test.TestCase):
|
||||
|
||||
self.stubs.Set(stubs.FakeSessionForVMTests,
|
||||
"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,
|
||||
spectacular=True)
|
||||
# Resize instance would be determined by the compute call
|
||||
@ -1083,7 +1083,7 @@ class XenAPIHostTestCase(test.TestCase):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
xenapi_fake.reset()
|
||||
xenapi_fake.create_local_srs()
|
||||
self.conn = xenapi_conn.get_connection(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
|
||||
def test_host_state(self):
|
||||
stats = self.conn.get_host_stats()
|
||||
@ -1135,7 +1135,7 @@ class XenAPIAutoDiskConfigTestCase(test.TestCase):
|
||||
'Dom0IptablesFirewallDriver')
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
xenapi_fake.reset()
|
||||
self.conn = xenapi_conn.get_connection(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
|
||||
self.user_id = 'fake'
|
||||
self.project_id = 'fake'
|
||||
@ -1228,7 +1228,7 @@ class XenAPIGenerateLocal(test.TestCase):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
db_fakes.stub_out_db_instance_api(self.stubs)
|
||||
xenapi_fake.reset()
|
||||
self.conn = xenapi_conn.get_connection(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
|
||||
self.user_id = 'fake'
|
||||
self.project_id = 'fake'
|
||||
@ -1307,7 +1307,7 @@ class XenAPIBWUsageTestCase(test.TestCase):
|
||||
'Dom0IptablesFirewallDriver')
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
xenapi_fake.reset()
|
||||
self.conn = xenapi_conn.get_connection(False)
|
||||
self.conn = xenapi_conn.XenAPIDriver(False)
|
||||
|
||||
@classmethod
|
||||
def _fake_compile_metrics(cls, start_time, stop_time=None):
|
||||
@ -1384,7 +1384,7 @@ class XenAPIDom0IptablesFirewallTestCase(test.TestCase):
|
||||
test_case=self)
|
||||
self.context = context.RequestContext(self.user_id, self.project_id)
|
||||
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
|
||||
|
||||
def _create_instance_ref(self):
|
||||
@ -1699,7 +1699,7 @@ class XenAPIAggregateTestCase(test.TestCase):
|
||||
host_ref = xenapi_fake.get_all('host')[0]
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
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',
|
||||
'host': xenapi_fake.get_record('host',
|
||||
host_ref)['uuid']}
|
||||
|
@ -66,15 +66,6 @@ baremetal_opts = [
|
||||
FLAGS.register_opts(baremetal_opts)
|
||||
|
||||
|
||||
def get_connection(read_only):
|
||||
# These are loaded late so that there's no need to install these
|
||||
# libraries when not using baremetal.
|
||||
# Cheetah is separate because the unit tests want to load Cheetah,
|
||||
# but not baremetal.
|
||||
_late_load_cheetah()
|
||||
return ProxyConnection(read_only)
|
||||
|
||||
|
||||
def _late_load_cheetah():
|
||||
global Template
|
||||
if Template is None:
|
||||
@ -86,6 +77,7 @@ def _late_load_cheetah():
|
||||
class ProxyConnection(driver.ComputeDriver):
|
||||
|
||||
def __init__(self, read_only):
|
||||
_late_load_cheetah()
|
||||
# Note that baremetal doesn't have a read-only connection
|
||||
# mode, so the read_only parameter is ignored
|
||||
super(ProxyConnection, self).__init__()
|
||||
|
@ -23,23 +23,20 @@ import sys
|
||||
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import importutils
|
||||
from nova import utils
|
||||
from nova.virt import driver
|
||||
from nova.virt import fake
|
||||
from nova.virt.libvirt import connection as libvirt_conn
|
||||
from nova.virt import vmwareapi_conn
|
||||
from nova.virt.xenapi import connection as xenapi_conn
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
FLAGS = flags.FLAGS
|
||||
|
||||
"""
|
||||
In case of baremetal (FLAGS.connection_type),
|
||||
specific driver is set by FLAGS.baremetal_driver
|
||||
"""
|
||||
if FLAGS.connection_type == 'baremetal':
|
||||
from nova.virt.baremetal import proxy
|
||||
known_drivers = {
|
||||
'baremetal': 'nova.virt.baremetal.proxy.ProxyConnection',
|
||||
'fake': 'nova.virt.fake.FakeDriver',
|
||||
'libvirt': 'nova.virt.libvirt.connection.LibvirtDriver',
|
||||
'vmwareapi': 'nova.virt.vmwareapi_conn.VMWareESXDriver',
|
||||
'xenapi': 'nova.virt.xenapi.connection.XenAPIDriver'
|
||||
}
|
||||
|
||||
|
||||
def get_connection(read_only=False):
|
||||
@ -68,21 +65,17 @@ def get_connection(read_only=False):
|
||||
* baremetal
|
||||
|
||||
"""
|
||||
# TODO(termie): maybe lazy load after initial check for permissions
|
||||
# TODO(termie): check whether we can be disconnected
|
||||
t = FLAGS.connection_type
|
||||
if t == 'fake':
|
||||
conn = fake.get_connection(read_only)
|
||||
elif t == 'libvirt':
|
||||
conn = libvirt_conn.get_connection(read_only)
|
||||
elif t == 'xenapi':
|
||||
conn = xenapi_conn.get_connection(read_only)
|
||||
elif t == 'vmwareapi':
|
||||
conn = vmwareapi_conn.get_connection(read_only)
|
||||
elif t == 'baremetal':
|
||||
conn = proxy.get_connection(read_only)
|
||||
else:
|
||||
raise Exception('Unknown connection type "%s"' % t)
|
||||
# TODO(sdague): is there a better way to mark things deprecated
|
||||
LOG.error(_('Specifying virt driver via connection_type is deprecated'))
|
||||
|
||||
driver_name = known_drivers.get(FLAGS.connection_type)
|
||||
|
||||
if driver_name is None:
|
||||
raise Exception('Unknown virt connection type "%s"' %
|
||||
FLAGS.connection_type)
|
||||
|
||||
conn = importutils.import_object(driver_name, read_only=read_only)
|
||||
|
||||
if conn is None:
|
||||
LOG.error(_('Failed to open connection to underlying virt platform'))
|
||||
|
@ -36,11 +36,6 @@ from nova.virt import driver
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_connection(_read_only):
|
||||
# The read_only parameter is ignored.
|
||||
return FakeConnection.instance()
|
||||
|
||||
|
||||
class FakeInstance(object):
|
||||
|
||||
def __init__(self, name, state):
|
||||
@ -48,10 +43,10 @@ class FakeInstance(object):
|
||||
self.state = state
|
||||
|
||||
|
||||
class FakeConnection(driver.ComputeDriver):
|
||||
class FakeDriver(driver.ComputeDriver):
|
||||
"""Fake hypervisor driver"""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, readonly=False):
|
||||
self.instances = {}
|
||||
self.host_status = {
|
||||
'host_name-description': 'Fake Host',
|
||||
@ -70,12 +65,6 @@ class FakeConnection(driver.ComputeDriver):
|
||||
'host_name_label': 'fake-mini'}
|
||||
self._mounts = {}
|
||||
|
||||
@classmethod
|
||||
def instance(cls):
|
||||
if not hasattr(cls, '_instance'):
|
||||
cls._instance = cls()
|
||||
return cls._instance
|
||||
|
||||
def init_host(self, host):
|
||||
return
|
||||
|
||||
|
@ -75,11 +75,9 @@ from nova.virt.libvirt import firewall
|
||||
from nova.virt.libvirt import imagecache
|
||||
from nova.virt.libvirt import utils as libvirt_utils
|
||||
|
||||
|
||||
libvirt = None
|
||||
Template = None
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
libvirt_opts = [
|
||||
@ -192,18 +190,6 @@ def patch_tpool_proxy():
|
||||
patch_tpool_proxy()
|
||||
|
||||
|
||||
def get_connection(read_only):
|
||||
# These are loaded late so that there's no need to install these
|
||||
# libraries when not using libvirt.
|
||||
# Cheetah is separate because the unit tests want to load Cheetah,
|
||||
# but not libvirt.
|
||||
global libvirt
|
||||
if libvirt is None:
|
||||
libvirt = __import__('libvirt')
|
||||
_late_load_cheetah()
|
||||
return LibvirtConnection(read_only)
|
||||
|
||||
|
||||
def _late_load_cheetah():
|
||||
global Template
|
||||
if Template is None:
|
||||
@ -216,10 +202,16 @@ def _get_eph_disk(ephemeral):
|
||||
return 'disk.eph' + str(ephemeral['num'])
|
||||
|
||||
|
||||
class LibvirtConnection(driver.ComputeDriver):
|
||||
class LibvirtDriver(driver.ComputeDriver):
|
||||
|
||||
def __init__(self, read_only):
|
||||
super(LibvirtConnection, self).__init__()
|
||||
super(LibvirtDriver, self).__init__()
|
||||
|
||||
global libvirt
|
||||
if libvirt is None:
|
||||
libvirt = __import__('libvirt')
|
||||
|
||||
_late_load_cheetah()
|
||||
|
||||
self._host_state = None
|
||||
self._initiator = None
|
||||
@ -2629,7 +2621,7 @@ class HostState(object):
|
||||
"""Retrieve status info from libvirt."""
|
||||
LOG.debug(_("Updating host stats"))
|
||||
if self.connection is None:
|
||||
self.connection = get_connection(self.read_only)
|
||||
self.connection = LibvirtDriver(self.read_only)
|
||||
data = {}
|
||||
data["vcpus"] = self.connection.get_vcpu_total()
|
||||
data["vcpus_used"] = self.connection.get_vcpu_used()
|
||||
|
@ -95,27 +95,22 @@ class Failure(Exception):
|
||||
return str(self.details)
|
||||
|
||||
|
||||
def get_connection(_read_only):
|
||||
"""Sets up the ESX host connection."""
|
||||
host_ip = FLAGS.vmwareapi_host_ip
|
||||
host_username = FLAGS.vmwareapi_host_username
|
||||
host_password = FLAGS.vmwareapi_host_password
|
||||
api_retry_count = FLAGS.vmwareapi_api_retry_count
|
||||
if not host_ip or host_username is None or host_password is None:
|
||||
raise Exception(_("Must specify vmwareapi_host_ip,"
|
||||
"vmwareapi_host_username "
|
||||
"and vmwareapi_host_password to use"
|
||||
"connection_type=vmwareapi"))
|
||||
return VMWareESXConnection(host_ip, host_username, host_password,
|
||||
api_retry_count)
|
||||
|
||||
|
||||
class VMWareESXConnection(driver.ComputeDriver):
|
||||
class VMWareESXDriver(driver.ComputeDriver):
|
||||
"""The ESX host connection object."""
|
||||
|
||||
def __init__(self, host_ip, host_username, host_password,
|
||||
api_retry_count, scheme="https"):
|
||||
super(VMWareESXConnection, self).__init__()
|
||||
def __init__(self, read_only=False, scheme="https"):
|
||||
super(VMWareESXDriver, self).__init__()
|
||||
|
||||
host_ip = FLAGS.vmwareapi_host_ip
|
||||
host_username = FLAGS.vmwareapi_host_username
|
||||
host_password = FLAGS.vmwareapi_host_password
|
||||
api_retry_count = FLAGS.vmwareapi_api_retry_count
|
||||
if not host_ip or host_username is None or host_password is None:
|
||||
raise Exception(_("Must specify vmwareapi_host_ip,"
|
||||
"vmwareapi_host_username "
|
||||
"and vmwareapi_host_password to use"
|
||||
"connection_type=vmwareapi"))
|
||||
|
||||
session = VMWareAPISession(host_ip, host_username, host_password,
|
||||
api_retry_count, scheme=scheme)
|
||||
self._vmops = vmops.VMWareVMOps(session)
|
||||
|
@ -127,26 +127,22 @@ FLAGS = flags.FLAGS
|
||||
FLAGS.register_opts(xenapi_opts)
|
||||
|
||||
|
||||
def get_connection(_read_only):
|
||||
"""Note that XenAPI doesn't have a read-only connection mode, so
|
||||
the read_only parameter is ignored."""
|
||||
url = FLAGS.xenapi_connection_url
|
||||
username = FLAGS.xenapi_connection_username
|
||||
password = FLAGS.xenapi_connection_password
|
||||
if not url or password is None:
|
||||
raise Exception(_('Must specify xenapi_connection_url, '
|
||||
'xenapi_connection_username (optionally), and '
|
||||
'xenapi_connection_password to use '
|
||||
'connection_type=xenapi'))
|
||||
return XenAPIConnection(url, username, password)
|
||||
|
||||
|
||||
class XenAPIConnection(driver.ComputeDriver):
|
||||
class XenAPIDriver(driver.ComputeDriver):
|
||||
"""A connection to XenServer or Xen Cloud Platform"""
|
||||
|
||||
def __init__(self, url, user, pw):
|
||||
super(XenAPIConnection, self).__init__()
|
||||
self._session = XenAPISession(url, user, pw)
|
||||
def __init__(self, read_only=False):
|
||||
super(XenAPIDriver, self).__init__()
|
||||
|
||||
url = FLAGS.xenapi_connection_url
|
||||
username = FLAGS.xenapi_connection_username
|
||||
password = FLAGS.xenapi_connection_password
|
||||
if not url or password is None:
|
||||
raise Exception(_('Must specify xenapi_connection_url, '
|
||||
'xenapi_connection_username (optionally), and '
|
||||
'xenapi_connection_password to use '
|
||||
'connection_type=xenapi'))
|
||||
|
||||
self._session = XenAPISession(url, username, password)
|
||||
self._volumeops = volumeops.VolumeOps(self._session)
|
||||
self._host_state = None
|
||||
self._host = host.Host(self._session)
|
||||
|
Loading…
x
Reference in New Issue
Block a user