From: Stephan Müller Date: Tue, 3 Mar 2020 14:39:32 +0000 (+0100) Subject: mgr/dashboard: Preserve rule selection on pool type change X-Git-Tag: v15.1.1~39^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=63480750b8bc679feb8432a6485827dc95094bd5;p=ceph.git mgr/dashboard: Preserve rule selection on pool type change 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 --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/pool/pool-form/pool-form.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/pool/pool-form/pool-form.component.spec.ts index 5ff1418c94cb..d4f8fc16e4d8 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/pool/pool-form/pool-form.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/pool/pool-form/pool-form.component.spec.ts @@ -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); }); }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/pool/pool-form/pool-form.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/pool/pool-form/pool-form.component.ts index 8e3e18f53bf4..92bb9522db38 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/pool/pool-form/pool-form.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/pool/pool-form/pool-form.component.ts @@ -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();