From 63524e7d1ef25bd88ef801128f2b7433ca717cc6 Mon Sep 17 00:00:00 2001 From: Pere Diaz Bou Date: Tue, 17 Aug 2021 09:41:58 +0200 Subject: [PATCH] mgr/dashboard: disable create snapshot with subvolumes Signed-off-by: Pere Diaz Bou (cherry picked from commit b38259b62950ed2b15175935af7de00059926f3f) --- .../cephfs-directories.component.spec.ts | 34 +++++++++++++++++++ .../cephfs-directories.component.ts | 13 ++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-directories/cephfs-directories.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-directories/cephfs-directories.component.spec.ts index c8f6c22a14b9..3a43ac5c77dc 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-directories/cephfs-directories.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-directories/cephfs-directories.component.spec.ts @@ -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(); + }); + }); + }); }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-directories/cephfs-directories.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-directories/cephfs-directories.component.ts index 498f63e8e8cb..c2528f7c4511 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-directories/cephfs-directories.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-directories/cephfs-directories.component.ts @@ -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 = []; -- 2.47.3