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)
-import errno
import functools
import logging
import stat
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()