]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/nfs: convert _cmd_nfs_export_rm to use EmptyResponder decorator
authorJohn Mulligan <jmulligan@redhat.com>
Fri, 6 May 2022 15:24:21 +0000 (11:24 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Thu, 12 Jan 2023 18:44:11 +0000 (13:44 -0500)
Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/pybind/mgr/nfs/export.py
src/pybind/mgr/nfs/module.py
src/pybind/mgr/nfs/tests/test_nfs.py

index 4646696ec151926b79c8e4237d92c1134ed98475..a040b94018f0ea53d8ad8a3777b3265f8690347c 100644 (file)
@@ -323,7 +323,7 @@ class ExportMgr:
             cluster_id: str,
             pseudo_path: Optional[str],
             export_obj: Optional[Export] = None
-    ) -> Tuple[int, str, str]:
+    ) -> None:
         try:
             if export_obj:
                 export: Optional[Export] = export_obj
@@ -340,10 +340,11 @@ class ExportMgr:
                 if not self.exports[cluster_id]:
                     del self.exports[cluster_id]
                     log.debug("Deleted all exports for cluster %s", cluster_id)
-                return 0, "Successfully deleted export", ""
-            return 0, "", "Export does not exist"
+                return None
+            raise NonFatalError("Export does not exist")
         except Exception as e:
-            return exception_handler(e, f"Failed to delete {pseudo_path} export for {cluster_id}")
+            log.exception(f"Failed to delete {pseudo_path} export for {cluster_id}")
+            raise ErrorResponse.wrap(e)
 
     def _fetch_export_obj(self, cluster_id: str, ex_id: int) -> Optional[Export]:
         try:
@@ -413,10 +414,10 @@ class ExportMgr:
             log.exception(f"Failed to create {kwargs['pseudo_path']} export for {kwargs['cluster_id']}")
             raise ErrorResponse.wrap(e)
 
-    @export_cluster_checker
     def delete_export(self,
                       cluster_id: str,
-                      pseudo_path: str) -> Tuple[int, str, str]:
+                      pseudo_path: str) -> None:
+        self._validate_cluster_id(cluster_id)
         return self._delete_export(cluster_id, pseudo_path)
 
     def delete_all_exports(self, cluster_id: str) -> None:
@@ -426,10 +427,11 @@ class ExportMgr:
             log.info("No exports to delete")
             return
         for export in export_list:
-            ret, out, err = self._delete_export(cluster_id=cluster_id, pseudo_path=None,
-                                                export_obj=export)
-            if ret != 0:
-                raise NFSException(f"Failed to delete exports: {err} and {ret}")
+            try:
+                self._delete_export(cluster_id=cluster_id, pseudo_path=None,
+                                    export_obj=export)
+            except Exception as e:
+                raise NFSException(f"Failed to delete export {export.export_id}: {e}")
         log.info("All exports successfully deleted for cluster id: %s", cluster_id)
 
     def list_all_exports(self) -> List[Dict[str, Any]]:
index 0e28e1b7934624b3b5b5a50d48554e26c72aae11..e883408a8b188b076afc17fcaf83248e6c6aa7e6 100644 (file)
@@ -78,12 +78,14 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
         )
 
     @CLICommand('nfs export rm', perm='rw')
-    def _cmd_nfs_export_rm(self, cluster_id: str, pseudo_path: str) -> Tuple[int, str, str]:
+    @object_format.EmptyResponder()
+    def _cmd_nfs_export_rm(self, cluster_id: str, pseudo_path: str) -> None:
         """Remove a cephfs export"""
         return self.export_mgr.delete_export(cluster_id=cluster_id, pseudo_path=pseudo_path)
 
     @CLICommand('nfs export delete', perm='rw')
-    def _cmd_nfs_export_delete(self, cluster_id: str, pseudo_path: str) -> Tuple[int, str, str]:
+    @object_format.EmptyResponder()
+    def _cmd_nfs_export_delete(self, cluster_id: str, pseudo_path: str) -> None:
         """Delete a cephfs export (DEPRECATED)"""
         return self.export_mgr.delete_export(cluster_id=cluster_id, pseudo_path=pseudo_path)
 
index 97512f1a356d2fa88eef03b644366075d285d9fe..50f864d3ba1cb22e14a7e42270d3ad7b25f1f436 100644 (file)
@@ -899,8 +899,8 @@ NFS_CORE_PARAM {
         nfs_mod = Module('nfs', '', '')
         conf = ExportMgr(nfs_mod)
         assert len(conf.exports[self.cluster_id]) == 2
-        assert conf.delete_export(cluster_id=self.cluster_id,
-                                  pseudo_path="/rgw") == (0, "Successfully deleted export", "")
+        conf.delete_export(cluster_id=self.cluster_id,
+                           pseudo_path="/rgw")
         exports = conf.exports[self.cluster_id]
         assert len(exports) == 1
         assert exports[0].export_id == 1