From 4139d4b58e37b29f7d84e641ce0c9fd0ee346b8f Mon Sep 17 00:00:00 2001 From: Tiago Melo Date: Mon, 1 Apr 2019 14:13:37 +0000 Subject: [PATCH] mgr/dashboard: Fix NFS pseudo validation Fixes: http://tracker.ceph.com/issues/39063 Signed-off-by: Tiago Melo --- .../app/ceph/nfs/nfs-form/nfs-form.component.spec.ts | 10 ++++++++++ .../src/app/ceph/nfs/nfs-form/nfs-form.component.ts | 9 ++++++++- src/pybind/mgr/dashboard/services/ganesha.py | 7 ++++--- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.spec.ts index 60024884acb..1ebd776a05e 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.spec.ts @@ -147,6 +147,16 @@ describe('NfsFormComponent', () => { }); }); + it('should remove "pseudo" requirement when NFS v4 disabled', () => { + component.nfsForm.patchValue({ + protocolNfsv4: false, + pseudo: '' + }); + + component.nfsForm.updateValueAndValidity({ emitEvent: false }); + expect(component.nfsForm.valid).toBeTruthy(); + }); + it('should call update', () => { activatedRoute.setParams({ cluster_id: 'cluster1', export_id: '1' }); component.isEdit = true; diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.ts index aa1ce7abb98..48349f4a558 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.ts @@ -169,7 +169,10 @@ export class NfsFormComponent implements OnInit { }), tag: new FormControl(''), pseudo: new FormControl('', { - validators: [Validators.required, Validators.pattern('^/[^><|&()]*$')] + validators: [ + CdValidators.requiredIf({ protocolNfsv4: true }), + Validators.pattern('^/[^><|&()]*$') + ] }), access_type: new FormControl('RW', { validators: [Validators.required] @@ -198,6 +201,10 @@ export class NfsFormComponent implements OnInit { CdValidators.requiredIf({ security_label: true, 'fsal.name': 'CEPH' }) ) }); + + this.nfsForm.get('protocolNfsv4').valueChanges.subscribe(() => { + this.nfsForm.get('pseudo').updateValueAndValidity({ emitEvent: false }); + }); } resolveModel(res) { diff --git a/src/pybind/mgr/dashboard/services/ganesha.py b/src/pybind/mgr/dashboard/services/ganesha.py index 2fe427e5d94..8a81e5bb35b 100644 --- a/src/pybind/mgr/dashboard/services/ganesha.py +++ b/src/pybind/mgr/dashboard/services/ganesha.py @@ -857,9 +857,10 @@ class GaneshaConf(object): @classmethod def format_path(cls, path): - path = path.strip() - if len(path) > 1 and path[-1] == '/': - path = path[:-1] + if path is not None: + path = path.strip() + if len(path) > 1 and path[-1] == '/': + path = path[:-1] return path def validate(self, export): -- 2.39.5