Skip to content

Commit 865ff7a

Browse files
authored
Merge pull request ceph#62808 from adk3798/mgr-rgw-fix-re-realm-bootstrap-after-deletions
mgr/rgw: don't fail realm bootstrap if system user exists already Reviewed-by: Redouane Kachach <[email protected]>
2 parents c350174 + 42c07e9 commit 865ff7a

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

src/pybind/mgr/rgw/module.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,33 @@ def _cmd_rgw_realm_bootstrap(self,
210210
RGWAM(self.env).realm_bootstrap(spec, start_radosgw)
211211
except RGWAMException as e:
212212
self.log.error('cmd run exception: (%d) %s' % (e.retcode, e.message))
213-
return HandleCommandResult(retval=e.retcode, stdout=e.stdout, stderr=e.stderr)
213+
# The RGWAM code isn't always consistent about what goes into stdout
214+
# and message fields. What is known is there are definitely some cases
215+
# where the message field contains useful info and the stdout field
216+
# does not, which means just giving the stdout can result in not so useful
217+
# return messages, e.g.
218+
#
219+
# [ceph: root@vm-00 /]# ceph rgw realm bootstrap -i specs/rgw.yaml
220+
# Error EEXIST:
221+
#
222+
# For that reason, we want to include the msg in what we return. Doing so
223+
# transformed the same error case that just gave us "Error EEXIST:" into
224+
#
225+
# [ceph: root@vm-00 /]# ceph rgw realm bootstrap -i specs/rgw.yaml
226+
# failed to create system user: Command error (-17): user create --uid sysuser-my_realm_ck
227+
# --display-name sysuser-my_realm_ck --system --rgw-zonegroup my_zonegroup_ck --zonegroup-id
228+
# 428a28d1-c8a9-4c12-a408-29507ef23842 --rgw-zone my_zone_ck --zone-id 161ee2ab-bc96-4729-a2b5-0d170e347129
229+
# stdout:
230+
# stderr:could not create user: unable to parse parameters, user: sysuser-my_realm_ck exists
231+
# Error EEXIST:
232+
#
233+
# which is much more useful
234+
msg = e.message
235+
if msg and e.stdout and (e.stdout not in msg):
236+
msg = f'{msg}; {e.stdout}'
237+
elif e.stdout:
238+
msg = e.stdout
239+
return HandleCommandResult(retval=e.retcode, stdout=msg, stderr=e.stderr)
214240
except PoolCreationError as e:
215241
self.log.error(f'Pool creation failure: {str(e)}')
216242
return HandleCommandResult(retval=-errno.EINVAL, stderr=str(e))

src/python-common/ceph/rgw/rgwam_core.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -503,16 +503,38 @@ def create_zone(self, realm, zg, zone_name, zone_is_master, access_key=None,
503503

504504
def create_system_user(self, realm, zonegroup, zone):
505505
try:
506-
sys_user_info = self.user_op().create(zone,
507-
zonegroup,
508-
uid=f'sysuser-{realm.name}',
509-
uid_prefix='user-sys',
510-
is_system=True)
506+
sys_user_info = self.user_op().create(
507+
zone,
508+
zonegroup,
509+
uid=f'sysuser-{realm.name}',
510+
uid_prefix='user-sys',
511+
is_system=True
512+
)
511513
sys_user = RGWUser(sys_user_info)
512514
logging.info(f'Created system user: {sys_user.uid} on'
513-
'{realm.name}/{zonegroup.name}/{zone.name}')
515+
f'{realm.name}/{zonegroup.name}/{zone.name}')
514516
return sys_user
515517
except RGWAMException as e:
518+
if e.retcode == -errno.EEXIST:
519+
# You get this error (EEXIST) when the user already exists. This
520+
# can happen if you delete the zone/zg/realm for the user but not
521+
# the user itself and then try to call "rgw realm bootstrap"
522+
# with the same zone/zg/realm names again. In this case, let's try
523+
# to get the existing user's info
524+
try:
525+
sys_user_info = self.user_op().info(
526+
zone,
527+
zonegroup,
528+
uid=f'sysuser-{realm.name}',
529+
)
530+
sys_user = RGWUser(sys_user_info)
531+
logging.info(f'Found existing system user: sysuser-{realm.name}')
532+
return sys_user
533+
except RGWAMException as e2:
534+
RGWAMException(
535+
f'System user sysuser-{realm.name} already existed. '
536+
'Failed getting info for user', e2
537+
)
516538
raise RGWAMException('failed to create system user', e)
517539

518540
def create_normal_user(self, zg, zone, uid=None):

0 commit comments

Comments
 (0)