]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: Preserve rule selection on pool type change
authorStephan Müller <smueller@suse.com>
Tue, 3 Mar 2020 14:39:32 +0000 (15:39 +0100)
committerStephan Müller <smueller@suse.com>
Mon, 9 Mar 2020 11:35:58 +0000 (12:35 +0100)
Now if the pool type is changed from replicated to erasure in the pool
form and you have multiple rules, your selection is preserved and not
overwritten by null, which caused an error message to be shown
(crush rule is required).

Fixes: https://tracker.ceph.com/issues/44371
Signed-off-by: Stephan Müller <smueller@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/ceph/pool/pool-form/pool-form.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/pool/pool-form/pool-form.component.ts

index 5ff1418c94cbe1f5e7ca6209640ace0ed9a15346..d4f8fc16e4d888e6199b1f9a7d6dbef504063afd 100644 (file)
@@ -500,9 +500,13 @@ describe('PoolFormComponent', () => {
       });
 
       it('disables rule field if only one rule exists which is used in the disabled field', () => {
-        formHelper.setValue('poolType', 'erasure');
+        infoReturn.crush_rules_replicated = [
+          createCrushRule({ id: 0, min: 2, max: 4, name: 'rep1', type: 'replicated' })
+        ];
+        setUpPoolComponent();
+        formHelper.setValue('poolType', 'replicated');
         const control = form.get('crushRule');
-        expect(control.value).toEqual(component.info.crush_rules_erasure[0]);
+        expect(control.value).toEqual(component.info.crush_rules_replicated[0]);
         expect(control.disabled).toBe(true);
       });
 
@@ -513,15 +517,14 @@ describe('PoolFormComponent', () => {
         expect(control.disabled).toBe(false);
       });
 
-      it('changing between both types will not leave crushRule in a bad state', () => {
-        formHelper.setValue('poolType', 'erasure');
+      it('changing between both pool types will not forget the crush rule selection', () => {
         formHelper.setValue('poolType', 'replicated');
         const control = form.get('crushRule');
-        expect(control.value).toEqual(null);
-        expect(control.disabled).toBe(false);
+        const currentRule = component.info.crush_rules_replicated[0];
+        control.setValue(currentRule);
         formHelper.setValue('poolType', 'erasure');
-        expect(control.value).toEqual(component.info.crush_rules_erasure[0]);
-        expect(control.disabled).toBe(true);
+        formHelper.setValue('poolType', 'replicated');
+        expect(control.value).toEqual(currentRule);
       });
     });
   });
index 8e3e18f53bf4325e8ed7fe017c46d0374fdf82b3..92bb9522db38c39c94c4b3718e50699d3e778cdc 100644 (file)
@@ -346,12 +346,14 @@ export class PoolFormComponent implements OnInit {
       return;
     }
     const control = this.form.get('crushRule');
-    if (rules.length === 1) {
-      control.setValue(rules[0]);
-      control.disable();
-    } else {
-      control.setValue(null);
-      control.enable();
+    if (this.isReplicated && !control.value) {
+      if (rules.length === 1) {
+        control.setValue(rules[0]);
+        control.disable();
+      } else {
+        control.setValue(null);
+        control.enable();
+      }
     }
     this.replicatedRuleChange();
     this.pgCalc();