From 3c9102bcba764c02dc1a9c5150647fc2e46eb926 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Thu, 5 May 2022 15:38:44 -0400 Subject: [PATCH] mgr/nfs: convert _cmd_nfs_cluster_create to use EmptyResponder decorator Signed-off-by: John Mulligan --- src/pybind/mgr/nfs/cluster.py | 18 +++++++++++------- src/pybind/mgr/nfs/module.py | 3 ++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/pybind/mgr/nfs/cluster.py b/src/pybind/mgr/nfs/cluster.py index 041534b8b6d..0c072c7b31d 100644 --- a/src/pybind/mgr/nfs/cluster.py +++ b/src/pybind/mgr/nfs/cluster.py @@ -11,8 +11,12 @@ from object_format import ErrorResponse import orchestrator from .exception import NFSInvalidOperation, ClusterNotFound -from .utils import (available_clusters, restart_nfs_service, conf_obj_name, - user_conf_obj_name) +from .utils import ( + NonFatalError, + available_clusters, + conf_obj_name, + restart_nfs_service, + user_conf_obj_name) from .export import NFSRados, exception_handler if TYPE_CHECKING: @@ -105,8 +109,7 @@ class NFSCluster: virtual_ip: Optional[str], ingress: Optional[bool] = None, port: Optional[int] = None, - ) -> Tuple[int, str, str]: - + ) -> None: try: if virtual_ip: # validate virtual_ip value: ip_address throws a ValueError @@ -128,10 +131,11 @@ class NFSCluster: if cluster_id not in available_clusters(self.mgr): self._call_orch_apply_nfs(cluster_id, placement, virtual_ip, port) - return 0, "", "" - return 0, "", f"{cluster_id} cluster already exists" + return + raise NonFatalError(f"{cluster_id} cluster already exists") except Exception as e: - return exception_handler(e, f"NFS Cluster {cluster_id} could not be created") + log.exception(f"NFS Cluster {cluster_id} could not be created") + raise ErrorResponse.wrap(e) def delete_nfs_cluster(self, cluster_id: str) -> Tuple[int, str, str]: try: diff --git a/src/pybind/mgr/nfs/module.py b/src/pybind/mgr/nfs/module.py index e883408a8b1..1be52f9512a 100644 --- a/src/pybind/mgr/nfs/module.py +++ b/src/pybind/mgr/nfs/module.py @@ -114,12 +114,13 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): return self.export_mgr.apply_export(cluster_id, export_config=inbuf) @CLICommand('nfs cluster create', perm='rw') + @object_format.EmptyResponder() def _cmd_nfs_cluster_create(self, cluster_id: str, placement: Optional[str] = None, ingress: Optional[bool] = None, virtual_ip: Optional[str] = None, - port: Optional[int] = None) -> Tuple[int, str, str]: + port: Optional[int] = None) -> None: """Create an NFS Cluster""" return self.nfs.create_nfs_cluster(cluster_id=cluster_id, placement=placement, virtual_ip=virtual_ip, ingress=ingress,