]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/nfs: test Export.validate(); several fixes
authorSage Weil <sage@newdream.net>
Fri, 11 Jun 2021 19:55:27 +0000 (15:55 -0400)
committerSage Weil <sage@newdream.net>
Mon, 21 Jun 2021 18:13:15 +0000 (14:13 -0400)
Signed-off-by: Sage Weil <sage@newdream.net>
src/pybind/mgr/nfs/export_utils.py
src/pybind/mgr/nfs/tests/test_nfs.py

index 8a8a09b5cc7e65d46471fcec5b9934bfa2b1909a..63f43ac030a6b25f6bcdd98fe9c0a91fdd0d0f25 100644 (file)
@@ -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)
index cfa8c96d40a0b25bd20c7636588dbdb9501f0453..0fd36e0e81e1eeae6f357e3d0b9aed4361b730a1 100644 (file)
@@ -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'])