From 01a8d0ba3d5aaf09b26de3acee33772c43ed9cac Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 11 Jun 2021 15:55:27 -0400 Subject: [PATCH] mgr/nfs: test Export.validate(); several fixes Signed-off-by: Sage Weil --- src/pybind/mgr/nfs/export_utils.py | 16 ++++++++++------ src/pybind/mgr/nfs/tests/test_nfs.py | 22 ++++++++++++++++++++-- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/pybind/mgr/nfs/export_utils.py b/src/pybind/mgr/nfs/export_utils.py index 8a8a09b5cc7..63f43ac030a 100644 --- a/src/pybind/mgr/nfs/export_utils.py +++ b/src/pybind/mgr/nfs/export_utils.py @@ -385,14 +385,16 @@ class Export: protocols = [protocols] transports = export_block.values.get('transports') - if not isinstance(transports, list): + if isinstance(transports, str): transports = [transports] + elif not transports: + transports = [] return cls(export_block.values['export_id'], export_block.values['path'], cluster_id, export_block.values['pseudo'], - export_block.values['access_type'], + export_block.values.get('access_type', 'none'), export_block.values.get('squash', 'no_root_squash'), export_block.values.get('security_label', True), protocols, @@ -453,7 +455,7 @@ class Export: @staticmethod def validate_access_type(access_type: str) -> None: valid_access_types = ['rw', 'ro', 'none'] - if access_type.lower() not in valid_access_types: + if not isinstance(access_type, str) or access_type.lower() not in valid_access_types: raise NFSInvalidOperation( f'{access_type} is invalid, valid access type are' f'{valid_access_types}' @@ -466,7 +468,7 @@ class Export: "rootidsquash", "all", "all_squash", "allsquash", "all_anomnymous", "allanonymous", "no_root_squash", "none", "noidsquash", ] - if squash not in valid_squash_ls: + if squash.lower() not in valid_squash_ls: raise NFSInvalidOperation( f"squash {squash} not in valid list {valid_squash_ls}" ) @@ -494,8 +496,10 @@ class Export: raise NFSInvalidOperation(f'{trans} is not a valid transport protocol') for client in self.clients: - self.validate_squash(client.squash) - self.validate_access_type(client.access_type) + if client.squash: + self.validate_squash(client.squash) + if client.access_type: + self.validate_access_type(client.access_type) if self.fsal.name == 'CEPH': fs = cast(CephFSFSAL, self.fsal) diff --git a/src/pybind/mgr/nfs/tests/test_nfs.py b/src/pybind/mgr/nfs/tests/test_nfs.py index cfa8c96d40a..0fd36e0e81e 100644 --- a/src/pybind/mgr/nfs/tests/test_nfs.py +++ b/src/pybind/mgr/nfs/tests/test_nfs.py @@ -389,7 +389,7 @@ NFS_CORE_PARAM { 'pseudo': '/cephfs_a/', 'security_label': True, 'squash': 'no_root_squash', - 'transports': [None]} + 'transports': []} export = [e for e in conf.exports['foo'] if e.export_id == 2][0] ex_dict = export.to_dict() @@ -534,7 +534,25 @@ NFS_CORE_PARAM { export2 = Export.from_dict(j['export_id'], j) j2 = export2.to_dict() assert j == j2 - """ + + @pytest.mark.parametrize( + "block", + [ + export_1, + export_2, + ] + ) + def test_export_validate(self, block): + cluster_id = 'foo' + blocks = GaneshaConfParser(block).parse() + print(block) + export = Export.from_export_block(blocks[0], cluster_id) + print(export.__dict__) + nfs_mod = Module('nfs', '', '') + with mock.patch('nfs.export_utils.check_fs', return_value=True): + export.validate(nfs_mod) + + """ def test_update_export(self): for cluster_id, info in self.clusters.items(): self._do_test_update_export(cluster_id, info['exports']) -- 2.39.5