]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/volumes: Make nfs create export interface idempotent
authorVarsha Rao <varao@redhat.com>
Thu, 14 May 2020 11:16:48 +0000 (16:46 +0530)
committerVarsha Rao <varao@redhat.com>
Wed, 8 Jul 2020 05:36:34 +0000 (07:36 +0200)
Signed-off-by: Varsha Rao <varao@redhat.com>
(cherry picked from commit b3b83b0554441597c6a7a282e55a5fb3ce8b9982)

src/pybind/mgr/volumes/fs/nfs.py

index 4ccb97be3ec2a2ba878b73c62b01099b7601d043..8b1fa8ac2af752065fb667c4fd0fd966e87ab45b 100644 (file)
@@ -232,7 +232,7 @@ class FSExport(object):
             })
 
         if ret!= 0:
-            log.error(f"User could not be deleted: {err}")
+            log.warning(f"User could not be deleted: {err}")
 
     def format_path(self, path):
         if path is not None:
@@ -297,36 +297,42 @@ class FSExport(object):
     def create_export(self, export_type, fs_name, pseudo_path, read_only, path, cluster_id):
         if export_type != 'cephfs':
             return -errno.EINVAL,"", f"Invalid export type: {export_type}"
+
+        if not self.check_fs(fs_name):
+            return -errno.EINVAL,"", "Invalid CephFS name"
+
         #TODO Check if valid cluster
         if cluster_id not in self.exports:
             self.exports[cluster_id] = []
 
         self.rados_namespace = cluster_id
-        if not self.check_fs(fs_name) or self._fetch_export(pseudo_path):
-            return -errno.EINVAL,"", "Invalid CephFS name or export already exists"
-
-        ex_id = self._gen_export_id()
-        user_id = f"{cluster_id}{ex_id}"
-        user_out, key = self._create_user_key(user_id, path, fs_name)
-        if isinstance(user_out, int):
-            return user_out, "", key
-
         access_type = "RW"
         if read_only:
             access_type = "R"
 
-        ex_dict = {
-            'path': self.format_path(path),
-            'pseudo': self.format_path(pseudo_path),
-            'cluster_id': cluster_id,
-            'access_type': access_type,
-            'fsal': {"name": "CEPH", "user_id": user_id, "fs_name": fs_name, "sec_label_xattr": ""},
-            'clients': []
-            }
-
-        export = Export.from_dict(ex_id, ex_dict)
-        export.fsal.cephx_key = key
-        self._save_export(export)
+        if not self._fetch_export(pseudo_path):
+            ex_id = self._gen_export_id()
+            user_id = f"{cluster_id}{ex_id}"
+            user_out, key = self._create_user_key(user_id, path, fs_name)
+
+            if isinstance(user_out, int):
+                return user_out, "", key
+
+            ex_dict = {
+                    'path': self.format_path(path),
+                    'pseudo': self.format_path(pseudo_path),
+                    'cluster_id': cluster_id,
+                    'access_type': access_type,
+                    'fsal': {"name": "CEPH", "user_id": user_id,
+                             "fs_name": fs_name, "sec_label_xattr": ""},
+                    'clients': []
+                    }
+
+            export = Export.from_dict(ex_id, ex_dict)
+            export.fsal.cephx_key = key
+            self._save_export(export)
+        else:
+            log.error("Export already exists")
 
         result = {
             "bind": pseudo_path,