From 4005a5d3a9806810159d8e86364d8fd28db9ca0e Mon Sep 17 00:00:00 2001 From: Varsha Rao Date: Thu, 14 May 2020 16:46:48 +0530 Subject: [PATCH] mgr/volumes: Make nfs create export interface idempotent Signed-off-by: Varsha Rao (cherry picked from commit b3b83b0554441597c6a7a282e55a5fb3ce8b9982) --- src/pybind/mgr/volumes/fs/nfs.py | 50 ++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/pybind/mgr/volumes/fs/nfs.py b/src/pybind/mgr/volumes/fs/nfs.py index 4ccb97be3ec2a..8b1fa8ac2af75 100644 --- a/src/pybind/mgr/volumes/fs/nfs.py +++ b/src/pybind/mgr/volumes/fs/nfs.py @@ -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, -- 2.39.5