]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: fix nfs exports form issues with squash field
authorNizamudeen A <nia@redhat.com>
Fri, 12 Aug 2022 10:44:31 +0000 (16:14 +0530)
committerNizamudeen A <nia@redhat.com>
Tue, 13 Sep 2022 07:24:19 +0000 (12:54 +0530)
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.

Resolves: rhbz#2062456

Fixes: https://tracker.ceph.com/issues/57114
Signed-off-by: Nizamudeen A <nia@redhat.com>
(cherry picked from commit 23c00ed480b9e8001790efeb891b9687887ab65d)
(cherry picked from commit b1aa496b1056cb7fcb79493cf30207aeb4db1b23)

src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form-client/nfs-form-client.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.html
src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/nfs.service.ts

index 942e96e2eb9674aef87266bcab7beaf624878f83..15e7d7d5ccebbd56512f1dc524c59548ef35845f 100644 (file)
@@ -21,7 +21,7 @@ export class NfsFormClientComponent implements OnInit {
 
   @ContentChild('squashHelper', { static: true }) squashHelperTpl: TemplateRef<any>;
 
-  nfsSquash: any[] = this.nfsService.nfsSquash;
+  nfsSquash: any[] = Object.keys(this.nfsService.nfsSquash);
   nfsAccessType: any[] = this.nfsService.nfsAccessType;
   icons = Icons;
   clientsFormArray: FormArray;
index 70a2ae370d7133e5ca34228068627ea969d6325e..7313ea69b2ecd96d1e1d3adaca92ca6188176a78 100644 (file)
               <option *ngIf="nfsAccessType !== null && nfsAccessType.length === 0"
                       value=""
                       i18n>-- No access type available --</option>
-              <option *ngIf="nfsAccessType !== null && nfsAccessType.length > 0"
-                      value=""
-                      i18n>-- Select the access type --</option>
               <option *ngFor="let accessType of nfsAccessType"
                       [value]="accessType.value">{{ accessType.value }}</option>
             </select>
         <div class="form-group row">
           <label class="cd-col-form-label"
                  for="squash">
-            <span class="required"
-                  i18n>Squash</span>
+            <span i18n>Squash</span>
             <ng-container *ngTemplateOutlet="squashHelper"></ng-container>
           </label>
           <div class="cd-col-form-input">
               <option *ngIf="nfsSquash !== null && nfsSquash.length === 0"
                       value=""
                       i18n>-- No squash available --</option>
-              <option *ngIf="nfsSquash !== null && nfsSquash.length > 0"
-                      value=""
-                      i18n>--Select what kind of user id squashing is performed --</option>
               <option *ngFor="let squash of nfsSquash"
                       [value]="squash">{{ squash }}</option>
 
index 7cf3d61387a436a138b1b3d92630c1f980478065..62efec423d36aac61f13cf28988ce0e64ccbbcdc 100644 (file)
@@ -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({
index a56c1105e08e49c2b89b9ac41fb5c7b9faec0d61..595b3b7fe7c39514b898047650fc1f65fcbefa00 100644 (file)
@@ -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) => {
index 636335673978f57619adf54f648830404070182e..9b4e4a0a288d06927e53b7e7e9027e37f5e22814 100644 (file)
@@ -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();