From: Nizamudeen A Date: Fri, 12 Aug 2022 10:44:31 +0000 (+0530) Subject: mgr/dashboard: fix nfs exports form issues with squash field X-Git-Tag: v17.2.4~11^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b1aa496b1056cb7fcb79493cf30207aeb4db1b23;p=ceph.git mgr/dashboard: fix nfs exports form issues with squash field 1. Squash is not a mandatory field. 2. If the export is created from backend, then squash can have many different names for each types of squash. for eg. ``` ['root', 'root_squash', 'rootsquash', 'rootid', 'root_id_squash', 'rootidsquash', 'all', 'all_squash', 'allsquash', 'all_anomnymous', 'allanonymous', 'no_root_squash', 'none', 'noidsquash'] ``` so we need a proper matching in the ui too otherwise the edit field will not have any value for the squash field. 3. Removed unncessary dropdown helper if there are values for the squash and access types. Fixes: https://tracker.ceph.com/issues/57114 Signed-off-by: Nizamudeen A (cherry picked from commit 23c00ed480b9e8001790efeb891b9687887ab65d) --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form-client/nfs-form-client.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form-client/nfs-form-client.component.ts index 942e96e2eb967..15e7d7d5ccebb 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form-client/nfs-form-client.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form-client/nfs-form-client.component.ts @@ -21,7 +21,7 @@ export class NfsFormClientComponent implements OnInit { @ContentChild('squashHelper', { static: true }) squashHelperTpl: TemplateRef; - nfsSquash: any[] = this.nfsService.nfsSquash; + nfsSquash: any[] = Object.keys(this.nfsService.nfsSquash); nfsAccessType: any[] = this.nfsService.nfsAccessType; icons = Icons; clientsFormArray: FormArray; diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.html index 70a2ae370d713..7313ea69b2ecd 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.html @@ -278,9 +278,6 @@ - @@ -304,8 +301,7 @@
@@ -319,9 +315,6 @@ - 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 7cf3d61387a43..62efec423d36a 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 @@ -36,13 +36,34 @@ describe('NfsFormComponent', () => { providers: [ { provide: ActivatedRoute, - useValue: new ActivatedRouteStub({ cluster_id: undefined, export_id: undefined }) + useValue: new ActivatedRouteStub({ cluster_id: 'mynfs', export_id: '1' }) } ] }, [LoadingPanelComponent] ); + const matchSquash = (backendSquashValue: string, uiSquashValue: string) => { + component.ngOnInit(); + httpTesting.expectOne('ui-api/nfs-ganesha/fsals').flush(['CEPH', 'RGW']); + httpTesting.expectOne('ui-api/nfs-ganesha/cephfs/filesystems').flush([{ id: 1, name: 'a' }]); + httpTesting.expectOne('api/nfs-ganesha/cluster').flush(['mynfs']); + httpTesting.expectOne('api/nfs-ganesha/export/mynfs/1').flush({ + fsal: { + name: 'RGW' + }, + export_id: 1, + transports: ['TCP', 'UDP'], + protocols: [4], + clients: [], + squash: backendSquashValue + }); + httpTesting.verify(); + expect(component.nfsForm.value).toMatchObject({ + squash: uiSquashValue + }); + }; + beforeEach(() => { fixture = TestBed.createComponent(NfsFormComponent); component = fixture.componentInstance; @@ -104,6 +125,14 @@ describe('NfsFormComponent', () => { expect(component.nfsForm.get('protocolNfsv4')).toBeTruthy(); }); + it('should match backend squash values with ui values', () => { + component.isEdit = true; + matchSquash('none', 'no_root_squash'); + matchSquash('all', 'all_squash'); + matchSquash('rootid', 'root_id_squash'); + matchSquash('root', 'root_squash'); + }); + describe('should submit request', () => { beforeEach(() => { component.nfsForm.patchValue({ 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 a56c1105e08e4..595b3b7fe7c39 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 @@ -56,7 +56,7 @@ export class NfsFormComponent extends CdForm implements OnInit { defaultAccessType = { RGW: 'RO' }; nfsAccessType: any[] = this.nfsService.nfsAccessType; - nfsSquash: any[] = this.nfsService.nfsSquash; + nfsSquash: any[] = Object.keys(this.nfsService.nfsSquash); action: string; resource: string; @@ -161,12 +161,8 @@ export class NfsFormComponent extends CdForm implements OnInit { Validators.pattern('^/[^><|&()]*$') ] }), - access_type: new FormControl('RW', { - validators: [Validators.required] - }), - squash: new FormControl(this.nfsSquash[0], { - validators: [Validators.required] - }), + access_type: new FormControl('RW'), + squash: new FormControl(this.nfsSquash[0]), transportUDP: new FormControl(true, { validators: [ CdValidators.requiredIf({ transportTCP: false }, (value: boolean) => { @@ -202,6 +198,12 @@ export class NfsFormComponent extends CdForm implements OnInit { res.transportUDP = res.transports.indexOf('UDP') !== -1; delete res.transports; + Object.entries(this.nfsService.nfsSquash).forEach(([key, value]) => { + if (value.includes(res.squash)) { + res.squash = key; + } + }); + res.clients.forEach((client: any) => { let addressStr = ''; client.addresses.forEach((address: string) => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/nfs.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/nfs.service.ts index 636335673978f..9b4e4a0a288d0 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/nfs.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/nfs.service.ts @@ -45,7 +45,12 @@ export class NfsService extends ApiClient { } ]; - nfsSquash = ['no_root_squash', 'root_id_squash', 'root_squash', 'all_squash']; + nfsSquash = { + no_root_squash: ['no_root_squash', 'noidsquash', 'none'], + root_id_squash: ['root_id_squash', 'rootidsquash', 'rootid'], + root_squash: ['root_squash', 'rootsquash', 'root'], + all_squash: ['all_squash', 'allsquash', 'all', 'allanonymous', 'all_anonymous'] + }; constructor(private http: HttpClient) { super();