]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: add validators to osdRecvSpeedForm 25472/head
authorTatjana Dehler <tdehler@suse.com>
Mon, 17 Dec 2018 11:26:24 +0000 (12:26 +0100)
committerTatjana Dehler <tdehler@suse.com>
Wed, 23 Jan 2019 11:45:34 +0000 (12:45 +0100)
Fixes: https://tracker.ceph.com/issues/37436
Signed-off-by: Tatjana Dehler <tdehler@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-recv-speed-modal/osd-recv-speed-modal.component.html
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-recv-speed-modal/osd-recv-speed-modal.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-recv-speed-modal/osd-recv-speed-modal.component.ts
src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf

index 884a1c56daef114911ea4309307ac37c8a3cb5e8..4429882b78cc71911e42eb292ab21988471099d8 100755 (executable)
                   *ngIf="osdRecvSpeedForm.getValue('customizePriority') &&
                   osdRecvSpeedForm.showError(attr.key, formDir, 'required')"
                   i18n>This field is required!</span>
+            <span class="help-block"
+                  *ngIf="osdRecvSpeedForm.getValue('customizePriority') &&
+                  osdRecvSpeedForm.showError(attr.key, formDir, 'pattern')"
+                  i18n>{{ attr.value.patternHelpText }}</span>
+            <span class="help-block"
+                  *ngIf="osdRecvSpeedForm.getValue('customizePriority') &&
+                  osdRecvSpeedForm.showError(attr.key, formDir, 'max')"
+                  i18n>The entered value is too high! It must not be greater than {{ attr.value.maxValue }}.</span>
+            <span class="help-block"
+                  *ngIf="osdRecvSpeedForm.getValue('customizePriority') &&
+                  osdRecvSpeedForm.showError(attr.key, formDir, 'min')"
+                  i18n>The entered value is too low! It must not be lower than {{ attr.value.minValue }}.</span>
           </div>
         </div>
       </div>
index 7c679091a8715681800eacc71ddee0aa71133f86..bee7768fd78f7f1438e4ee38207ac61197bc5d56 100755 (executable)
@@ -194,4 +194,55 @@ describe('OsdRecvSpeedModalComponent', () => {
       });
     });
   });
+
+  describe('setValidators', () => {
+    const configOptions = [
+      {
+        name: 'osd_max_backfills',
+        type: 'uint'
+      },
+      {
+        name: 'osd_recovery_max_active',
+        type: 'uint'
+      },
+      {
+        name: 'osd_recovery_max_single_start',
+        type: 'uint'
+      },
+      {
+        name: 'osd_recovery_sleep',
+        type: 'float'
+      }
+    ];
+
+    it('should set needed validators for config option', () => {
+      component.setValidators(configOptions);
+      configOptions.forEach((configOption) => {
+        const control = component.osdRecvSpeedForm.controls[configOption.name];
+
+        if (configOption.type === 'float') {
+          expect(component.priorityAttrs[configOption.name].patternHelpText).toBe(
+            'The entered value needs to be a number or decimal.'
+          );
+        } else {
+          expect(component.priorityAttrs[configOption.name].minValue).toBe(0);
+          expect(component.priorityAttrs[configOption.name].patternHelpText).toBe(
+            'The entered value needs to be an unsigned number.'
+          );
+
+          control.setValue(-1);
+          expect(control.hasError('min')).toBeTruthy();
+        }
+
+        control.setValue(null);
+        expect(control.hasError('required')).toBeTruthy();
+        control.setValue('E');
+        expect(control.hasError('pattern')).toBeTruthy();
+        control.setValue(3);
+        expect(control.hasError('required')).toBeFalsy();
+        expect(control.hasError('min')).toBeFalsy();
+        expect(control.hasError('pattern')).toBeFalsy();
+      });
+    });
+  });
 });
index 860ad1bcf331d38fc5da4856a075ef9fff529e41..12dc31a0dcc88c1a3cd7f00becd799cd7698bbef 100755 (executable)
@@ -12,6 +12,7 @@ import { OsdService } from '../../../../shared/api/osd.service';
 import { NotificationType } from '../../../../shared/enum/notification-type.enum';
 import { CdFormGroup } from '../../../../shared/forms/cd-form-group';
 import { NotificationService } from '../../../../shared/services/notification.service';
+import { ConfigOptionTypes } from '../../configuration/configuration-form/configuration-form.types';
 
 @Component({
   selector: 'cd-osd-recv-speed-modal',
@@ -38,19 +39,31 @@ export class OsdRecvSpeedModalComponent implements OnInit {
     this.priorityAttrs = {
       osd_max_backfills: {
         text: this.i18n('Max Backfills'),
-        desc: ''
+        desc: '',
+        patternHelpText: '',
+        maxValue: undefined,
+        minValue: undefined
       },
       osd_recovery_max_active: {
         text: this.i18n('Recovery Max Active'),
-        desc: ''
+        desc: '',
+        patternHelpText: '',
+        maxValue: undefined,
+        minValue: undefined
       },
       osd_recovery_max_single_start: {
         text: this.i18n('Recovery Max Single Start'),
-        desc: ''
+        desc: '',
+        patternHelpText: '',
+        maxValue: undefined,
+        minValue: undefined
       },
       osd_recovery_sleep: {
         text: this.i18n('Recovery Sleep'),
-        desc: ''
+        desc: '',
+        patternHelpText: '',
+        maxValue: undefined,
+        minValue: undefined
       }
     };
 
@@ -91,6 +104,7 @@ export class OsdRecvSpeedModalComponent implements OnInit {
           this.setPriority(priority);
         });
         this.setDescription(resp.configOptions);
+        this.setValidators(resp.configOptions);
       });
   }
 
@@ -144,6 +158,28 @@ export class OsdRecvSpeedModalComponent implements OnInit {
     });
   }
 
+  setValidators(configOptions: Array<any>) {
+    configOptions.forEach((configOption) => {
+      const typeValidators = ConfigOptionTypes.getTypeValidators(configOption);
+      if (typeValidators) {
+        typeValidators.validators.push(Validators.required);
+
+        if ('max' in typeValidators && typeValidators.max !== '') {
+          this.priorityAttrs[configOption.name].maxValue = typeValidators.max;
+        }
+
+        if ('min' in typeValidators && typeValidators.min !== '') {
+          this.priorityAttrs[configOption.name].minValue = typeValidators.min;
+        }
+
+        this.priorityAttrs[configOption.name].patternHelpText = typeValidators.patternHelpText;
+        this.osdRecvSpeedForm.controls[configOption.name].setValidators(typeValidators.validators);
+      } else {
+        this.osdRecvSpeedForm.controls[configOption.name].setValidators(Validators.required);
+      }
+    });
+  }
+
   onCustomizePriorityChange() {
     if (this.osdRecvSpeedForm.getValue('customizePriority')) {
       const values = {};
@@ -169,6 +205,9 @@ export class OsdRecvSpeedModalComponent implements OnInit {
       _.find(this.priorities, (p) => {
         return p.name === selectedPriorityName;
       }) || this.priorities[0];
+    // Uncheck the 'Customize priority values' checkbox.
+    this.osdRecvSpeedForm.get('customizePriority').setValue(false);
+    // Set the priority profile values.
     this.setPriority(selectedPriority);
   }
 
index 8c73162c6732df58a0adb280c36b21a8c65f0bef..d7a8c9179d4975d1014a9af71b1da5b6fe4306a9 100644 (file)
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/cluster/osd/osd-recv-speed-modal/osd-recv-speed-modal.component.html</context>
-          <context context-type="linenumber">79</context>
+          <context context-type="linenumber">91</context>
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/cluster/osd/osd-reweight-modal/osd-reweight-modal.component.html</context>
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/cluster/osd/osd-recv-speed-modal/osd-recv-speed-modal.component.html</context>
-          <context context-type="linenumber">75</context>
+          <context context-type="linenumber">87</context>
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/cluster/osd/osd-scrub-modal/osd-scrub-modal.component.html</context>
           <context context-type="sourcefile">app/ceph/pool/pool-form/pool-form.component.html</context>
           <context context-type="linenumber">95</context>
         </context-group>
+      </trans-unit><trans-unit id="b699e94bf376491bd50b70a98531071c737eaf40" datatype="html">
+        <source><x id="INTERPOLATION" equiv-text="{{ attr.value.patternHelpText }}"/></source>
+        <context-group purpose="location">
+          <context context-type="sourcefile">app/ceph/cluster/osd/osd-recv-speed-modal/osd-recv-speed-modal.component.html</context>
+          <context context-type="linenumber">71</context>
+        </context-group>
+      </trans-unit><trans-unit id="98fe13e7ad6c2b80375d204b47858ded83f80e15" datatype="html">
+        <source>The entered value is too high! It must not be greater than <x id="INTERPOLATION" equiv-text="{{ attr.value.maxValue }}"/>.</source>
+        <context-group purpose="location">
+          <context context-type="sourcefile">app/ceph/cluster/osd/osd-recv-speed-modal/osd-recv-speed-modal.component.html</context>
+          <context context-type="linenumber">75</context>
+        </context-group>
+      </trans-unit><trans-unit id="5423a3c111be47fc5a1bfe46ceb58c81c84db691" datatype="html">
+        <source>The entered value is too low! It must not be lower than <x id="INTERPOLATION" equiv-text="{{ attr.value.minValue }}"/>.</source>
+        <context-group purpose="location">
+          <context context-type="sourcefile">app/ceph/cluster/osd/osd-recv-speed-modal/osd-recv-speed-modal.component.html</context>
+          <context context-type="linenumber">79</context>
+        </context-group>
       </trans-unit><trans-unit id="272696ff8acdbed0af6dc13f09729e70be435b82" datatype="html">
         <source>Reweight OSD</source>
         <context-group purpose="location">