]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/nfs/utils: changes to helper func to check cephfs path
authorDhairya Parmar <dparmar@redhat.com>
Tue, 11 Apr 2023 10:06:52 +0000 (15:36 +0530)
committerDhairya Parmar <dparmar@redhat.com>
Tue, 2 May 2023 10:10:07 +0000 (15:40 +0530)
- Renamed to cephfs_path_is_dir

- Removed exception handling to prevent redundant log statements like:
   "No such file or directory error in stat: b'/mnt/testdir_symlink': No such file or directory [Errno 2]"

  Exceptions handled inside caller eliminates this redundancy

- Set modifier flag AT_SYMLINK_NOFOLLOW

- Removed string "{path} is not a dir" when raising NotADirectoryError
  Rationale: will be handled in export.py

- change mock to cephfs_path_is_dir

Signed-off-by: Dhairya Parmar <dparmar@redhat.com>
(cherry picked from commit f3d737093fed625ef9ae85f4e11b3630b2a45e56)

src/pybind/mgr/nfs/tests/test_nfs.py
src/pybind/mgr/nfs/utils.py

index 4aa20db4b0c5e4a6a787a328c06a200e7a7f36b3..a1caba5ea0f767269b81ca987cacefd1283167bc 100644 (file)
@@ -252,7 +252,7 @@ EXPORT {
                 mock.patch('nfs.export_utils.check_fs', return_value=True), \
                 mock.patch('nfs.export.ExportMgr._create_user_key',
                            return_value='thekeyforclientabc'), \
-                mock.patch('nfs.export.check_cephfs_path'):
+                mock.patch('nfs.export.cephfs_path_is_dir'):
 
             rados.open_ioctx.return_value.__enter__.return_value = self.io_mock
             rados.open_ioctx.return_value.__exit__ = mock.Mock(return_value=None)
index ebf2c0d64835689ad24686ed9bc733c428e79715..110aa3a94ed879f1887f818dc84ca20ff170f320 100644 (file)
@@ -1,4 +1,3 @@
-import errno
 import functools
 import logging
 import stat
@@ -67,23 +66,14 @@ def check_fs(mgr: 'Module', fs_name: str) -> bool:
     return fs_name in [fs['mdsmap']['fs_name'] for fs in fs_map['filesystems']]
 
 
-def check_cephfs_path(mgr: 'Module', fs: str, path: str) -> None:
+def cephfs_path_is_dir(mgr: 'Module', fs: str, path: str) -> None:
     @functools.lru_cache(maxsize=1)
     def _get_cephfs_client() -> CephfsClient:
         return CephfsClient(mgr)
-    try:
-        cephfs_client = _get_cephfs_client()
-        with open_filesystem(cephfs_client, fs) as fs_handle:
-            stx = fs_handle.statx(path.encode('utf-8'),
-                                  cephfs.CEPH_STATX_MODE, 0)
-            if not stat.S_ISDIR(stx.get('mode')):
-                raise NotADirectoryError(f"{path} is not a dir")
-    except cephfs.ObjectNotFound as e:
-        log.exception(f"{-errno.ENOENT}: {e.args[1]}")
-        raise e
-    except cephfs.Error as e:
-        log.exception(f"{e.args[0]}: {e.args[1]}")
-        raise e
-    except Exception as e:
-        log.exception(f"unknown exception occurred: {e}")
-        raise e
+    cephfs_client = _get_cephfs_client()
+
+    with open_filesystem(cephfs_client, fs) as fs_handle:
+        stx = fs_handle.statx(path.encode('utf-8'), cephfs.CEPH_STATX_MODE,
+                              cephfs.AT_SYMLINK_NOFOLLOW)
+        if not stat.S_ISDIR(stx.get('mode')):
+            raise NotADirectoryError()