]> git.apps.os.sepia.ceph.com Git - ceph-ci.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 09:46:45 +0000 (15:16 +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 f3d7370)

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

index 7b39a9df720c8a1abcca465e538b54fbd7e3eb80..5b4d5fe7e127f4c79db57a17fb4d634264361f0e 100644 (file)
@@ -252,7 +252,7 @@ EXPORT {
                 mock.patch('nfs.ganesha_conf.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 058b0195d343de045ae0ad91f69e2391db78fa39..ba3190a9644a0abc55ab331c9b2c35de1eba7fec 100644 (file)
@@ -1,4 +1,3 @@
-import errno
 import functools
 import logging
 import stat
@@ -92,23 +91,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()