]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/rgw: fix error handling in rgw zone create 61713/head
authorAdam King <adking@redhat.com>
Wed, 19 Jun 2024 19:04:21 +0000 (15:04 -0400)
committerAdam King <adking@redhat.com>
Fri, 7 Feb 2025 20:45:21 +0000 (15:45 -0500)
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 <adking@redhat.com>
(cherry picked from commit b6017adfde3c56f0cddcd3d8174e094c26844ac2)

src/pybind/mgr/rgw/module.py

index f48e2e09fc32350592cc9c7bb4c335ea1ce744ae..fb2b978995685c7f2eb37ce27df808253cf3d8b2 100644 (file)
@@ -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')