From 9a738872917d7b9bfcf9621c8d2a0ae5c71eab3c Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Fri, 6 May 2022 10:04:41 -0400 Subject: [PATCH] mgr/nfs: convert _cmd_nfs_cluster_config_get to ErrorResponseHandler decorator Signed-off-by: John Mulligan --- src/pybind/mgr/nfs/cluster.py | 11 ++++++----- src/pybind/mgr/nfs/module.py | 4 +++- src/pybind/mgr/nfs/tests/test_nfs.py | 9 +++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/pybind/mgr/nfs/cluster.py b/src/pybind/mgr/nfs/cluster.py index 3a113c43f93f9..1e87d0d1afbd0 100644 --- a/src/pybind/mgr/nfs/cluster.py +++ b/src/pybind/mgr/nfs/cluster.py @@ -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: diff --git a/src/pybind/mgr/nfs/module.py b/src/pybind/mgr/nfs/module.py index d6505eb84742c..2774f0945314f 100644 --- a/src/pybind/mgr/nfs/module.py +++ b/src/pybind/mgr/nfs/module.py @@ -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') diff --git a/src/pybind/mgr/nfs/tests/test_nfs.py b/src/pybind/mgr/nfs/tests/test_nfs.py index b04b60a6fbdf2..2f57b85e18d21 100644 --- a/src/pybind/mgr/nfs/tests/test_nfs.py +++ b/src/pybind/mgr/nfs/tests/test_nfs.py @@ -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): -- 2.39.5