]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/volumes/nfs: Check if cluster exists before creating exports
authorVarsha Rao <varao@redhat.com>
Fri, 5 Jun 2020 10:33:01 +0000 (16:03 +0530)
committerVarsha Rao <varao@redhat.com>
Tue, 30 Jun 2020 17:47:38 +0000 (23:17 +0530)
Fixes: https://tracker.ceph.com/issues/45740
Signed-off-by: Varsha Rao <varao@redhat.com>
src/pybind/mgr/volumes/fs/nfs.py

index e24dd2f04214f313b4c79a353babe7167ffa4372..3464eec3866c39f1f8c6543f1212647edb7b3760 100644 (file)
@@ -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)