mgr/nfs: convert _cmd_nfs_cluster_ls to use Responder decorator

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2022-05-07 10:29:33 -04:00
parent fdac9f71e4
commit b53ffbf865
3 changed files with 9 additions and 7 deletions

View File

@ -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')

View File

@ -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()

View File

@ -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)