From: Melissa Li Date: Tue, 19 Jul 2022 21:05:14 +0000 (-0400) Subject: mgr/dashboard: validate mds service_id and helper text for service_id X-Git-Tag: v18.0.0~304^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1d6cb2882d5b9c2a058631a2c189706bcdc73e68;p=ceph.git mgr/dashboard: validate mds service_id and helper text for service_id 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 --- 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 a3e19ee3112c..658932c52734 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 @@ -65,10 +65,12 @@
- + for="service_id"> + Id + Used in the service name which is <service_type.service_id> +
The value does not match the pattern <service_id>[.<realm_name>.<zone_name>]. + MDS service id must start with a letter and contain alphanumeric characters or '.', '-', and '_'
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 082fe9162b15..b0574c6efb09 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 @@ -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; 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 4d964575eec1..4c400a01861c 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 @@ -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' }),