]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: Prevent clone when layering not enabled on parent image
authorRicardo Marques <rimarques@suse.com>
Thu, 25 Jul 2019 11:48:17 +0000 (12:48 +0100)
committerRicardo Marques <rimarques@suse.com>
Fri, 26 Jul 2019 09:52:53 +0000 (10:52 +0100)
Fixes: https://tracker.ceph.com/issues/39653
Signed-off-by: Ricardo Marques <rimarques@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-details/rbd-details.component.html
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
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-list/rbd-snapshot-list.component.ts

index 21956cb39a674d2e7fd6226f7fba96e263722be2..fa42aa8edb5f7f3203d05e37215d16ff6e3d1eb5 100644 (file)
   <tab i18n-heading
        heading="Snapshots">
     <cd-rbd-snapshot-list [snapshots]="selectedItem.snapshots"
+                          [featuresName]="selectedItem.features_name"
                           [poolName]="selectedItem.pool_name"
                           [rbdName]="selectedItem.name"></cd-rbd-snapshot-list>
   </tab>
index 2b7fed607e6e805fcd59c606b8b5c092ed102298..bf3e89a680946b9da4cef1825a14a07638a9492b 100644 (file)
@@ -1,4 +1,5 @@
 import { I18n } from '@ngx-translate/i18n-polyfill';
+import * as _ from 'lodash';
 
 import { ActionLabelsI18n } from '../../../shared/constants/app.constants';
 import { Icons } from '../../../shared/enum/icons.enum';
@@ -18,7 +19,7 @@ export class RbdSnapshotActionsModel {
   deleteSnap: CdTableAction;
   ordering: CdTableAction[];
 
-  constructor(i18n: I18n, actionLabels: ActionLabelsI18n) {
+  constructor(i18n: I18n, actionLabels: ActionLabelsI18n, featuresName: string[]) {
     this.i18n = i18n;
 
     this.create = {
@@ -49,7 +50,10 @@ export class RbdSnapshotActionsModel {
       permission: 'create',
       canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
       disable: (selection: CdTableSelection) =>
-        !selection.hasSingleSelection || selection.first().cdExecuting,
+        !selection.hasSingleSelection ||
+        selection.first().cdExecuting ||
+        !_.isUndefined(this.getCloneDisableDesc(featuresName)),
+      disableDesc: () => this.getCloneDisableDesc(featuresName),
       icon: Icons.clone,
       name: actionLabels.CLONE
     };
@@ -87,4 +91,10 @@ export class RbdSnapshotActionsModel {
       this.deleteSnap
     ];
   }
+
+  getCloneDisableDesc(featuresName: string[]): string | undefined {
+    if (!featuresName.includes('layering')) {
+      return this.i18n('Parent image must support Layering');
+    }
+  }
 }
index 0d805c27dde27f56c2e18ce40eee4590bd1fdc74..2044a784f26250bd6c79d716efa42e485e2828ea 100644 (file)
@@ -64,6 +64,7 @@ describe('RbdSnapshotListComponent', () => {
   beforeEach(() => {
     fixture = TestBed.createComponent(RbdSnapshotListComponent);
     component = fixture.componentInstance;
+    component.ngOnChanges();
     summaryService = TestBed.get(SummaryService);
   });
 
index e8ef32a41114a8561bb776e3d250522fe4f12070..a72be35e6cc1c18388e12e5bd965adddd2ac0b47 100644 (file)
@@ -37,6 +37,8 @@ export class RbdSnapshotListComponent implements OnInit, OnChanges {
   @Input()
   snapshots: RbdSnapshotModel[] = [];
   @Input()
+  featuresName: string[];
+  @Input()
   poolName: string;
   @Input()
   rbdName: string;
@@ -79,21 +81,6 @@ export class RbdSnapshotListComponent implements OnInit, OnChanges {
     private actionLabels: ActionLabelsI18n
   ) {
     this.permission = this.authStorageService.getPermissions().rbdImage;
-    const actions = new RbdSnapshotActionsModel(this.i18n, this.actionLabels);
-    actions.create.click = () => this.openCreateSnapshotModal();
-    actions.rename.click = () => this.openEditSnapshotModal();
-    actions.protect.click = () => this.toggleProtection();
-    actions.unprotect.click = () => this.toggleProtection();
-    const getImageUri = () =>
-      this.selection.first() &&
-      `${encodeURIComponent(this.poolName)}/${encodeURIComponent(
-        this.rbdName
-      )}/${encodeURIComponent(this.selection.first().name)}`;
-    actions.clone.routerLink = () => `/block/rbd/clone/${getImageUri()}`;
-    actions.copy.routerLink = () => `/block/rbd/copy/${getImageUri()}`;
-    actions.rollback.click = () => this.rollbackModal();
-    actions.deleteSnap.click = () => this.deleteSnapshotModal();
-    this.tableActions = actions.ordering;
   }
 
   ngOnInit() {
@@ -135,6 +122,22 @@ export class RbdSnapshotListComponent implements OnInit, OnChanges {
   }
 
   ngOnChanges() {
+    const actions = new RbdSnapshotActionsModel(this.i18n, this.actionLabels, this.featuresName);
+    actions.create.click = () => this.openCreateSnapshotModal();
+    actions.rename.click = () => this.openEditSnapshotModal();
+    actions.protect.click = () => this.toggleProtection();
+    actions.unprotect.click = () => this.toggleProtection();
+    const getImageUri = () =>
+      this.selection.first() &&
+      `${encodeURIComponent(this.poolName)}/${encodeURIComponent(
+        this.rbdName
+      )}/${encodeURIComponent(this.selection.first().name)}`;
+    actions.clone.routerLink = () => `/block/rbd/clone/${getImageUri()}`;
+    actions.copy.routerLink = () => `/block/rbd/copy/${getImageUri()}`;
+    actions.rollback.click = () => this.rollbackModal();
+    actions.deleteSnap.click = () => this.deleteSnapshotModal();
+    this.tableActions = actions.ordering;
+
     const itemFilter = (entry, task) => {
       return entry.name === task.metadata['snapshot_name'];
     };