Created
September 13, 2016 18:25
-
-
Save WaltHP/76aa4d75a1a84eb636fe80c978544c7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/os_brick/initiator/connector.py b/os_brick/initiator/connector.py | |
index 86adfa8..c4602a3 100644 | |
--- a/os_brick/initiator/connector.py | |
+++ b/os_brick/initiator/connector.py | |
@@ -25,6 +25,7 @@ import re | |
import socket | |
import sys | |
+from debtcollector import removals | |
from oslo_concurrency import lockutils | |
from oslo_log import log as logging | |
from oslo_utils import importutils | |
@@ -220,57 +221,70 @@ def get_connector_properties(root_helper, my_ip, multipath, enforce_multipath, | |
return props | |
+def factory(protocol, root_helper, driver=None, | |
+ use_multipath=False, | |
+ device_scan_attempts=initiator.DEVICE_SCAN_ATTEMPTS_DEFAULT, | |
+ arch=None, | |
+ *args, **kwargs): | |
+ """Build a Connector object based upon protocol and architecture.""" | |
+ # We do this instead of assigning it in the definition | |
+ # to help mocking for unit tests | |
+ if arch is None: | |
+ arch = platform.machine() | |
+ | |
+ # Set the correct mapping for imports | |
+ if sys.platform == 'win32': | |
+ _mapping = _connector_mapping_windows | |
+ elif arch in (initiator.S390, initiator.S390X): | |
+ _mapping = _connector_mapping_linux_s390x | |
+ else: | |
+ _mapping = _connector_mapping_linux | |
+ | |
+ LOG.debug("Factory for %(protocol)s on %(arch)s", | |
+ {'protocol': protocol, 'arch': arch}) | |
+ protocol = protocol.upper() | |
+ | |
+ # set any special kwargs needed by connectors | |
+ if protocol in (initiator.NFS, initiator.GLUSTERFS, | |
+ initiator.SCALITY, initiator.QUOBYTE, | |
+ initiator.VZSTORAGE): | |
+ kwargs.update({'mount_type': protocol.lower()}) | |
+ elif protocol == initiator.ISER: | |
+ kwargs.update({'transport': 'iser'}) | |
+ | |
+ # now set all the default kwargs | |
+ kwargs.update( | |
+ {'root_helper': root_helper, | |
+ 'driver': driver, | |
+ 'use_multipath': use_multipath, | |
+ 'device_scan_attempts': device_scan_attempts, | |
+ }) | |
+ | |
+ connector = _mapping.get(protocol) | |
+ if not connector: | |
+ msg = (_("Invalid InitiatorConnector protocol " | |
+ "specified %(protocol)s") % | |
+ dict(protocol=protocol)) | |
+ raise ValueError(msg) | |
+ | |
+ conn_cls = importutils.import_class(connector) | |
+ return conn_cls(*args, **kwargs) | |
+ | |
+ | |
# TODO(walter-boring) We have to keep this class defined here | |
# so we don't break backwards compatibility | |
class InitiatorConnector(object): | |
@staticmethod | |
+ @removals.remove(message="Please use connector.factory() This method will" | |
+ "be removed in the O release") | |
def factory(protocol, root_helper, driver=None, | |
use_multipath=False, | |
device_scan_attempts=initiator.DEVICE_SCAN_ATTEMPTS_DEFAULT, | |
arch=None, | |
*args, **kwargs): | |
"""Build a Connector object based upon protocol and architecture.""" | |
- | |
- # We do this instead of assigning it in the definition | |
- # to help mocking for unit tests | |
- if arch is None: | |
- arch = platform.machine() | |
- | |
- # Set the correct mapping for imports | |
- if sys.platform == 'win32': | |
- _mapping = _connector_mapping_windows | |
- elif arch in (initiator.S390, initiator.S390X): | |
- _mapping = _connector_mapping_linux_s390x | |
- else: | |
- _mapping = _connector_mapping_linux | |
- | |
- LOG.debug("Factory for %(protocol)s on %(arch)s", | |
- {'protocol': protocol, 'arch': arch}) | |
- protocol = protocol.upper() | |
- | |
- # set any special kwargs needed by connectors | |
- if protocol in (initiator.NFS, initiator.GLUSTERFS, | |
- initiator.SCALITY, initiator.QUOBYTE, | |
- initiator.VZSTORAGE): | |
- kwargs.update({'mount_type': protocol.lower()}) | |
- elif protocol == initiator.ISER: | |
- kwargs.update({'transport': 'iser'}) | |
- | |
- # now set all the default kwargs | |
- kwargs.update( | |
- {'root_helper': root_helper, | |
- 'driver': driver, | |
- 'use_multipath': use_multipath, | |
- 'device_scan_attempts': device_scan_attempts, | |
- }) | |
- | |
- connector = _mapping.get(protocol) | |
- if not connector: | |
- msg = (_("Invalid InitiatorConnector protocol " | |
- "specified %(protocol)s") % | |
- dict(protocol=protocol)) | |
- raise ValueError(msg) | |
- | |
- conn_cls = importutils.import_class(connector) | |
- return conn_cls(*args, **kwargs) | |
+ return factory(protocol, root_helper, driver=driver, | |
+ device_scan_attempts=device_scan_attempts, | |
+ arch=arch, | |
+ *args, **kwargs) | |
diff --git a/os_brick/tests/initiator/connectors/test_base_iscsi.py b/os_brick/tests/initiator/connectors/test_base_iscsi.py | |
index ca7fe82..db593a2 100644 | |
--- a/os_brick/tests/initiator/connectors/test_base_iscsi.py | |
+++ b/os_brick/tests/initiator/connectors/test_base_iscsi.py | |
@@ -48,7 +48,7 @@ class BaseISCSIConnectorTestCase(test_base.TestCase): | |
'target_iqn': mock.sentinel.iqn, | |
'target_lun': mock.sentinel.lun, | |
'extra_property': 'extra_property'} | |
- self.assertDictEqual(expected_props, list_props[0]) | |
+ self.assertDictMatch(expected_props, list_props[0]) | |
def test_get_all_targets(self): | |
connection_properties = { | |
diff --git a/requirements.txt b/requirements.txt | |
index 0a7ce32..20f0341 100644 | |
--- a/requirements.txt | |
+++ b/requirements.txt | |
@@ -4,6 +4,7 @@ | |
pbr>=1.6 # Apache-2.0 | |
Babel>=2.3.4 # BSD | |
+debtcollector>=1.2.0 # Apache-2.0 | |
eventlet!=0.18.3,>=0.18.2 # MIT | |
oslo.concurrency>=3.8.0 # Apache-2.0 | |
oslo.log>=1.14.0 # Apache-2.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment