From f27fdd89909e45e29b0ba8f4932926c6bae07cc6 Mon Sep 17 00:00:00 2001 From: Adam King Date: Wed, 19 Jun 2024 15:04:21 -0400 Subject: [PATCH] mgr/rgw: fix error handling in rgw zone create This was returning either a list of strings or a HandleCommandResult and in the latter case it would error out trying to build the final return message which covered up the original error Fixes: https://tracker.ceph.com/issues/66568 Signed-off-by: Adam King (cherry picked from commit b6017adfde3c56f0cddcd3d8174e094c26844ac2) --- src/pybind/mgr/rgw/module.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/pybind/mgr/rgw/module.py b/src/pybind/mgr/rgw/module.py index f48e2e09fc323..fb2b978995685 100644 --- a/src/pybind/mgr/rgw/module.py +++ b/src/pybind/mgr/rgw/module.py @@ -298,10 +298,12 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): inbuf: Optional[str] = None) -> HandleCommandResult: """Bootstrap new rgw zone that syncs with zone on another cluster in the same realm""" - created_zones = self.rgw_zone_create(zone_name, realm_token, port, placement, - start_radosgw, zone_endpoints, inbuf) - - return HandleCommandResult(retval=0, stdout=f"Zones {', '.join(created_zones)} created successfully") + try: + created_zones = self.rgw_zone_create(zone_name, realm_token, port, placement, + start_radosgw, zone_endpoints, inbuf) + return HandleCommandResult(retval=0, stdout=f"Zones {', '.join(created_zones)} created successfully") + except RGWAMException as e: + return HandleCommandResult(retval=e.retcode, stderr=f'Failed to create zone: {str(e)}') def rgw_zone_create(self, zone_name: Optional[str] = None, @@ -310,13 +312,13 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): placement: Optional[Union[str, Dict[str, Any]]] = None, start_radosgw: Optional[bool] = True, zone_endpoints: Optional[str] = None, - inbuf: Optional[str] = None) -> Any: + inbuf: Optional[str] = None) -> List[str]: if inbuf: try: rgw_specs = self._parse_rgw_specs(inbuf) except RGWSpecParsingError as e: - return HandleCommandResult(retval=-errno.EINVAL, stderr=f'{e}') + raise RGWAMException(str(e)) elif (zone_name and realm_token): token = RealmToken.from_base64_str(realm_token) if isinstance(placement, dict): @@ -331,7 +333,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): zone_endpoints=zone_endpoints)] else: err_msg = 'Invalid arguments: either pass a spec with -i or provide the zone_name and realm_token.' - return HandleCommandResult(retval=-errno.EINVAL, stdout='', stderr=err_msg) + raise RGWAMException(err_msg) try: created_zones = [] @@ -341,8 +343,9 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): created_zones.append(rgw_spec.rgw_zone) return created_zones except RGWAMException as e: - self.log.error('cmd run exception: (%d) %s' % (e.retcode, e.message)) - return HandleCommandResult(retval=e.retcode, stdout=e.stdout, stderr=e.stderr) + err_msg = 'cmd run exception: (%d) %s' % (e.retcode, e.message) + self.log.error(err_msg) + raise e return created_zones @CLICommand('rgw realm reconcile', perm='rw') -- 2.39.5