Move driver_dict_from_config to libvirt driver
The driver_dict_from_config helper method is only used by the libvirt driver and is very specific to how the libvirt driver parses the libvirt_volume_drivers list of values, so this change moves it to the libvirt driver so that we can expand it in a following change to add specific error handling for the libvirt driver. Change-Id: I2b41d9e4e72b120f70371fff1201600acaa53708
This commit is contained in:
parent
61b50feade
commit
03d8e51172
|
@ -18370,3 +18370,44 @@ class LVMSnapshotTests(_BaseSnapshotTests):
|
|||
def test_qcow2(self):
|
||||
self.flags(snapshot_image_format='qcow2', group='libvirt')
|
||||
self._test_lvm_snapshot('qcow2')
|
||||
|
||||
|
||||
class FakeDriver(object):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.args = args
|
||||
self.kwargs = kwargs
|
||||
|
||||
|
||||
class FakeDriver2(FakeDriver):
|
||||
pass
|
||||
|
||||
|
||||
class ToDriverRegistryTestCase(test.NoDBTestCase):
|
||||
|
||||
def assertDriverInstance(self, inst, class_, *args, **kwargs):
|
||||
self.assertEqual(class_, inst.__class__)
|
||||
self.assertEqual(args, inst.args)
|
||||
self.assertEqual(kwargs, inst.kwargs)
|
||||
|
||||
def test_driver_dict_from_config(self):
|
||||
drvs = libvirt_driver.driver_dict_from_config(
|
||||
[
|
||||
'key1=nova.tests.unit.virt.libvirt.test_driver.FakeDriver',
|
||||
'key2=nova.tests.unit.virt.libvirt.test_driver.FakeDriver2',
|
||||
], 'arg1', 'arg2', param1='value1', param2='value2'
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
sorted(['key1', 'key2']),
|
||||
sorted(drvs.keys())
|
||||
)
|
||||
|
||||
self.assertDriverInstance(
|
||||
drvs['key1'],
|
||||
FakeDriver, 'arg1', 'arg2', param1='value1',
|
||||
param2='value2')
|
||||
|
||||
self.assertDriverInstance(
|
||||
drvs['key2'],
|
||||
FakeDriver2, 'arg1', 'arg2', param1='value1',
|
||||
param2='value2')
|
||||
|
|
|
@ -19,47 +19,6 @@ from nova import test
|
|||
from nova.virt import driver
|
||||
|
||||
|
||||
class FakeDriver(object):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.args = args
|
||||
self.kwargs = kwargs
|
||||
|
||||
|
||||
class FakeDriver2(FakeDriver):
|
||||
pass
|
||||
|
||||
|
||||
class ToDriverRegistryTestCase(test.NoDBTestCase):
|
||||
|
||||
def assertDriverInstance(self, inst, class_, *args, **kwargs):
|
||||
self.assertEqual(class_, inst.__class__)
|
||||
self.assertEqual(args, inst.args)
|
||||
self.assertEqual(kwargs, inst.kwargs)
|
||||
|
||||
def test_driver_dict_from_config(self):
|
||||
drvs = driver.driver_dict_from_config(
|
||||
[
|
||||
'key1=nova.tests.unit.virt.test_driver.FakeDriver',
|
||||
'key2=nova.tests.unit.virt.test_driver.FakeDriver2',
|
||||
], 'arg1', 'arg2', param1='value1', param2='value2'
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
sorted(['key1', 'key2']),
|
||||
sorted(drvs.keys())
|
||||
)
|
||||
|
||||
self.assertDriverInstance(
|
||||
drvs['key1'],
|
||||
FakeDriver, 'arg1', 'arg2', param1='value1',
|
||||
param2='value2')
|
||||
|
||||
self.assertDriverInstance(
|
||||
drvs['key2'],
|
||||
FakeDriver2, 'arg1', 'arg2', param1='value1',
|
||||
param2='value2')
|
||||
|
||||
|
||||
class DriverMethodTestCase(test.NoDBTestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
|
|
@ -35,17 +35,6 @@ CONF = nova.conf.CONF
|
|||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def driver_dict_from_config(named_driver_config, *args, **kwargs):
|
||||
driver_registry = dict()
|
||||
|
||||
for driver_str in named_driver_config:
|
||||
driver_type, _sep, driver = driver_str.partition('=')
|
||||
driver_class = importutils.import_class(driver)
|
||||
driver_registry[driver_type] = driver_class(*args, **kwargs)
|
||||
|
||||
return driver_registry
|
||||
|
||||
|
||||
def get_block_device_info(instance, block_device_mapping):
|
||||
"""Converts block device mappings for an instance to driver format.
|
||||
|
||||
|
|
|
@ -169,6 +169,17 @@ libvirt_volume_drivers = [
|
|||
]
|
||||
|
||||
|
||||
def driver_dict_from_config(named_driver_config, *args, **kwargs):
|
||||
driver_registry = dict()
|
||||
|
||||
for driver_str in named_driver_config:
|
||||
driver_type, _sep, driver = driver_str.partition('=')
|
||||
driver_class = importutils.import_class(driver)
|
||||
driver_registry[driver_type] = driver_class(*args, **kwargs)
|
||||
|
||||
return driver_registry
|
||||
|
||||
|
||||
def patch_tpool_proxy():
|
||||
"""eventlet.tpool.Proxy doesn't work with old-style class in __str__()
|
||||
or __repr__() calls. See bug #962840 for details.
|
||||
|
@ -352,7 +363,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
|
||||
self.vif_driver = libvirt_vif.LibvirtGenericVIFDriver()
|
||||
|
||||
self.volume_drivers = driver.driver_dict_from_config(
|
||||
self.volume_drivers = driver_dict_from_config(
|
||||
self._get_volume_drivers(), self._host)
|
||||
|
||||
self._disk_cachemode = None
|
||||
|
|
Loading…
Reference in New Issue