]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: disable protect if layering is not enabled on the image 53174/head
authoravanthakkar <avanjohn@gmail.com>
Mon, 21 Aug 2023 13:34:53 +0000 (19:04 +0530)
committeravanthakkar <avanjohn@gmail.com>
Mon, 28 Aug 2023 07:17:37 +0000 (12:47 +0530)
Fixes: https://tracker.ceph.com/issues/62498
Signed-off-by: avanthakkar <avanjohn@gmail.com>
(cherry picked from commit 16e913f0ba3918732cfc9984f707379df65ac29a)

src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-list/rbd-snapshot-actions.model.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-list/rbd-snapshot-list.component.spec.ts

index 8b40111b8c8cb655586b4ea90c863ada4af02ea0..345d47e7421d1508be01c2a226252afbf3d21cec 100644 (file)
@@ -44,7 +44,9 @@ export class RbdSnapshotActionsModel {
       visible: (selection: CdTableSelection) =>
         selection.hasSingleSelection && !selection.first().is_protected,
       name: actionLabels.PROTECT,
-      disable: (selection: CdTableSelection) => this.disableForMirrorSnapshot(selection)
+      disable: (selection: CdTableSelection) =>
+        this.disableForMirrorSnapshot(selection) ||
+        this.getDisableDesc(selection, this.featuresName)
     };
     this.unprotect = {
       permission: 'update',
@@ -58,7 +60,7 @@ export class RbdSnapshotActionsModel {
       permission: 'create',
       canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
       disable: (selection: CdTableSelection) =>
-        this.getCloneDisableDesc(selection, this.featuresName) ||
+        this.getDisableDesc(selection, this.featuresName) ||
         this.disableForMirrorSnapshot(selection),
       icon: Icons.clone,
       name: actionLabels.CLONE
@@ -107,10 +109,10 @@ export class RbdSnapshotActionsModel {
     ];
   }
 
-  getCloneDisableDesc(selection: CdTableSelection, featuresName: string[]): boolean | string {
+  getDisableDesc(selection: CdTableSelection, featuresName: string[]): boolean | string {
     if (selection.hasSingleSelection && !selection.first().cdExecuting) {
       if (!featuresName?.includes('layering')) {
-        return $localize`Parent image must support Layering`;
+        return $localize`The layering feature needs to be enabled on parent image`;
       }
 
       if (this.cloneFormatVersion === 1 && !selection.first().is_protected) {
index 797fc35a11c6394a27a20b0b28784a3aa392d63e..d2fb9b067e0122fcb900d643f940626e384b495c 100644 (file)
@@ -288,7 +288,7 @@ describe('RbdSnapshotListComponent', () => {
 
     it('should be disabled with version 1 and protected false', () => {
       const selection = new CdTableSelection([{ name: 'someName', is_protected: false }]);
-      const disableDesc = actions.getCloneDisableDesc(selection, ['layering']);
+      const disableDesc = actions.getDisableDesc(selection, ['layering']);
       expect(disableDesc).toBe('Snapshot must be protected in order to clone.');
     });
 
@@ -299,8 +299,25 @@ describe('RbdSnapshotListComponent', () => {
     ])('should be enabled with version %d and protected %s', (version, is_protected) => {
       actions.cloneFormatVersion = version;
       const selection = new CdTableSelection([{ name: 'someName', is_protected: is_protected }]);
-      const disableDesc = actions.getCloneDisableDesc(selection, ['layering']);
+      const disableDesc = actions.getDisableDesc(selection, ['layering']);
       expect(disableDesc).toBe(false);
     });
   });
+
+  describe('protect button disable state', () => {
+    let actions: RbdSnapshotActionsModel;
+
+    beforeEach(() => {
+      fixture.detectChanges();
+      const rbdService = TestBed.inject(RbdService);
+      const actionLabelsI18n = TestBed.inject(ActionLabelsI18n);
+      actions = new RbdSnapshotActionsModel(actionLabelsI18n, [], rbdService);
+    });
+
+    it('should be disabled if layering not supported', () => {
+      const selection = new CdTableSelection([{ name: 'someName', is_protected: false }]);
+      const disableDesc = actions.getDisableDesc(selection, ['deep-flatten', 'fast-diff']);
+      expect(disableDesc).toBe('The layering feature needs to be enabled on parent image');
+    });
+  });
 });