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>
<!-- 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 <service_type.service_id></cd-helper>
+ </label>
<div class="cd-col-form-input">
<input id="service_id"
class="form-control"
<span class="invalid-feedback"
*ngIf="serviceForm.showError('service_id', frm, 'rgwPattern')"
i18n>The value does not match the pattern <strong><service_id>[.<realm_name>.<zone_name>]</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>
});
});
+ 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;
})
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 })
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'
}),