From ec3f15994476cf36e0ab34c0d3145102e61fece9 Mon Sep 17 00:00:00 2001 From: Arne Recknagel Date: Tue, 21 Feb 2017 16:56:53 +0100 Subject: [PATCH] Fix s390 "connector not found" issue This patch introduces a try-catch block on a call to the os-brick library which may throw a ValueError. os_brick will throw it when a driver is not supported, so ignoring it and skipping its addition to the driver list should be the expected behavior. This fix is required for s390, where nova is currently broken without it. The issue was resolved in Ocata with changes including [1] and [2], as well as a change to os_brick [3]. The backport to newton [4] was abandoned as it requires a raise in the os_brick minimum version. This fix is a revision of [5], which is essentially a lightweight version of [1] that only addresses the issue at hand. [1]: https://review.openstack.org/#/c/395067/ [2]: https://review.openstack.org/#/c/394979/ [3]: https://review.openstack.org/#/c/375415/ [4]: https://review.openstack.org/#/c/428386/ [5]: https://review.openstack.org/#/c/394425/ Change-Id: I638f12ce3deab0338a8d2652398c35acb9280f72 Closes-Bug: 1639239 --- nova/tests/unit/virt/test_driver.py | 17 +++++++++++++++++ nova/virt/driver.py | 11 +++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) 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