Skip to content

Commit 0d56b61

Browse files
authored
Merge pull request ceph#60841 from rhcs-dashboard/fix-69052-main
mgr/dashboard: Automate system user creation and restart of rgw daemons on Migrate to Multisite Reviewed-by: Nizamudeen A <[email protected]> Reviewed-by: Naman Munet <[email protected]>
2 parents abbb91e + fd05431 commit 0d56b61

File tree

5 files changed

+63
-65
lines changed

5 files changed

+63
-65
lines changed

src/pybind/mgr/dashboard/controllers/rgw.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,11 @@ def status(self):
106106
@allow_empty_body
107107
# pylint: disable=W0102,W0613
108108
def migrate(self, daemon_name=None, realm_name=None, zonegroup_name=None, zone_name=None,
109-
zonegroup_endpoints=None, zone_endpoints=None, access_key=None,
110-
secret_key=None):
109+
zonegroup_endpoints=None, zone_endpoints=None, username=None):
111110
multisite_instance = RgwMultisite()
112111
result = multisite_instance.migrate_to_multisite(realm_name, zonegroup_name,
113112
zone_name, zonegroup_endpoints,
114-
zone_endpoints, access_key,
115-
secret_key)
113+
zone_endpoints, username)
116114
return result
117115

118116
@RESTController.Collection(method='POST', path='/multisite-replications')

src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-multisite-migrate/rgw-multisite-migrate.component.html

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -111,36 +111,21 @@
111111
</div>
112112
<div class="form-group row">
113113
<label class="cd-col-form-label required"
114-
for="access_key"
115-
i18n>S3 access key
116-
<cd-helper>
117-
<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>
118-
</cd-helper>
119-
</label>
114+
for="username"
115+
i18n>Username</label>
120116
<div class="cd-col-form-input">
121117
<input class="form-control"
122118
type="text"
123-
placeholder="e.g."
124-
id="access_key"
125-
name="access_key"
126-
formControlName="access_key">
127-
</div>
128-
</div>
129-
<div class="form-group row">
130-
<label class="cd-col-form-label required"
131-
for="access_key"
132-
i18n>S3 secret key
133-
<cd-helper>
134-
<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>
135-
</cd-helper>
136-
</label>
137-
<div class="cd-col-form-input">
138-
<input class="form-control"
139-
type="text"
140-
placeholder="e.g."
141-
id="secret_key"
142-
name="secret_key"
143-
formControlName="secret_key">
119+
placeholder="username"
120+
id="username"
121+
name="username"
122+
formControlName="username">
123+
<cd-help-text>
124+
<span i18n>Specify the username for the system user. This user will be created automatically as part of the process.</span>
125+
</cd-help-text>
126+
<span class="invalid-feedback"
127+
*ngIf="multisiteMigrateForm.showError('username', formDir, 'required')"
128+
i18n>This field is required.</span>
144129
</div>
145130
</div>
146131
</div>

src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-multisite-migrate/rgw-multisite-migrate.component.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { NotificationType } from '~/app/shared/enum/notification-type.enum';
1111
import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
1212
import { CdValidators } from '~/app/shared/forms/cd-validators';
1313
import { NotificationService } from '~/app/shared/services/notification.service';
14-
import { RgwRealm, RgwZone, RgwZonegroup, SystemKey } from '../models/rgw-multisite';
14+
import { RgwRealm, RgwZone, RgwZonegroup } from '../models/rgw-multisite';
1515
import { ModalService } from '~/app/shared/services/modal.service';
1616
import { RgwDaemonService } from '~/app/shared/api/rgw-daemon.service';
1717

@@ -135,8 +135,9 @@ export class RgwMultisiteMigrateComponent implements OnInit {
135135
Validators.required
136136
]
137137
),
138-
access_key: new UntypedFormControl(null),
139-
secret_key: new UntypedFormControl(null)
138+
username: new UntypedFormControl(null, {
139+
validators: [Validators.required]
140+
})
140141
});
141142
}
142143

@@ -174,21 +175,21 @@ export class RgwMultisiteMigrateComponent implements OnInit {
174175
this.zone = new RgwZone();
175176
this.zone.name = values['zoneName'];
176177
this.zone.endpoints = values['zone_endpoints'];
177-
this.zone.system_key = new SystemKey();
178-
this.zone.system_key.access_key = values['access_key'];
179-
this.zone.system_key.secret_key = values['secret_key'];
180-
this.rgwMultisiteService.migrate(this.realm, this.zonegroup, this.zone).subscribe(
181-
() => {
182-
this.notificationService.show(
183-
NotificationType.success,
184-
$localize`Migration done successfully`
185-
);
186-
this.submitAction.emit();
187-
this.activeModal.close();
188-
},
189-
() => {
190-
this.notificationService.show(NotificationType.error, $localize`Migration failed`);
191-
}
192-
);
178+
this.rgwMultisiteService
179+
.migrate(this.realm, this.zonegroup, this.zone, values['username'])
180+
.subscribe(
181+
() => {
182+
this.rgwMultisiteService.setRestartGatewayMessage(false);
183+
this.notificationService.show(
184+
NotificationType.success,
185+
$localize`Migration done successfully`
186+
);
187+
this.submitAction.emit();
188+
this.activeModal.close();
189+
},
190+
() => {
191+
this.notificationService.show(NotificationType.error, $localize`Migration failed`);
192+
}
193+
);
193194
}
194195
}

src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-multisite.service.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@ export class RgwMultisiteService {
1616

1717
constructor(private http: HttpClient, public rgwDaemonService: RgwDaemonService) {}
1818

19-
migrate(realm: RgwRealm, zonegroup: RgwZonegroup, zone: RgwZone) {
19+
migrate(realm: RgwRealm, zonegroup: RgwZonegroup, zone: RgwZone, username: string) {
2020
return this.rgwDaemonService.request((params: HttpParams) => {
2121
params = params.appendAll({
2222
realm_name: realm.name,
2323
zonegroup_name: zonegroup.name,
2424
zone_name: zone.name,
2525
zonegroup_endpoints: zonegroup.endpoints,
2626
zone_endpoints: zone.endpoints,
27-
access_key: zone.system_key.access_key,
28-
secret_key: zone.system_key.secret_key
27+
username: username
2928
});
3029
return this.http.put(`${this.uiUrl}/migrate`, null, { params: params });
3130
});

src/pybind/mgr/dashboard/services/rgw_client.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,8 +1348,7 @@ def check_user_in_second_cluster(self, cluster_url, cluster_token, username,
13481348

13491349
class RgwMultisite:
13501350
def migrate_to_multisite(self, realm_name: str, zonegroup_name: str, zone_name: str,
1351-
zonegroup_endpoints: str, zone_endpoints: str, access_key: str,
1352-
secret_key: str):
1351+
zonegroup_endpoints: str, zone_endpoints: str, username: str):
13531352
rgw_realm_create_cmd = ['realm', 'create', '--rgw-realm', realm_name, '--default']
13541353
try:
13551354
exit_code, _, err = mgr.send_rgwadmin_command(rgw_realm_create_cmd, False)
@@ -1411,18 +1410,34 @@ def migrate_to_multisite(self, realm_name: str, zonegroup_name: str, zone_name:
14111410
http_status_code=500, component='rgw')
14121411
except SubprocessError as error:
14131412
raise DashboardException(error, http_status_code=500, component='rgw')
1413+
self.update_period()
14141414

1415-
if access_key and secret_key:
1416-
rgw_zone_modify_cmd = ['zone', 'modify', '--rgw-zone', zone_name,
1417-
'--access-key', access_key, '--secret', secret_key]
1418-
try:
1419-
exit_code, _, err = mgr.send_rgwadmin_command(rgw_zone_modify_cmd)
1420-
if exit_code > 0:
1421-
raise DashboardException(e=err, msg='Unable to modify zone',
1415+
try:
1416+
user_details = self.create_system_user(username, zone_name)
1417+
if user_details:
1418+
keys = user_details['keys'][0]
1419+
access_key = keys['access_key']
1420+
secret_key = keys['secret_key']
1421+
if access_key and secret_key:
1422+
self.modify_zone(zone_name=zone_name,
1423+
zonegroup_name=zonegroup_name,
1424+
default='true', master='true',
1425+
endpoints=zone_endpoints,
1426+
access_key=keys['access_key'],
1427+
secret_key=keys['secret_key'])
1428+
else:
1429+
raise DashboardException(msg='Access key or secret key is missing',
14221430
http_status_code=500, component='rgw')
1423-
except SubprocessError as error:
1424-
raise DashboardException(error, http_status_code=500, component='rgw')
1425-
self.update_period()
1431+
except Exception as e:
1432+
raise DashboardException(msg='Failed to modify zone or create system user: %s' % e,
1433+
http_status_code=500, component='rgw')
1434+
1435+
try:
1436+
rgw_service_manager = RgwServiceManager()
1437+
rgw_service_manager.restart_rgw_daemons_and_set_credentials()
1438+
except Exception as e:
1439+
raise DashboardException(msg='Failed to restart RGW daemon: %s' % e,
1440+
http_status_code=500, component='rgw')
14261441

14271442
def create_realm(self, realm_name: str, default: bool):
14281443
rgw_realm_create_cmd = ['realm', 'create']

0 commit comments

Comments
 (0)