]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: Automate system user creation and restart of rgw daemons on Migrate...
authorAashish Sharma <aasharma@li-e74156cc-2f67-11b2-a85c-e98659a63c5c.ibm.com>
Tue, 26 Nov 2024 06:21:24 +0000 (11:51 +0530)
committerAashish Sharma <aasharma@li-e74156cc-2f67-11b2-a85c-e98659a63c5c.ibm.com>
Tue, 26 Nov 2024 12:54:29 +0000 (18:24 +0530)
1. Automate the process of replication user creation during single site to multi-site migration
2. Provide a support for automatic restart post creation of default realm/zone group/zone as a part of multisite migrate

Fixes: https://tracker.ceph.com/issues/69052
Signed-off-by: Aashish Sharma <aasharma@redhat.com>
src/pybind/mgr/dashboard/controllers/rgw.py
src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-multisite-migrate/rgw-multisite-migrate.component.html
src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-multisite-migrate/rgw-multisite-migrate.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-multisite.service.ts
src/pybind/mgr/dashboard/services/rgw_client.py

index 9d2576747947395b5102a0dea69ee89c53a3a5f7..6fd687084fe98eddb0b5bc7562be2976268c8e5e 100755 (executable)
@@ -106,13 +106,11 @@ class RgwMultisiteStatus(RESTController):
     @allow_empty_body
     # pylint: disable=W0102,W0613
     def migrate(self, daemon_name=None, realm_name=None, zonegroup_name=None, zone_name=None,
-                zonegroup_endpoints=None, zone_endpoints=None, access_key=None,
-                secret_key=None):
+                zonegroup_endpoints=None, zone_endpoints=None, username=None):
         multisite_instance = RgwMultisite()
         result = multisite_instance.migrate_to_multisite(realm_name, zonegroup_name,
                                                          zone_name, zonegroup_endpoints,
-                                                         zone_endpoints, access_key,
-                                                         secret_key)
+                                                         zone_endpoints, username)
         return result
 
     @RESTController.Collection(method='POST', path='/multisite-replications')
index 51f72dd7f8977d8b6346a2eaa0e03e37765d5667..9117e71c34b71d727d62d91d04a29cdacfad0efd 100644 (file)
       </div>
       <div class="form-group row">
         <label class="cd-col-form-label required"
-               for="access_key"
-               i18n>S3 access key
-          <cd-helper>
-            <span>To see or copy your S3 access key, go to <b>Object Gateway > Users</b> and click on your user name. In <b>Keys</b>, click <b>Show</b>. View the access key by clicking Show and copy the key by clicking <b>Copy to Clipboard</b>.</span>
-          </cd-helper>
-        </label>
+               for="username"
+               i18n>Username</label>
         <div class="cd-col-form-input">
           <input class="form-control"
                  type="text"
-                 placeholder="e.g."
-                 id="access_key"
-                 name="access_key"
-                 formControlName="access_key">
-        </div>
-      </div>
-      <div class="form-group row">
-        <label class="cd-col-form-label required"
-               for="access_key"
-               i18n>S3 secret key
-          <cd-helper>
-            <span>To see or copy your S3 access key, go to <b>Object Gateway > Users</b> and click on your user name. In <b>Keys</b>, click <b>Show</b>. View the secret key by clicking Show and copy the key by clicking <b>Copy to Clipboard</b>.</span>
-          </cd-helper>
-        </label>
-        <div class="cd-col-form-input">
-          <input class="form-control"
-                 type="text"
-                 placeholder="e.g."
-                 id="secret_key"
-                 name="secret_key"
-                 formControlName="secret_key">
+                 placeholder="username"
+                 id="username"
+                 name="username"
+                 formControlName="username">
+          <cd-help-text>
+            <span i18n>Specify the username for the system user. This user will be created automatically as part of the process.</span>
+          </cd-help-text>
+          <span class="invalid-feedback"
+                *ngIf="multisiteMigrateForm.showError('username', formDir, 'required')"
+                i18n>This field is required.</span>
         </div>
       </div>
     </div>
index 1073dee429a5f1962de2fdb007e01b748a670dbe..d9ad56a5bf4da977eb538cf3ce96b71ddbf539ff 100644 (file)
@@ -11,7 +11,7 @@ import { NotificationType } from '~/app/shared/enum/notification-type.enum';
 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
 import { CdValidators } from '~/app/shared/forms/cd-validators';
 import { NotificationService } from '~/app/shared/services/notification.service';
-import { RgwRealm, RgwZone, RgwZonegroup, SystemKey } from '../models/rgw-multisite';
+import { RgwRealm, RgwZone, RgwZonegroup } from '../models/rgw-multisite';
 import { ModalService } from '~/app/shared/services/modal.service';
 import { RgwDaemonService } from '~/app/shared/api/rgw-daemon.service';
 
@@ -135,8 +135,9 @@ export class RgwMultisiteMigrateComponent implements OnInit {
           Validators.required
         ]
       ),
-      access_key: new UntypedFormControl(null),
-      secret_key: new UntypedFormControl(null)
+      username: new UntypedFormControl(null, {
+        validators: [Validators.required]
+      })
     });
   }
 
@@ -174,21 +175,21 @@ export class RgwMultisiteMigrateComponent implements OnInit {
     this.zone = new RgwZone();
     this.zone.name = values['zoneName'];
     this.zone.endpoints = values['zone_endpoints'];
-    this.zone.system_key = new SystemKey();
-    this.zone.system_key.access_key = values['access_key'];
-    this.zone.system_key.secret_key = values['secret_key'];
-    this.rgwMultisiteService.migrate(this.realm, this.zonegroup, this.zone).subscribe(
-      () => {
-        this.notificationService.show(
-          NotificationType.success,
-          $localize`Migration done successfully`
-        );
-        this.submitAction.emit();
-        this.activeModal.close();
-      },
-      () => {
-        this.notificationService.show(NotificationType.error, $localize`Migration failed`);
-      }
-    );
+    this.rgwMultisiteService
+      .migrate(this.realm, this.zonegroup, this.zone, values['username'])
+      .subscribe(
+        () => {
+          this.rgwMultisiteService.setRestartGatewayMessage(false);
+          this.notificationService.show(
+            NotificationType.success,
+            $localize`Migration done successfully`
+          );
+          this.submitAction.emit();
+          this.activeModal.close();
+        },
+        () => {
+          this.notificationService.show(NotificationType.error, $localize`Migration failed`);
+        }
+      );
   }
 }
index 3dc886e172fc4c8e35dc532cd34878475500cc86..8a39dc8a284fa2fa85853e756042ad3b648a5031 100644 (file)
@@ -16,7 +16,7 @@ export class RgwMultisiteService {
 
   constructor(private http: HttpClient, public rgwDaemonService: RgwDaemonService) {}
 
-  migrate(realm: RgwRealm, zonegroup: RgwZonegroup, zone: RgwZone) {
+  migrate(realm: RgwRealm, zonegroup: RgwZonegroup, zone: RgwZone, username: string) {
     return this.rgwDaemonService.request((params: HttpParams) => {
       params = params.appendAll({
         realm_name: realm.name,
@@ -24,8 +24,7 @@ export class RgwMultisiteService {
         zone_name: zone.name,
         zonegroup_endpoints: zonegroup.endpoints,
         zone_endpoints: zone.endpoints,
-        access_key: zone.system_key.access_key,
-        secret_key: zone.system_key.secret_key
+        username: username
       });
       return this.http.put(`${this.uiUrl}/migrate`, null, { params: params });
     });
index 2fe098216942dad0fa43b5d73dfe7497718d45b0..9fa249acf444e030004ce2bdc4a1e0f52d7cb93c 100755 (executable)
@@ -1348,8 +1348,7 @@ class RgwMultisiteAutomation:
 
 class RgwMultisite:
     def migrate_to_multisite(self, realm_name: str, zonegroup_name: str, zone_name: str,
-                             zonegroup_endpoints: str, zone_endpoints: str, access_key: str,
-                             secret_key: str):
+                             zonegroup_endpoints: str, zone_endpoints: str, username: str):
         rgw_realm_create_cmd = ['realm', 'create', '--rgw-realm', realm_name, '--default']
         try:
             exit_code, _, err = mgr.send_rgwadmin_command(rgw_realm_create_cmd, False)
@@ -1411,18 +1410,34 @@ class RgwMultisite:
                                          http_status_code=500, component='rgw')
         except SubprocessError as error:
             raise DashboardException(error, http_status_code=500, component='rgw')
+        self.update_period()
 
-        if access_key and secret_key:
-            rgw_zone_modify_cmd = ['zone', 'modify', '--rgw-zone', zone_name,
-                                   '--access-key', access_key, '--secret', secret_key]
-            try:
-                exit_code, _, err = mgr.send_rgwadmin_command(rgw_zone_modify_cmd)
-                if exit_code > 0:
-                    raise DashboardException(e=err, msg='Unable to modify zone',
+        try:
+            user_details = self.create_system_user(username, zone_name)
+            if user_details:
+                keys = user_details['keys'][0]
+                access_key = keys['access_key']
+                secret_key = keys['secret_key']
+                if access_key and secret_key:
+                    self.modify_zone(zone_name=zone_name,
+                                     zonegroup_name=zonegroup_name,
+                                     default='true', master='true',
+                                     endpoints=zone_endpoints,
+                                     access_key=keys['access_key'],
+                                     secret_key=keys['secret_key'])
+                else:
+                    raise DashboardException(msg='Access key or secret key is missing',
                                              http_status_code=500, component='rgw')
-            except SubprocessError as error:
-                raise DashboardException(error, http_status_code=500, component='rgw')
-        self.update_period()
+        except Exception as e:
+            raise DashboardException(msg='Failed to modify zone or create system user: %s' % e,
+                                     http_status_code=500, component='rgw')
+
+        try:
+            rgw_service_manager = RgwServiceManager()
+            rgw_service_manager.restart_rgw_daemons_and_set_credentials()
+        except Exception as e:
+            raise DashboardException(msg='Failed to restart RGW daemon: %s' % e,
+                                     http_status_code=500, component='rgw')
 
     def create_realm(self, realm_name: str, default: bool):
         rgw_realm_create_cmd = ['realm', 'create']