From c13a40b99e7e8bfabd874be1482d5cbdf1237e5e Mon Sep 17 00:00:00 2001 From: Varsha Rao Date: Fri, 5 Jun 2020 16:03:01 +0530 Subject: [PATCH] mgr/volumes/nfs: Check if cluster exists before creating exports Fixes: https://tracker.ceph.com/issues/45740 Signed-off-by: Varsha Rao --- src/pybind/mgr/volumes/fs/nfs.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/pybind/mgr/volumes/fs/nfs.py b/src/pybind/mgr/volumes/fs/nfs.py index e24dd2f0421..3464eec3866 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) -- 2.39.5