diff --git a/nova/tests/unit/virt/test_driver.py b/nova/tests/unit/virt/test_driver.py index aa7478ca0b96..041ff3e05cfd 100644 --- a/nova/tests/unit/virt/test_driver.py +++ b/nova/tests/unit/virt/test_driver.py @@ -13,6 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. +import mock +from os_brick.initiator import connector from oslo_config import fixture as fixture_config from nova import test @@ -29,6 +31,13 @@ class FakeDriver2(FakeDriver): pass +class FailDriver(object): + def __init__(self): + self.connector = connector.InitiatorConnector.factory( + 'UNSUPPORTED', None + ) + + class ToDriverRegistryTestCase(test.NoDBTestCase): def assertDriverInstance(self, inst, class_, *args, **kwargs): @@ -59,6 +68,14 @@ class ToDriverRegistryTestCase(test.NoDBTestCase): FakeDriver2, 'arg1', 'arg2', param1='value1', param2='value2') + @mock.patch.object(connector.InitiatorConnector, "factory") + def test_driver_dict_from_config_exception(self, mocked_factory): + mocked_factory.side_effect = ValueError + registry = driver.driver_dict_from_config([ + 'fail=nova.tests.unit.virt.test_driver.FailDriver', + ]) + self.assertEqual({}, registry) + class DriverMethodTestCase(test.NoDBTestCase): diff --git a/nova/virt/driver.py b/nova/virt/driver.py index 1ca49a40fb8e..7bd446451d83 100644 --- a/nova/virt/driver.py +++ b/nova/virt/driver.py @@ -41,8 +41,15 @@ def driver_dict_from_config(named_driver_config, *args, **kwargs): 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) - + try: + driver_registry[driver_type] = driver_class(*args, **kwargs) + except ValueError: + # NOTE(arne_r): + # stable/newton can not enforce os_brick versions that include + # the InvalidConnectorProtocol exception. Since it inherits from + # ValueError, this fix is still compatible with it. + LOG.debug('Unable to load volume driver %s. It is not ' + 'supported on this host.', driver_type) return driver_registry