]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Allow to edit iSCSI target with active session 35998/head
authorRicardo Marques <rimarques@suse.com>
Tue, 7 Jul 2020 12:39:08 +0000 (13:39 +0100)
committerRicardo Marques <rimarques@suse.com>
Fri, 10 Jul 2020 10:37:47 +0000 (11:37 +0100)
Fixes: https://tracker.ceph.com/issues/46383
Signed-off-by: Ricardo Marques <rimarques@suse.com>
(cherry picked from commit df6163e1369703117ac683bcbd5056e1543f4d06)

 Conflicts:
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.spec.ts

src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.ts

index dbe889648ed04d51af11378b8476858126799ec5..aa95a4a28706aeeb92b0f1faa9c8e15584c626a7 100644 (file)
@@ -16,6 +16,7 @@ import {
 } from '../../../../testing/unit-test-helper';
 import { IscsiService } from '../../../shared/api/iscsi.service';
 import { TableActionsComponent } from '../../../shared/datatable/table-actions/table-actions.component';
+import { CdTableAction } from '../../../shared/models/cd-table-action';
 import { ExecutingTask } from '../../../shared/models/executing-task';
 import { SummaryService } from '../../../shared/services/summary.service';
 import { TaskListService } from '../../../shared/services/task-list.service';
@@ -323,6 +324,108 @@ describe('IscsiTargetListComponent', () => {
         expect(tableActions.tableActions.length).toBe(0);
         expect(tableActions.tableActions).toEqual([]);
       });
+
+      describe('handling of actions', () => {
+        beforeEach(() => {
+          fixture.detectChanges();
+        });
+
+        let action: CdTableAction;
+
+        const getAction = (name: string): CdTableAction => {
+          return component.tableActions.find((tableAction) => tableAction.name === name);
+        };
+
+        describe('edit', () => {
+          beforeEach(() => {
+            action = getAction('Edit');
+          });
+
+          it('should be disabled if no gateways', () => {
+            component.selection.selected = [
+              {
+                id: '-1'
+              }
+            ];
+            component.selection.update();
+            expect(action.disable(undefined)).toBeTruthy();
+            expect(action.disableDesc(undefined)).toBe('Unavailable gateway(s)');
+          });
+
+          it('should be enabled if active sessions', () => {
+            component.selection.selected = [
+              {
+                id: '-1',
+                info: {
+                  num_sessions: 1
+                }
+              }
+            ];
+            component.selection.update();
+            expect(action.disable(undefined)).toBeFalsy();
+            expect(action.disableDesc(undefined)).toBeUndefined();
+          });
+
+          it('should be enabled if no active sessions', () => {
+            component.selection.selected = [
+              {
+                id: '-1',
+                info: {
+                  num_sessions: 0
+                }
+              }
+            ];
+            component.selection.update();
+            expect(action.disable(undefined)).toBeFalsy();
+            expect(action.disableDesc(undefined)).toBeUndefined();
+          });
+        });
+
+        describe('delete', () => {
+          beforeEach(() => {
+            action = getAction('Delete');
+          });
+
+          it('should be disabled if no gateways', () => {
+            component.selection.selected = [
+              {
+                id: '-1'
+              }
+            ];
+            component.selection.update();
+            expect(action.disable(undefined)).toBeTruthy();
+            expect(action.disableDesc(undefined)).toBe('Unavailable gateway(s)');
+          });
+
+          it('should be disabled if active sessions', () => {
+            component.selection.selected = [
+              {
+                id: '-1',
+                info: {
+                  num_sessions: 1
+                }
+              }
+            ];
+            component.selection.update();
+            expect(action.disable(undefined)).toBeTruthy();
+            expect(action.disableDesc(undefined)).toBe('Target has active sessions');
+          });
+
+          it('should be enabled if no active sessions', () => {
+            component.selection.selected = [
+              {
+                id: '-1',
+                info: {
+                  num_sessions: 0
+                }
+              }
+            ];
+            component.selection.update();
+            expect(action.disable(undefined)).toBeFalsy();
+            expect(action.disableDesc(undefined)).toBeUndefined();
+          });
+        });
+      });
     });
   });
 });
index 4a2be837551d2cb488c32d75d5c1598a9af1dfa8..6710b755457af45035dc7829097e4a8388b560c8 100644 (file)
@@ -80,7 +80,7 @@ export class IscsiTargetListComponent implements OnInit, OnDestroy {
         icon: 'fa-pencil',
         routerLink: () => `/block/iscsi/targets/edit/${this.selection.first().target_iqn}`,
         name: this.actionLabels.EDIT,
-        disable: () => !this.selection.first() || !_.isUndefined(this.getDeleteDisableDesc()),
+        disable: () => !this.selection.first() || !_.isUndefined(this.getEditDisableDesc()),
         disableDesc: () => this.getEditDisableDesc()
       },
       {