]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/nfs: convert _cmd_nfs_cluster_config_get to ErrorResponseHandler decorator
authorJohn Mulligan <jmulligan@redhat.com>
Fri, 6 May 2022 14:04:41 +0000 (10:04 -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/cluster.py
src/pybind/mgr/nfs/module.py
src/pybind/mgr/nfs/tests/test_nfs.py

index 3a113c43f93f94990635eb3b0e3981c26cfbf116..1e87d0d1afbd03ecb2a47f3c52ff2bb1df68b792 100644 (file)
@@ -2,7 +2,7 @@ import ipaddress
 import logging
 import re
 import socket
-from typing import cast, Dict, List, Any, Union, Optional, TYPE_CHECKING, Tuple
+from typing import cast, Dict, List, Any, Union, Optional, TYPE_CHECKING
 
 from mgr_module import NFS_POOL_NAME as POOL_NAME
 from ceph.deployment.service_spec import NFSServiceSpec, PlacementSpec, IngressSpec
@@ -18,7 +18,7 @@ from .utils import (
     conf_obj_name,
     restart_nfs_service,
     user_conf_obj_name)
-from .export import NFSRados, exception_handler
+from .export import NFSRados
 
 if TYPE_CHECKING:
     from nfs.module import Module
@@ -227,15 +227,16 @@ class NFSCluster:
             log.exception("Failed to show info for cluster")
             raise ErrorResponse.wrap(e)
 
-    def get_nfs_cluster_config(self, cluster_id: str) -> Tuple[int, str, str]:
+    def get_nfs_cluster_config(self, cluster_id: str) -> str:
         try:
             if cluster_id in available_clusters(self.mgr):
                 rados_obj = self._rados(cluster_id)
                 conf = rados_obj.read_obj(user_conf_obj_name(cluster_id))
-                return 0, conf or "", ""
+                return conf or ""
             raise ClusterNotFound()
         except Exception as e:
-            return exception_handler(e, f"Fetching NFS-Ganesha Config failed for {cluster_id}")
+            log.exception(f"Fetching NFS-Ganesha Config failed for {cluster_id}")
+            raise ErrorResponse.wrap(e)
 
     def set_nfs_cluster_config(self, cluster_id: str, nfs_config: str) -> None:
         try:
index d6505eb84742c96702db8a9492eeaff5754d9b43..2774f0945314fb26fe3d7cfa0525359354ada08a 100644 (file)
@@ -152,9 +152,11 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
         return self.nfs.show_nfs_cluster_info(cluster_id=cluster_id)
 
     @CLICommand('nfs cluster config get', perm='r')
+    @object_format.ErrorResponseHandler()
     def _cmd_nfs_cluster_config_get(self, cluster_id: str) -> Tuple[int, str, str]:
         """Fetch NFS-Ganesha config"""
-        return self.nfs.get_nfs_cluster_config(cluster_id=cluster_id)
+        conf = self.nfs.get_nfs_cluster_config(cluster_id=cluster_id)
+        return 0, conf, ""
 
     @CLICommand('nfs cluster config set', perm='rw')
     @CLICheckNonemptyFileInput(desc='NFS-Ganesha Configuration')
index b04b60a6fbdf257fde6b32d9728615184430330a..2f57b85e18d21333246a71620448563b24373e9d 100644 (file)
@@ -1101,20 +1101,17 @@ NFS_CORE_PARAM {
         nfs_mod = Module('nfs', '', '')
         cluster = NFSCluster(nfs_mod)
 
-        rc, out, err = cluster.get_nfs_cluster_config(self.cluster_id)
-        assert rc == 0
+        out = cluster.get_nfs_cluster_config(self.cluster_id)
         assert out == ""
 
         cluster.set_nfs_cluster_config(self.cluster_id, '# foo\n')
 
-        rc, out, err = cluster.get_nfs_cluster_config(self.cluster_id)
-        assert rc == 0
+        out = cluster.get_nfs_cluster_config(self.cluster_id)
         assert out == "# foo\n"
 
         cluster.reset_nfs_cluster_config(self.cluster_id)
 
-        rc, out, err = cluster.get_nfs_cluster_config(self.cluster_id)
-        assert rc == 0
+        out = cluster.get_nfs_cluster_config(self.cluster_id)
         assert out == ""
 
     def test_cluster_config(self):