]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/rgw: don't fail realm bootstrap if system user exists already 62808/head
authorAdam King <adking@redhat.com>
Mon, 14 Apr 2025 21:00:11 +0000 (17:00 -0400)
committerAdam King <adking@redhat.com>
Mon, 5 May 2025 17:33:58 +0000 (13:33 -0400)
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 <adking@redhat.com>
src/python-common/ceph/rgw/rgwam_core.py

index 2f8f1e9208703bf4870f6d4589c15152f9e7d1c8..bbfb85af27a70c929fb7b643c1e25f1266b9a265 100644 (file)
@@ -503,16 +503,38 @@ class RGWAM:
 
     def create_system_user(self, realm, zonegroup, zone):
         try:
-            sys_user_info = self.user_op().create(zone,
-                                                  zonegroup,
-                                                  uid=f'sysuser-{realm.name}',
-                                                  uid_prefix='user-sys',
-                                                  is_system=True)
+            sys_user_info = self.user_op().create(
+                zone,
+                zonegroup,
+                uid=f'sysuser-{realm.name}',
+                uid_prefix='user-sys',
+                is_system=True
+            )
             sys_user = RGWUser(sys_user_info)
             logging.info(f'Created system user: {sys_user.uid} on'
-                         '{realm.name}/{zonegroup.name}/{zone.name}')
+                         f'{realm.name}/{zonegroup.name}/{zone.name}')
             return sys_user
         except RGWAMException as e:
+            if e.retcode == -errno.EEXIST:
+                # You get this error (EEXIST) when the user already exists. This
+                # can happen if you delete the zone/zg/realm for the user but not
+                # the user itself and then try to call "rgw realm bootstrap"
+                # with the same zone/zg/realm names again. In this case, let's try
+                # to get the existing user's info
+                try:
+                    sys_user_info = self.user_op().info(
+                        zone,
+                        zonegroup,
+                        uid=f'sysuser-{realm.name}',
+                    )
+                    sys_user = RGWUser(sys_user_info)
+                    logging.info(f'Found existing system user: sysuser-{realm.name}')
+                    return sys_user
+                except RGWAMException as e2:
+                    RGWAMException(
+                        f'System user sysuser-{realm.name} already existed. '
+                        'Failed getting info for user', e2
+                    )
             raise RGWAMException('failed to create system user', e)
 
     def create_normal_user(self, zg, zone, uid=None):