]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: rgw service creation form: add realm and zone to service spec.
authorAlfonso Martínez <almartin@redhat.com>
Mon, 9 Aug 2021 10:12:52 +0000 (12:12 +0200)
committerAlfonso Martínez <almartin@redhat.com>
Tue, 10 Aug 2021 12:06:03 +0000 (14:06 +0200)
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 <almartin@redhat.com>
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.ts

index 965d2105058f52ceffcbadf8b75a2d926d3fcc39..e24a734451b7e0958b336e0a945bca5cac2d6cce 100644 (file)
@@ -77,7 +77,7 @@
                   i18n>This field is required.</span>
             <span class="invalid-feedback"
                   *ngIf="serviceForm.showError('service_id', frm, 'rgwPattern')"
-                  i18n>The value does not match the pattern <strong>&lt;realm_name&gt;.&lt;zone_name&gt;[.&lt;subcluster&gt;]</strong>.</span>
+                  i18n>The value does not match the pattern <strong>&lt;service_id&gt;[.&lt;realm_name&gt;.&lt;zone_name&gt;]</strong>.</span>
           </div>
         </div>
 
index 1f9679dca58748b0dfe4152e42f765f5ade33a53..11c0663efd246fa85685ac7482d8b06a62735dd8 100644 (file)
@@ -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
index df231c7efdb25d732c04a320578b18097f0e2ad1..cb80a2571c0ae73a2a474b555d0f2bdf54aa339c 100644 (file)
@@ -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}`;