From: Ricardo Marques Date: Tue, 7 Jul 2020 12:39:08 +0000 (+0100) Subject: mgr/dashboard: Allow to edit iSCSI target with active session X-Git-Tag: v14.2.11~68^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8aa0991bb974b5284e2497ece2949858f27dd9c4;p=ceph.git 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 --- 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 dbe889648ed..aa95a4a2870 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 4a2be837551..6710b755457 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() }, {