From 9e8657dd6ef781d7e6027625fc2f05442256c6ac Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Tue, 29 Oct 2019 20:50:02 +0200 Subject: [PATCH] Split connector list by platform We'll keep separate lists of connectors for each of the supported operating systems so that we don't end up trying to use unsupported connectors. Since Cinder is explicitly trying to use the iSCSI/FC connectors, we'll have to include those as well, for now. Change-Id: Ibec2b798e8c5c3457cebea12cfd2f5813e62fb9e Closes-Bug: #1850109 --- os_brick/initiator/connector.py | 44 +++++++++++++++++----- os_brick/tests/initiator/test_connector.py | 2 +- tools/generate_connector_list.py | 2 +- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/os_brick/initiator/connector.py b/os_brick/initiator/connector.py index 3712e81fa..963ee6a65 100644 --- a/os_brick/initiator/connector.py +++ b/os_brick/initiator/connector.py @@ -39,7 +39,14 @@ synchronized = lockutils.synchronized_with_prefix('os-brick-') # List of connectors to call when getting # the connector properties for a host -connector_list = [ +windows_connector_list = [ + 'os_brick.initiator.windows.base.BaseWindowsConnector', + 'os_brick.initiator.windows.iscsi.WindowsISCSIConnector', + 'os_brick.initiator.windows.fibre_channel.WindowsFCConnector', + 'os_brick.initiator.windows.smbfs.WindowsSMBFSConnector' +] + +unix_connector_list = [ 'os_brick.initiator.connectors.base.BaseLinuxConnector', 'os_brick.initiator.connectors.iscsi.ISCSIConnector', 'os_brick.initiator.connectors.fibre_channel.FibreChannelConnector', @@ -58,15 +65,19 @@ connector_list = [ 'os_brick.initiator.connectors.scaleio.ScaleIOConnector', 'os_brick.initiator.connectors.disco.DISCOConnector', 'os_brick.initiator.connectors.vmware.VmdkConnector', - 'os_brick.initiator.windows.base.BaseWindowsConnector', - 'os_brick.initiator.windows.iscsi.WindowsISCSIConnector', - 'os_brick.initiator.windows.fibre_channel.WindowsFCConnector', - 'os_brick.initiator.windows.smbfs.WindowsSMBFSConnector', 'os_brick.initiator.connectors.vrtshyperscale.HyperScaleConnector', 'os_brick.initiator.connectors.storpool.StorPoolConnector', 'os_brick.initiator.connectors.nvmeof.NVMeOFConnector', ] + +def _get_connector_list(): + if sys.platform != 'win32': + return unix_connector_list + else: + return windows_connector_list + + # Mappings used to determine who to construct in the factory _connector_mapping_linux = { initiator.AOE: @@ -182,9 +193,24 @@ _connector_mapping_windows = { # Create aliases to the old names until 2.0.0 # TODO(smcginnis) Remove this lookup once unit test code is updated to # point to the correct location -for item in connector_list: - _name = item.split('.')[-1] - globals()[_name] = importutils.import_class(item) +def _set_aliases(): + conn_list = _get_connector_list() + # TODO(lpetrut): Cinder is explicitly trying to use those two + # connectors. We should drop this once we fix Cinder and + # get passed the backwards compatibility period. + if sys.platform == 'win32': + conn_list += [ + 'os_brick.initiator.connectors.iscsi.ISCSIConnector', + ('os_brick.initiator.connectors.fibre_channel.' + 'FibreChannelConnector'), + ] + + for item in conn_list: + _name = item.split('.')[-1] + globals()[_name] = importutils.import_class(item) + + +_set_aliases() @utils.trace @@ -220,7 +246,7 @@ def get_connector_properties(root_helper, my_ip, multipath, enforce_multipath, props['ip'] = my_ip props['host'] = host if host else socket.gethostname() - for item in connector_list: + for item in _get_connector_list(): connector = importutils.import_class(item) if (utils.platform_matches(props['platform'], connector.platform) and diff --git a/os_brick/tests/initiator/test_connector.py b/os_brick/tests/initiator/test_connector.py index 612b7ccc8..ea251a3de 100644 --- a/os_brick/tests/initiator/test_connector.py +++ b/os_brick/tests/initiator/test_connector.py @@ -79,7 +79,7 @@ class ConnectorUtilsTestCase(test_base.TestCase): mock_list = [] # Make sure every connector is called - for item in connector.connector_list: + for item in connector._get_connector_list(): patched = mock.MagicMock() patched.platform = platform.machine() patched.os_type = sys.platform diff --git a/tools/generate_connector_list.py b/tools/generate_connector_list.py index 6717b130f..fafacacf4 100755 --- a/tools/generate_connector_list.py +++ b/tools/generate_connector_list.py @@ -55,7 +55,7 @@ def _ensure_loaded(connector_list): def get_connectors(): """Get a list of all connectors.""" - classes = _ensure_loaded(connector.connector_list) + classes = _ensure_loaded(connector._get_connector_list()) return [DriverInfo(x) for x in classes]