From e3d57fddcec7ce06c9205192c7e9bbbb5601c8ba Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alfonso=20Mart=C3=ADnez?= Date: Mon, 9 Aug 2021 12:12:52 +0200 Subject: [PATCH] mgr/dashboard: rgw service creation form: add realm and zone to service spec. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Align rgw service id pattern with cephadm: https://github.com/ceph/ceph/pull/39877 - Update rgw pattern to allow service id for non-multisite config. - Extract realm and zone from service id (when detected) and add them to the service spec. Fixes: https://tracker.ceph.com/issues/44605 Signed-off-by: Alfonso Martínez (cherry picked from commit 0575844192502ded32962b75a91cf51de22e97e6) --- .../service-form/service-form.component.html | 2 +- .../service-form.component.spec.ts | 42 ++++++++++++++----- .../service-form/service-form.component.ts | 16 ++++++- 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html index 965d2105058f..e24a734451b7 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html @@ -77,7 +77,7 @@ i18n>This field is required. The value does not match the pattern <realm_name>.<zone_name>[.<subcluster>]. + i18n>The value does not match the pattern <service_id>[.<realm_name>.<zone_name>]. diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts index 1f9679dca587..11c0663efd24 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts @@ -100,14 +100,15 @@ describe('ServiceFormComponent', () => { }); it('should test unmanaged', () => { - formHelper.setValue('service_type', 'rgw'); + formHelper.setValue('service_type', 'mgr'); + formHelper.setValue('service_id', 'svc'); formHelper.setValue('placement', 'label'); formHelper.setValue('label', 'bar'); - formHelper.setValue('rgw_frontend_port', 4567); formHelper.setValue('unmanaged', true); component.onSubmit(); expect(cephServiceService.create).toHaveBeenCalledWith({ - service_type: 'rgw', + service_type: 'mgr', + service_id: 'svc', placement: {}, unmanaged: true }); @@ -170,32 +171,52 @@ describe('ServiceFormComponent', () => { describe('should test service rgw', () => { beforeEach(() => { formHelper.setValue('service_type', 'rgw'); + formHelper.setValue('service_id', 'svc'); }); it('should test rgw valid service id', () => { - formHelper.setValue('service_id', 'foo.bar'); + formHelper.setValue('service_id', 'svc.realm.zone'); formHelper.expectValid('service_id'); - formHelper.setValue('service_id', 'foo.bar.bas'); + formHelper.setValue('service_id', 'svc'); formHelper.expectValid('service_id'); }); it('should test rgw invalid service id', () => { - formHelper.setValue('service_id', 'foo'); + formHelper.setValue('service_id', '.'); + formHelper.expectError('service_id', 'rgwPattern'); + formHelper.setValue('service_id', 'svc.'); + formHelper.expectError('service_id', 'rgwPattern'); + formHelper.setValue('service_id', 'svc.realm'); formHelper.expectError('service_id', 'rgwPattern'); - formHelper.setValue('service_id', 'foo.'); + formHelper.setValue('service_id', 'svc.realm.'); formHelper.expectError('service_id', 'rgwPattern'); - formHelper.setValue('service_id', 'foo.bar.'); + formHelper.setValue('service_id', '.svc.realm'); formHelper.expectError('service_id', 'rgwPattern'); - formHelper.setValue('service_id', 'foo.bar.bas.'); + formHelper.setValue('service_id', 'svc.realm.zone.'); formHelper.expectError('service_id', 'rgwPattern'); }); - it('should submit rgw with port', () => { + it('should submit rgw with realm and zone', () => { + formHelper.setValue('service_id', 'svc.my-realm.my-zone'); + component.onSubmit(); + expect(cephServiceService.create).toHaveBeenCalledWith({ + service_type: 'rgw', + service_id: 'svc', + rgw_realm: 'my-realm', + rgw_zone: 'my-zone', + placement: {}, + unmanaged: false, + ssl: false + }); + }); + + it('should submit rgw with port and ssl enabled', () => { formHelper.setValue('rgw_frontend_port', 1234); formHelper.setValue('ssl', true); component.onSubmit(); expect(cephServiceService.create).toHaveBeenCalledWith({ service_type: 'rgw', + service_id: 'svc', placement: {}, unmanaged: false, rgw_frontend_port: 1234, @@ -239,6 +260,7 @@ describe('ServiceFormComponent', () => { component.onSubmit(); expect(cephServiceService.create).toHaveBeenCalledWith({ service_type: 'rgw', + service_id: 'svc', placement: {}, unmanaged: false, ssl: false diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.ts index df231c7efdb2..cb80a2571c0a 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.ts @@ -27,6 +27,7 @@ import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service'; styleUrls: ['./service-form.component.scss'] }) export class ServiceFormComponent extends CdForm implements OnInit { + readonly RGW_SVC_ID_PATTERN = /^([^.]+)(\.([^.]+)\.([^.]+))?$/; @ViewChild(NgbTypeahead, { static: false }) typeahead: NgbTypeahead; @@ -91,7 +92,7 @@ export class ServiceFormComponent extends CdForm implements OnInit { if (_.isEmpty(value)) { return false; } - return !/^[^.]+\.[^.]+(\.[^.]+)?$/.test(value); + return !this.RGW_SVC_ID_PATTERN.test(value); }) ] ) @@ -283,13 +284,24 @@ export class ServiceFormComponent extends CdForm implements OnInit { onSubmit() { const self = this; const values: object = this.serviceForm.value; - const serviceId: string = values['service_id']; const serviceType: string = values['service_type']; const serviceSpec: object = { service_type: serviceType, placement: {}, unmanaged: values['unmanaged'] }; + let svcId: string; + if (serviceType === 'rgw') { + const svcIdMatch = values['service_id'].match(this.RGW_SVC_ID_PATTERN); + svcId = svcIdMatch[1]; + if (svcIdMatch[3]) { + serviceSpec['rgw_realm'] = svcIdMatch[3]; + serviceSpec['rgw_zone'] = svcIdMatch[4]; + } + } else { + svcId = values['service_id']; + } + const serviceId: string = svcId; let serviceName: string = serviceType; if (_.isString(serviceId) && !_.isEmpty(serviceId)) { serviceName = `${serviceType}.${serviceId}`; -- 2.47.3