diff --git a/os_brick/initiator/connector.py b/os_brick/initiator/connector.py index e149fffe1..d1fb35ab9 100644 --- a/os_brick/initiator/connector.py +++ b/os_brick/initiator/connector.py @@ -72,6 +72,7 @@ HUAWEISDSHYPERVISOR = "HUAWEISDSHYPERVISOR" HGST = "HGST" RBD = "RBD" SCALEIO = "SCALEIO" +SCALITY = "SCALITY" def _check_multipathd_running(root_helper, enforce_multipath): @@ -195,7 +196,7 @@ class InitiatorConnector(executor.Executor): execute=execute, device_scan_attempts=device_scan_attempts, *args, **kwargs) - elif protocol == NFS or protocol == GLUSTERFS: + elif protocol in (NFS, GLUSTERFS, SCALITY): return RemoteFsConnector(mount_type=protocol.lower(), root_helper=root_helper, driver=driver, @@ -1215,14 +1216,11 @@ class RemoteFsConnector(InitiatorConnector): conn = kwargs.get('conn') if conn: mount_point_base = conn.get('mount_point_base') - if mount_type.lower() == 'nfs': - kwargs['nfs_mount_point_base'] =\ - kwargs.get('nfs_mount_point_base') or\ - mount_point_base - elif mount_type.lower() == 'glusterfs': - kwargs['glusterfs_mount_point_base'] =\ - kwargs.get('glusterfs_mount_point_base') or\ - mount_point_base + mount_type_lower = mount_type.lower() + if mount_type_lower in ('nfs', 'glusterfs', 'scality'): + kwargs[mount_type_lower + '_mount_point_base'] = ( + kwargs.get(mount_type_lower + '_mount_point_base') or + mount_point_base) else: LOG.warning(_LW("Connection details not present." " RemoteFsClient may not initialize properly.")) diff --git a/os_brick/remotefs/remotefs.py b/os_brick/remotefs/remotefs.py index 5b8757984..e17244304 100644 --- a/os_brick/remotefs/remotefs.py +++ b/os_brick/remotefs/remotefs.py @@ -35,34 +35,30 @@ class RemoteFsClient(object): def __init__(self, mount_type, root_helper, execute=putils.execute, *args, **kwargs): - self._mount_type = mount_type - if mount_type == "nfs": - self._mount_base = kwargs.get('nfs_mount_point_base', None) - if not self._mount_base: - raise exception.InvalidParameterValue( - err=_('nfs_mount_point_base required')) - self._mount_options = kwargs.get('nfs_mount_options', None) - self._check_nfs_options() - elif mount_type == "cifs": - self._mount_base = kwargs.get('smbfs_mount_point_base', None) - if not self._mount_base: - raise exception.InvalidParameterValue( - err=_('smbfs_mount_point_base required')) - self._mount_options = kwargs.get('smbfs_mount_options', None) - elif mount_type == "glusterfs": - self._mount_base = kwargs.get('glusterfs_mount_point_base', None) - if not self._mount_base: - raise exception.InvalidParameterValue( - err=_('glusterfs_mount_point_base required')) - self._mount_options = None - elif mount_type == "vzstorage": - self._mount_base = kwargs.get('vzstorage_mount_point_base', None) - if not self._mount_base: - raise exception.InvalidParameterValue( - err=_('vzstorage_mount_point_base required')) - self._mount_options = None - else: + mount_type_to_option_prefix = { + 'nfs': 'nfs', + 'cifs': 'smbfs', + 'glusterfs': 'glusterfs', + 'vzstorage': 'vzstorage', + 'scality': 'scality_sofs' + } + + if mount_type not in mount_type_to_option_prefix: raise exception.ProtocolNotSupported(protocol=mount_type) + + self._mount_type = mount_type + option_prefix = mount_type_to_option_prefix[mount_type] + + self._mount_base = kwargs.get(option_prefix + '_mount_point_base') + if not self._mount_base: + raise exception.InvalidParameterValue( + err=_('%s_mount_point_base required') % option_prefix) + + self._mount_options = kwargs.get(option_prefix + '_mount_options') + + if mount_type == "nfs": + self._check_nfs_options() + self.root_helper = root_helper self.set_execute(execute) diff --git a/os_brick/tests/initiator/test_connector.py b/os_brick/tests/initiator/test_connector.py index 797670f3d..f08f95a87 100644 --- a/os_brick/tests/initiator/test_connector.py +++ b/os_brick/tests/initiator/test_connector.py @@ -159,6 +159,10 @@ class ConnectorTestCase(base.TestCase): 'glusterfs', None, glusterfs_mount_point_base='/mnt/test') self.assertEqual(obj.__class__.__name__, "RemoteFsConnector") + obj = connector.InitiatorConnector.factory( + 'scality', None, scality_sofs_mount_point_base='/mnt/test') + self.assertEqual(obj.__class__.__name__, "RemoteFsConnector") + obj = connector.InitiatorConnector.factory('local', None) self.assertEqual(obj.__class__.__name__, "LocalConnector") diff --git a/os_brick/tests/remotefs/test_remotefs.py b/os_brick/tests/remotefs/test_remotefs.py index f3e856a5f..8e7ea415e 100644 --- a/os_brick/tests/remotefs/test_remotefs.py +++ b/os_brick/tests/remotefs/test_remotefs.py @@ -174,7 +174,26 @@ class RemoteFsClientTestCase(base.TestCase): def test_no_mount_point_vzstorage(self): self._test_no_mount_point('vzstorage') + def test_no_mount_point_scality(self): + self._test_no_mount_point('scality') + def test_invalid_fs(self): self.assertRaises(exception.ProtocolNotSupported, remotefs.RemoteFsClient, 'my_fs', root_helper='true', execute=putils.execute) + + def test_init_sets_mount_base(self): + client = remotefs.RemoteFsClient("cifs", root_helper='true', + smbfs_mount_point_base='/fake', + cifs_mount_point_base='/fake2') + # Tests that although the FS type is "cifs", the config option + # starts with "smbfs_" + self.assertEqual('/fake', client._mount_base) + + def test_init_nfs_calls_check_nfs_options(self): + to_patch = remotefs.RemoteFsClient._check_nfs_options + with mock.patch.object(to_patch) as mock_check_nfs_options: + remotefs.RemoteFsClient("nfs", root_helper='true', + nfs_mount_point_base='/fake') + + mock_check_nfs_options.assert_called_once_with()