add a getter for connector mapping
Nova needs to check the architecture drivers like "_connector_mapping_linux". To avoid accessing private attribute, this adds a new function "get_connector_mapping" Change-Id: I66f37aace797eca54356b4aaf1bc1b655567c1e2
This commit is contained in:
parent
1c43a21cde
commit
10be2fe948
|
@ -230,6 +230,31 @@ def get_connector_properties(root_helper, my_ip, multipath, enforce_multipath,
|
||||||
return props
|
return props
|
||||||
|
|
||||||
|
|
||||||
|
def get_connector_mapping(arch=None):
|
||||||
|
"""Get connector mapping based on platform.
|
||||||
|
|
||||||
|
This is used by Nova to get the right connector information.
|
||||||
|
|
||||||
|
:param arch: The architecture being requested.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# 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':
|
||||||
|
return _connector_mapping_windows
|
||||||
|
elif arch in (initiator.S390, initiator.S390X):
|
||||||
|
return _connector_mapping_linux_s390x
|
||||||
|
elif arch in (initiator.PPC64, initiator.PPC64LE):
|
||||||
|
return _connector_mapping_linux_ppc64
|
||||||
|
|
||||||
|
else:
|
||||||
|
return _connector_mapping_linux
|
||||||
|
|
||||||
|
|
||||||
# TODO(walter-boring) We have to keep this class defined here
|
# TODO(walter-boring) We have to keep this class defined here
|
||||||
# so we don't break backwards compatibility
|
# so we don't break backwards compatibility
|
||||||
class InitiatorConnector(object):
|
class InitiatorConnector(object):
|
||||||
|
@ -242,21 +267,7 @@ class InitiatorConnector(object):
|
||||||
*args, **kwargs):
|
*args, **kwargs):
|
||||||
"""Build a Connector object based upon protocol and architecture."""
|
"""Build a Connector object based upon protocol and architecture."""
|
||||||
|
|
||||||
# We do this instead of assigning it in the definition
|
_mapping = get_connector_mapping(arch)
|
||||||
# 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
|
|
||||||
elif arch in (initiator.PPC64, initiator.PPC64LE):
|
|
||||||
_mapping = _connector_mapping_linux_ppc64
|
|
||||||
|
|
||||||
else:
|
|
||||||
_mapping = _connector_mapping_linux
|
|
||||||
|
|
||||||
LOG.debug("Factory for %(protocol)s on %(arch)s",
|
LOG.debug("Factory for %(protocol)s on %(arch)s",
|
||||||
{'protocol': protocol, 'arch': arch})
|
{'protocol': protocol, 'arch': arch})
|
||||||
|
|
|
@ -178,6 +178,25 @@ class ConnectorTestCase(test_base.TestCase):
|
||||||
'sudo', multipath=multipath,
|
'sudo', multipath=multipath,
|
||||||
enforce_multipath=enforce_multipath)
|
enforce_multipath=enforce_multipath)
|
||||||
|
|
||||||
|
@mock.patch('sys.platform', 'win32')
|
||||||
|
def test_get_connector_mapping_win32(self):
|
||||||
|
mapping_win32 = connector.get_connector_mapping()
|
||||||
|
self.assertTrue('ISCSI' in mapping_win32)
|
||||||
|
self.assertFalse('RBD' in mapping_win32)
|
||||||
|
self.assertFalse('STORPOOL' in mapping_win32)
|
||||||
|
|
||||||
|
@mock.patch('os_brick.initiator.connector.platform.machine')
|
||||||
|
def test_get_connector_mapping(self, mock_platform_machine):
|
||||||
|
mock_platform_machine.return_value = 'x86_64'
|
||||||
|
mapping_x86 = connector.get_connector_mapping()
|
||||||
|
mock_platform_machine.return_value = 'ppc64le'
|
||||||
|
mapping_ppc = connector.get_connector_mapping()
|
||||||
|
self.assertNotEqual(mapping_x86, mapping_ppc)
|
||||||
|
mock_platform_machine.return_value = 's390x'
|
||||||
|
mapping_s390 = connector.get_connector_mapping()
|
||||||
|
self.assertNotEqual(mapping_x86, mapping_s390)
|
||||||
|
self.assertNotEqual(mapping_ppc, mapping_s390)
|
||||||
|
|
||||||
def test_factory(self):
|
def test_factory(self):
|
||||||
obj = connector.InitiatorConnector.factory('iscsi', None)
|
obj = connector.InitiatorConnector.factory('iscsi', None)
|
||||||
self.assertEqual("ISCSIConnector", obj.__class__.__name__)
|
self.assertEqual("ISCSIConnector", obj.__class__.__name__)
|
||||||
|
|
Loading…
Reference in New Issue