From 8aa0991bb974b5284e2497ece2949858f27dd9c4 Mon Sep 17 00:00:00 2001 From: Ricardo Marques Date: Tue, 7 Jul 2020 13:39:08 +0100 Subject: [PATCH] mgr/dashboard: Allow to edit iSCSI target with active session Fixes: https://tracker.ceph.com/issues/46383 Signed-off-by: Ricardo Marques (cherry picked from commit df6163e1369703117ac683bcbd5056e1543f4d06) Conflicts: src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.spec.ts --- .../iscsi-target-list.component.spec.ts | 103 ++++++++++++++++++ .../iscsi-target-list.component.ts | 2 +- 2 files changed, 104 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.spec.ts index dbe889648ed04..aa95a4a28706a 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.spec.ts @@ -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(); + }); + }); + }); }); }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.ts index 4a2be837551d2..6710b755457af 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.ts @@ -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() }, { -- 2.39.5