]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: validate mds service_id and helper text for service_id 47179/head
authorMelissa Li <melissali@redhat.com>
Tue, 19 Jul 2022 21:05:14 +0000 (17:05 -0400)
committerMelissa Li <melissali@redhat.com>
Wed, 27 Jul 2022 16:28:04 +0000 (12:28 -0400)
Validate mds service_id to avoid mds daemon from being created and going into error state due to invalid id.
Also add helper text to describe the role of service_id.

Fixes: https://tracker.ceph.com/issues/56077
Signed-off-by: Melissa Li <melissali@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 a3e19ee3112c3d28a3ec630ada446adca026d0a7..658932c5273485083a1eddce839bd89168d0e498 100644 (file)
         <!-- Service id -->
         <div class="form-group row"
              *ngIf="serviceForm.controls.service_type.value !== 'snmp-gateway'">
-          <label i18n
-                 class="cd-col-form-label"
+          <label class="cd-col-form-label"
                  [ngClass]="{'required': ['mds', 'rgw', 'nfs', 'iscsi', 'ingress'].includes(serviceForm.controls.service_type.value)}"
-                 for="service_id">Id</label>
+                 for="service_id">
+            <span i18n>Id</span>
+            <cd-helper i18n>Used in the service name which is &lt;service_type.service_id&gt;</cd-helper>
+          </label>
           <div class="cd-col-form-input">
             <input id="service_id"
                    class="form-control"
@@ -80,6 +82,9 @@
             <span class="invalid-feedback"
                   *ngIf="serviceForm.showError('service_id', frm, 'rgwPattern')"
                   i18n>The value does not match the pattern <strong>&lt;service_id&gt;[.&lt;realm_name&gt;.&lt;zone_name&gt;]</strong>.</span>
+            <span class="invalid-feedback"
+                  *ngIf="serviceForm.showError('service_id', frm, 'mdsPattern')"
+                  i18n>MDS service id must start with a letter and contain alphanumeric characters or '.', '-', and '_'</span>
           </div>
         </div>
 
index 082fe9162b154dbd71a598402814007cc5994584..b0574c6efb09c2034ea933a6fbb49b880152856f 100644 (file)
@@ -530,6 +530,28 @@ x4Ea7kGVgx9kWh5XjWz9wjZvY49UKIT5ppIAWPMbLl3UpfckiuNhTA==
       });
     });
 
+    describe('should test service mds', () => {
+      beforeEach(() => {
+        formHelper.setValue('service_type', 'mds');
+      });
+
+      it('should test mds valid service id', () => {
+        formHelper.setValue('service_id', 'svc123');
+        formHelper.expectValid('service_id');
+        formHelper.setValue('service_id', 'svc_id-1');
+        formHelper.expectValid('service_id');
+      });
+
+      it('should test mds invalid service id', () => {
+        formHelper.setValue('service_id', '123');
+        formHelper.expectError('service_id', 'mdsPattern');
+        formHelper.setValue('service_id', '123svc');
+        formHelper.expectError('service_id', 'mdsPattern');
+        formHelper.setValue('service_id', 'svc#1');
+        formHelper.expectError('service_id', 'mdsPattern');
+      });
+    });
+
     describe('check edit fields', () => {
       beforeEach(() => {
         component.editing = true;
index 4d964575eec1811aa0ad9a574c0448eec95aad0a..4c400a01861ca8fa8c363824f9a8fa529d65c1a4 100644 (file)
@@ -28,6 +28,7 @@ import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
 })
 export class ServiceFormComponent extends CdForm implements OnInit {
   readonly RGW_SVC_ID_PATTERN = /^([^.]+)(\.([^.]+)\.([^.]+))?$/;
+  readonly MDS_SVC_ID_PATTERN = /^[a-zA-Z_.-][a-zA-Z0-9_.-]*$/;
   readonly SNMP_DESTINATION_PATTERN = /^[^\:]+:[0-9]/;
   readonly SNMP_ENGINE_ID_PATTERN = /^[0-9A-Fa-f]{10,64}/g;
   @ViewChild(NgbTypeahead, { static: false })
@@ -83,9 +84,20 @@ export class ServiceFormComponent extends CdForm implements OnInit {
       service_id: [
         null,
         [
-          CdValidators.requiredIf({
-            service_type: 'mds'
-          }),
+          CdValidators.composeIf(
+            {
+              service_type: 'mds'
+            },
+            [
+              Validators.required,
+              CdValidators.custom('mdsPattern', (value: string) => {
+                if (_.isEmpty(value)) {
+                  return false;
+                }
+                return !this.MDS_SVC_ID_PATTERN.test(value);
+              })
+            ]
+          ),
           CdValidators.requiredIf({
             service_type: 'nfs'
           }),