]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: disable create snapshot with subvolumes 42732/head
authorPere Diaz Bou <pdiazbou@redhat.com>
Tue, 17 Aug 2021 07:41:58 +0000 (09:41 +0200)
committerPere Diaz Bou <pdiazbou@redhat.com>
Tue, 17 Aug 2021 08:35:24 +0000 (10:35 +0200)
Signed-off-by: Pere Diaz Bou <pdiazbou@redhat.com>
src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-directories/cephfs-directories.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-directories/cephfs-directories.component.ts

index c8f6c22a14b9a093ae846e1de101d99732cbf883..3a43ac5c77dc2e2b7dcc29df9410fb8caf552570 100644 (file)
@@ -1073,5 +1073,39 @@ describe('CephfsDirectoriesComponent', () => {
         expect(component.loadingIndicator).toBe(true);
       });
     });
+    describe('disable create snapshot', () => {
+      let actions: CdTableAction[];
+      beforeEach(() => {
+        actions = component.snapshot.tableActions;
+        mockLib.mkDir('/', 'volumes', 2, 2);
+        mockLib.mkDir('/volumes', 'group1', 2, 2);
+        mockLib.mkDir('/volumes/group1', 'subvol', 2, 2);
+        mockLib.mkDir('/volumes/group1/subvol', 'subfile', 2, 2);
+      });
+
+      const empty = (): CdTableSelection => new CdTableSelection();
+
+      it('should return a descriptive message to explain why it is disabled', () => {
+        const path = '/volumes/group1/subvol/subfile';
+        const res = 'Cannot create snapshots for files/folders in the subvolume subvol';
+        mockLib.selectNode(path);
+        expect(actions[0].disable(empty())).toContain(res);
+      });
+
+      it('should return false if it is not a subvolume node', () => {
+        const testCases = [
+          '/volumes/group1/subvol',
+          '/volumes/group1',
+          '/volumes',
+          '/',
+          '/a',
+          '/a/b'
+        ];
+        testCases.forEach((testCase) => {
+          mockLib.selectNode(testCase);
+          expect(actions[0].disable(empty())).toBeFalsy();
+        });
+      });
+    });
   });
 });
index 498f63e8e8cb9cadd3ac559e215353a12e7d0f5e..c2528f7c4511ed1f6980da5fc64b43a81a3863a8 100644 (file)
@@ -219,7 +219,8 @@ export class CephfsDirectoriesComponent implements OnInit, OnChanges {
           icon: Icons.add,
           permission: 'create',
           canBePrimary: (selection) => !selection.hasSelection,
-          click: () => this.createSnapshot()
+          click: () => this.createSnapshot(),
+          disable: () => this.disableCreateSnapshot()
         },
         {
           name: this.actionLabels.DELETE,
@@ -233,6 +234,16 @@ export class CephfsDirectoriesComponent implements OnInit, OnChanges {
     };
   }
 
+  private disableCreateSnapshot(): string | boolean {
+    const folders = this.selectedDir.path.split('/').slice(1);
+    // With deph of 4 or more we have the subvolume files/folders for which we cannot create
+    // a snapshot. Somehow, you can create a snapshot of the subvolume but not its files.
+    if (folders.length >= 4 && folders[0] === 'volumes') {
+      return $localize`Cannot create snapshots for files/folders in the subvolume ${folders[2]}`;
+    }
+    return false;
+  }
+
   ngOnChanges() {
     this.selectedDir = undefined;
     this.dirs = [];