From b53ffbf86519446953497cd60ae9cad53481df6e Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Sat, 7 May 2022 10:29:33 -0400 Subject: [PATCH] mgr/nfs: convert _cmd_nfs_cluster_ls to use Responder decorator Signed-off-by: John Mulligan --- src/pybind/mgr/nfs/cluster.py | 8 +++++--- src/pybind/mgr/nfs/module.py | 3 ++- src/pybind/mgr/nfs/tests/test_nfs.py | 5 ++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/pybind/mgr/nfs/cluster.py b/src/pybind/mgr/nfs/cluster.py index 2b640754afb..b14879dd408 100644 --- a/src/pybind/mgr/nfs/cluster.py +++ b/src/pybind/mgr/nfs/cluster.py @@ -7,6 +7,7 @@ from typing import cast, Dict, List, Any, Union, Optional, TYPE_CHECKING, Tuple from mgr_module import NFS_POOL_NAME as POOL_NAME from ceph.deployment.service_spec import NFSServiceSpec, PlacementSpec, IngressSpec +from object_format import ErrorResponse import orchestrator @@ -148,11 +149,12 @@ class NFSCluster: except Exception as e: return exception_handler(e, f"Failed to delete NFS Cluster {cluster_id}") - def list_nfs_cluster(self) -> Tuple[int, str, str]: + def list_nfs_cluster(self) -> List[str]: try: - return 0, '\n'.join(available_clusters(self.mgr)), "" + return available_clusters(self.mgr) except Exception as e: - return exception_handler(e, "Failed to list NFS Cluster") + log.exception("Failed to list NFS Cluster") + raise ErrorResponse.wrap(e) def _show_nfs_cluster_info(self, cluster_id: str) -> Dict[str, Any]: completion = self.mgr.list_daemons(daemon_type='nfs') diff --git a/src/pybind/mgr/nfs/module.py b/src/pybind/mgr/nfs/module.py index 891cf47692c..036fd8a773f 100644 --- a/src/pybind/mgr/nfs/module.py +++ b/src/pybind/mgr/nfs/module.py @@ -132,7 +132,8 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): return self.nfs.delete_nfs_cluster(cluster_id=cluster_id) @CLICommand('nfs cluster ls', perm='r') - def _cmd_nfs_cluster_ls(self) -> Tuple[int, str, str]: + @object_format.Responder() + def _cmd_nfs_cluster_ls(self) -> List[str]: """List NFS Clusters""" return self.nfs.list_nfs_cluster() diff --git a/src/pybind/mgr/nfs/tests/test_nfs.py b/src/pybind/mgr/nfs/tests/test_nfs.py index 6fdf6d1583b..494760cf57c 100644 --- a/src/pybind/mgr/nfs/tests/test_nfs.py +++ b/src/pybind/mgr/nfs/tests/test_nfs.py @@ -1078,9 +1078,8 @@ NFS_CORE_PARAM { nfs_mod = Module('nfs', '', '') cluster = NFSCluster(nfs_mod) - rc, out, err = cluster.list_nfs_cluster() - assert rc == 0 - assert out == self.cluster_id + out = cluster.list_nfs_cluster() + assert out[0] == self.cluster_id def test_cluster_ls(self): self._do_mock_test(self._do_test_cluster_ls)