]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/nfs: convert _cmd_nfs_cluster_info to use Responder decorator
authorJohn Mulligan <jmulligan@redhat.com>
Sat, 7 May 2022 14:30:12 +0000 (10:30 -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 b14879dd408ca99168762c98a8ab6ccfce7bb21b..041534b8b6d729414c94a7dbbec5bbe555fee334 100644 (file)
@@ -1,6 +1,5 @@
 import ipaddress
 import logging
-import json
 import re
 import socket
 from typing import cast, Dict, List, Any, Union, Optional, TYPE_CHECKING, Tuple
@@ -203,7 +202,7 @@ class NFSCluster:
         log.debug("Successfully fetched %s info: %s", cluster_id, r)
         return r
 
-    def show_nfs_cluster_info(self, cluster_id: Optional[str] = None) -> Tuple[int, str, str]:
+    def show_nfs_cluster_info(self, cluster_id: Optional[str] = None) -> Dict[str, Any]:
         try:
             if cluster_id and cluster_id not in available_clusters(self.mgr):
                 raise ClusterNotFound()
@@ -217,9 +216,10 @@ class NFSCluster:
                 res = self._show_nfs_cluster_info(cluster_id)
                 if res:
                     info_res[cluster_id] = res
-            return (0, json.dumps(info_res, indent=4), '')
+            return info_res
         except Exception as e:
-            return exception_handler(e, "Failed to show info for cluster")
+            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]:
         try:
index 036fd8a773f40dc183785ab388219a0f12b74bdb..537c6be39eb0a505e0dc2359654d7e2013f2ef94 100644 (file)
@@ -138,7 +138,8 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
         return self.nfs.list_nfs_cluster()
 
     @CLICommand('nfs cluster info', perm='r')
-    def _cmd_nfs_cluster_info(self, cluster_id: Optional[str] = None) -> Tuple[int, str, str]:
+    @object_format.Responder()
+    def _cmd_nfs_cluster_info(self, cluster_id: Optional[str] = None) -> Dict[str, Any]:
         """Displays NFS Cluster info"""
         return self.nfs.show_nfs_cluster_info(cluster_id=cluster_id)
 
index 494760cf57c8eb666b896141a6e0a31ad1c76a49..5607396bbe007cf5656bd798367fb0724d611afd 100644 (file)
@@ -1088,9 +1088,8 @@ NFS_CORE_PARAM {
         nfs_mod = Module('nfs', '', '')
         cluster = NFSCluster(nfs_mod)
 
-        rc, out, err = cluster.show_nfs_cluster_info(self.cluster_id)
-        assert rc == 0
-        assert json.loads(out) == {"foo": {"virtual_ip": None, "backend": []}}
+        out = cluster.show_nfs_cluster_info(self.cluster_id)
+        assert out == {"foo": {"virtual_ip": None, "backend": []}}
 
     def test_cluster_info(self):
         self._do_mock_test(self._do_test_cluster_info)