Skip to content

Commit b6017ad

Browse files
committed
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 <[email protected]>
1 parent 009e20e commit b6017ad

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/pybind/mgr/rgw/module.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,12 @@ def _cmd_rgw_zone_create(self,
310310
inbuf: Optional[str] = None) -> HandleCommandResult:
311311
"""Bootstrap new rgw zone that syncs with zone on another cluster in the same realm"""
312312

313-
created_zones = self.rgw_zone_create(zone_name, realm_token, port, placement,
314-
start_radosgw, zone_endpoints, inbuf)
315-
316-
return HandleCommandResult(retval=0, stdout=f"Zones {', '.join(created_zones)} created successfully")
313+
try:
314+
created_zones = self.rgw_zone_create(zone_name, realm_token, port, placement,
315+
start_radosgw, zone_endpoints, inbuf)
316+
return HandleCommandResult(retval=0, stdout=f"Zones {', '.join(created_zones)} created successfully")
317+
except RGWAMException as e:
318+
return HandleCommandResult(retval=e.retcode, stderr=f'Failed to create zone: {str(e)}')
317319

318320
def rgw_zone_create(self,
319321
zone_name: Optional[str] = None,
@@ -322,13 +324,13 @@ def rgw_zone_create(self,
322324
placement: Optional[Union[str, Dict[str, Any]]] = None,
323325
start_radosgw: Optional[bool] = True,
324326
zone_endpoints: Optional[str] = None,
325-
inbuf: Optional[str] = None) -> Any:
327+
inbuf: Optional[str] = None) -> List[str]:
326328

327329
if inbuf:
328330
try:
329331
rgw_specs = self._parse_rgw_specs(inbuf)
330332
except RGWSpecParsingError as e:
331-
return HandleCommandResult(retval=-errno.EINVAL, stderr=f'{e}')
333+
raise RGWAMException(str(e))
332334
elif (zone_name and realm_token):
333335
token = RealmToken.from_base64_str(realm_token)
334336
if isinstance(placement, dict):
@@ -343,7 +345,7 @@ def rgw_zone_create(self,
343345
zone_endpoints=zone_endpoints)]
344346
else:
345347
err_msg = 'Invalid arguments: either pass a spec with -i or provide the zone_name and realm_token.'
346-
return HandleCommandResult(retval=-errno.EINVAL, stdout='', stderr=err_msg)
348+
raise RGWAMException(err_msg)
347349

348350
try:
349351
created_zones = []
@@ -353,8 +355,9 @@ def rgw_zone_create(self,
353355
created_zones.append(rgw_spec.rgw_zone)
354356
return created_zones
355357
except RGWAMException as e:
356-
self.log.error('cmd run exception: (%d) %s' % (e.retcode, e.message))
357-
return HandleCommandResult(retval=e.retcode, stdout=e.stdout, stderr=e.stderr)
358+
err_msg = 'cmd run exception: (%d) %s' % (e.retcode, e.message)
359+
self.log.error(err_msg)
360+
raise e
358361
return created_zones
359362

360363
@CLICommand('rgw realm reconcile', perm='rw')

0 commit comments

Comments
 (0)