From: Varsha Rao Date: Fri, 5 Jun 2020 10:33:01 +0000 (+0530) Subject: mgr/volumes/nfs: Check if cluster exists before creating exports X-Git-Tag: v15.2.5~166^2~22 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=98c1eb58f220fb63cbac282c61def26d7b6fb72c;p=ceph.git mgr/volumes/nfs: Check if cluster exists before creating exports Fixes: https://tracker.ceph.com/issues/45740 Signed-off-by: Varsha Rao (cherry picked from commit c13a40b99e7e8bfabd874be1482d5cbdf1237e5e) --- diff --git a/src/pybind/mgr/volumes/fs/nfs.py b/src/pybind/mgr/volumes/fs/nfs.py index e24dd2f04214..3464eec3866c 100644 --- a/src/pybind/mgr/volumes/fs/nfs.py +++ b/src/pybind/mgr/volumes/fs/nfs.py @@ -316,7 +316,7 @@ class FSExport(object): def __init__(self, mgr, namespace=None): self.mgr = mgr self.rados_pool = 'nfs-ganesha' - self.rados_namespace = namespace #TODO check if cluster exists + self.rados_namespace = namespace self.exports = {} try: @@ -450,9 +450,12 @@ class FSExport(object): def create_export(self, fs_name, cluster_id, pseudo_path, read_only, path): try: if not self.check_fs(fs_name): - return -errno.EINVAL,"", "Invalid CephFS name" + return -errno.ENOENT, "", f"filesystem {fs_name} not found" + + cluster_check = f"ganesha-{cluster_id}" in available_clusters(self.mgr) + if not cluster_check: + return -errno.ENOENT, "", "Cluster does not exists" - #TODO Check if valid cluster if cluster_id not in self.exports: self.exports[cluster_id] = [] @@ -554,7 +557,7 @@ class NFSCluster: log.info(f"Deleted object:{common_conf}") def _set_cluster_id(self, cluster_id): - self.cluster_id = "ganesha-%s" % cluster_id + self.cluster_id = f"ganesha-{cluster_id}" def _set_pool_namespace(self, cluster_id): self.pool_ns = cluster_id @@ -604,7 +607,7 @@ class NFSCluster: if self.cluster_id in available_clusters(self.mgr): self._call_orch_apply_nfs(placement) return 0, "NFS Cluster Updated Successfully", "" - return -errno.EINVAL, "", "Cluster does not exist" + return -errno.ENOENT, "", "Cluster does not exist" except Exception as e: log.warning("NFS Cluster could not be updated") return -errno.EINVAL, "", str(e)