From: Dhairya Parmar Date: Tue, 11 Apr 2023 10:06:52 +0000 (+0530) Subject: mgr/nfs/utils: changes to helper func to check cephfs path X-Git-Tag: v19.0.0~1313^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f3d737093fed625ef9ae85f4e11b3630b2a45e56;p=ceph.git mgr/nfs/utils: changes to helper func to check cephfs path - 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 --- diff --git a/src/pybind/mgr/nfs/tests/test_nfs.py b/src/pybind/mgr/nfs/tests/test_nfs.py index 7b39a9df720c..5b4d5fe7e127 100644 --- a/src/pybind/mgr/nfs/tests/test_nfs.py +++ b/src/pybind/mgr/nfs/tests/test_nfs.py @@ -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) diff --git a/src/pybind/mgr/nfs/utils.py b/src/pybind/mgr/nfs/utils.py index 058b0195d343..ba3190a9644a 100644 --- a/src/pybind/mgr/nfs/utils.py +++ b/src/pybind/mgr/nfs/utils.py @@ -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()