Skip to content

Commit 42c07e9

Browse files
committed
mgr/rgw: don't fail realm bootstrap if system user exists already
If you create a realm/zonegroup/zone and a system user for the zone, delete the realm/zonegroup/zone, and then recreate them, attempting to recreate the system user failes with EEXIST. Instead of having the realm bootstrap fail in these scenarios, we can go grab the info we need from the existing user. Fixes: https://tracker.ceph.com/issues/70914 Signed-off-by: Adam King <[email protected]>
1 parent 61e2b24 commit 42c07e9

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

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)