Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
convert vm,vmi actions to dynamic
  • Loading branch information
glekner committed Nov 22, 2021
1 parent a934847 commit db8d0a7
Show file tree
Hide file tree
Showing 19 changed files with 168 additions and 652 deletions.
Expand Up @@ -81,7 +81,8 @@ const ActionMenuToggle: React.FC<ActionMenuToggleProps> = ({
aria-haspopup="true"
data-test-id={isKebabVariant ? 'kebab-button' : 'actions-menu-button'}
onClick={handleToggleClick}
{...(isKebabVariant ? { onFocus: onToggleHover, onMouseEnter: onToggleHover } : {})}
onFocus={onToggleHover}
onMouseOver={onToggleHover}
>
{isKebabVariant ? <EllipsisVIcon /> : toggleLabel}
</MenuToggle>
Expand Down
Expand Up @@ -143,7 +143,7 @@ describe('test dev console', () => {
it('ID(CNV-5702) clone vm', () => {
selectActionFromDropdown(VM_ACTION.Clone, actionButtons.actionDropdownButton);
cy.get(modalTitle)
.contains('Clone Virtual Machine')
.contains('Clone')
.should('exist');
cy.get(alertTitle).should('be.visible');
cy.get(confirmCloneButton).click();
Expand Down
Expand Up @@ -50,7 +50,7 @@ describe('Test VM/VMI actions', () => {

it('ID(CNV-765) Unpauses VM', () => {
vm.pause();
vm.unpause();
vm.resume();
});

it('ID(CNV-4015) Stops VM', () => {
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('Test VM/VMI actions', () => {
namespace: vmData.namespace,
},
});
vm.unpause();
vm.resume();
});

it('ID(CNV-4019) Unpauses VM via modal dialog', () => {
Expand Down
Expand Up @@ -14,6 +14,7 @@ const vmData: VirtualMachineData = {
pvcSize: '1',
sshEnable: false,
startOnCreation: false,
sourceAvailable: true,
};

describe('Test VM Migration', () => {
Expand Down
Expand Up @@ -33,16 +33,16 @@ export enum DEFAULT_VALUES {
// VM Actions
export enum VM_ACTION {
Cancel = 'Cancel Virtual Machine Migration',
Clone = 'Clone Virtual Machine',
Clone = 'Clone',
Delete = 'Delete Virtual Machine',
EditAnnotations = 'Edit Annotations',
EditLabels = 'Edit Labels',
Migrate = 'Migrate Virtual Machine',
Restart = 'Restart Virtual Machine',
Start = 'Start Virtual Machine',
Stop = 'Stop Virtual Machine',
Unpause = 'Unpause Virtual Machine',
Pause = 'Pause Virtual Machine',
Migrate = 'Migrate',
Restart = 'Restart',
Start = 'Start',
Stop = 'Stop',
Resume = 'Resume',
Pause = 'Pause',
}

export enum VMI_ACTION {
Expand Down
Expand Up @@ -121,9 +121,9 @@ export const vm = {
});
cy.byTestID('create-vm-empty').should('be.visible');
},
unpause: () => {
resume: () => {
waitForStatus(VM_STATUS.Paused);
action(VM_ACTION.Unpause);
action(VM_ACTION.Resume);
waitForStatus(VM_STATUS.Running);
},
migrate: (waitForComplete = true) => {
Expand Down
Expand Up @@ -11,16 +11,16 @@ export enum TAB {
}

export enum VM_ACTION {
Cancel = 'Cancel Virtual Machine Migration',
Clone = 'Clone Virtual Machine',
Delete = 'Delete Virtual Machine',
Cancel = 'Cancel Migration',
Clone = 'Clone',
Delete = 'Delete',
EditAnnotations = 'Edit Annotations',
EditLabels = 'Edit Labels',
Migrate = 'Migrate Virtual Machine',
Restart = 'Restart Virtual Machine',
Start = 'Start Virtual Machine',
Stop = 'Stop Virtual Machine',
Unpause = 'Unpause Virtual Machine',
Migrate = 'Migrate',
Restart = 'Restart',
Start = 'Start',
Stop = 'Stop',
Unpause = 'Unpause',
}

export enum VMI_ACTION {
Expand Down
Expand Up @@ -16,7 +16,7 @@ import { ProvisionSource } from './utils/constants/enums/provisionSource';
import { VM_ACTION, VM_STATUS } from './utils/constants/vm';

describe('Test VM Migration', () => {
const MIGRATE_VM = 'Migrate Virtual Machine';
const MIGRATE_VM = 'Migrate';
const CANCEL_MIGRATION = 'Cancel Virtual Machine Migration';
const VM_BOOT_AND_MIGRATE_TIMEOUT = VM_BOOTUP_TIMEOUT_SECS + VM_MIGRATION_TIMEOUT_SECS;

Expand Down
35 changes: 15 additions & 20 deletions frontend/packages/kubevirt-plugin/locales/en/kubevirt-plugin.json
Expand Up @@ -457,6 +457,7 @@
"new VM name": "new VM name",
"Start virtual machine on clone": "Start virtual machine on clone",
"Configuration": "Configuration",
"Clone": "Clone",
"Detach {{diskName}} hot-plugged disk": "Detach {{diskName}} hot-plugged disk",
"Detach {{diskName}} disk": "Detach {{diskName}} disk",
"Are you sure you want to detach <1>{{diskName}}</1> disk?": "Are you sure you want to detach <1>{{diskName}}</1> disk?",
Expand Down Expand Up @@ -804,36 +805,29 @@
"Supported operating systems are labeled below.": "Supported operating systems are labeled below.",
"Learn more about Red Hat support": "Learn more about Red Hat support",
"Are you sure you want to {actionLabel} <3>{name}</3> in namespace <6>{namespace}</6>?": "Are you sure you want to {actionLabel} <3>{name}</3> in namespace <6>{namespace}</6>?",
"Cancel Import?": "Cancel Import?",
"Are you sure you want to cancel importing {{vmImportElem}}? It will also delete the newly created {{vmElem}} in the {{nsElem}} namespace?": "Are you sure you want to cancel importing {{vmImportElem}}? It will also delete the newly created {{vmElem}} in the {{nsElem}} namespace?",
"Are you sure you want to cancel importing {{vmImportElem}} in the {{nsElem}} namespace?": "Are you sure you want to cancel importing {{vmImportElem}} in the {{nsElem}} namespace?",
"Cancel Import": "Cancel Import",
"<0>This virtual machine will start as soon as the import has been completed. If you proceed you will not be able to change this option.</0>Are you sure you want to start <2>{name}</2> in namespace <5>{namespace}</5> after it has imported?": "<0>This virtual machine will start as soon as the import has been completed. If you proceed you will not be able to change this option.</0>Are you sure you want to start <2>{name}</2> in namespace <5>{namespace}</5> after it has imported?",
"Start Virtual Machine": "Start Virtual Machine",
" Start Virtual Machine": " Start Virtual Machine",
"Start": "Start",
"Stop Virtual Machine": "Stop Virtual Machine",
"Stop Virtual Machine alert": "Stop Virtual Machine alert",
"stop": "stop",
" Start": " Start",
"Stop": "Stop",
"Unpause Virtual Machine": "Unpause Virtual Machine",
"unpause": "unpause",
"Pause Virtual Machine": "Pause Virtual Machine",
"pause": "pause",
"Stop alert": "Stop alert",
"stop": "stop",
"Restart alert": "Restart alert",
"Pause": "Pause",
"pause": "pause",
"Resume": "Resume",
"unpause": "unpause",
"Do you wish to migrate <1>{name}</1> vmi to another node?": "Do you wish to migrate <1>{name}</1> vmi to another node?",
"Migrate Virtual Machine": "Migrate Virtual Machine",
"Migrate": "Migrate",
"Migrate Node to Node": "Migrate Node to Node",
"Are you sure you want to cancel <1>{name}</1> migration in <4>{namespace}</4> namespace?": "Are you sure you want to cancel <1>{name}</1> migration in <4>{namespace}</4> namespace?",
"Cancel Virtual Machine Migration": "Cancel Virtual Machine Migration",
"Cancel Migration": "Cancel Migration",
"Open Console": "Open Console",
"Delete Virtual Machine": "Delete Virtual Machine",
"Delete Virtual Machine Instance": "Delete Virtual Machine Instance",
"Open Console": "Open Console",
"Copy SSH Command": "Copy SSH Command",
"Manage SSH access in the virtual machine details page": "Manage SSH access in the virtual machine details page",
"Requires SSH Service": "Requires SSH Service",
"copy to clipboard": "copy to clipboard",
"Cancel Import?": "Cancel Import?",
"Are you sure you want to cancel importing {{vmImportElem}}? It will also delete the newly created {{vmElem}} in the {{nsElem}} namespace?": "Are you sure you want to cancel importing {{vmImportElem}}? It will also delete the newly created {{vmElem}} in the {{nsElem}} namespace?",
"Are you sure you want to cancel importing {{vmImportElem}} in the {{nsElem}} namespace?": "Are you sure you want to cancel importing {{vmImportElem}} in the {{nsElem}} namespace?",
"Cancel Import": "Cancel Import",
"Launch Migration Tool": "Launch Migration Tool",
"Install Migration Tool": "Install Migration Tool",
"Deploy Migration Tool Instance": "Deploy Migration Tool Instance",
Expand Down Expand Up @@ -883,6 +877,7 @@
"Pod": "Pod",
"User credentials": "User credentials",
"user: {{user}}": "user: {{user}}",
"Requires SSH Service": "Requires SSH Service",
"SSH Access": "SSH Access",
"port: {{port}}": "port: {{port}}",
"SSH Service disabled": "SSH Service disabled",
Expand Down
17 changes: 10 additions & 7 deletions frontend/packages/kubevirt-plugin/src/actions/provider.ts
Expand Up @@ -3,7 +3,7 @@ import { CommonActionFactory } from '@console/app/src/actions/creators/common-fa
import { useK8sWatchResource } from '@console/internal/components/utils/k8s-watch-hook';
import { referenceFor } from '@console/internal/module/k8s';
import { useK8sModel } from '@console/shared/src/hooks/useK8sModel';
import { VmActionFactory } from '../components/vms/menu-actions';
import { VmActionFactory, VmiActionFactory } from '../components/vms/menu-actions';
import { useVMStatus } from '../hooks/use-vm-status';
import { VirtualMachineInstanceModel } from '../models';
import { kubevirtReferenceForModel } from '../models/kubevirtReferenceForModel';
Expand All @@ -25,9 +25,10 @@ export const useVmActionsProvider = (vm: VMKind) => {
const vmStatusBundle = useVMStatus(name, namespace);

const actions = React.useMemo(() => {
const start = !isVMRunningOrExpectedRunning(vm, vmi)
? VmActionFactory.Start(k8sModel, vm, { vmi, vmStatusBundle })
: VmActionFactory.Stop(k8sModel, vm, { vmStatusBundle, vmi });
const start =
!isVMRunningOrExpectedRunning(vm, vmi) || isVMIPaused(vmi)
? VmActionFactory.Start(k8sModel, vm, { vmi, vmStatusBundle })
: VmActionFactory.Stop(k8sModel, vm, { vmStatusBundle, vmi });

const migrate =
!vmStatusBundle || !vmStatusBundle?.status?.isMigrating()
Expand All @@ -44,9 +45,11 @@ export const useVmActionsProvider = (vm: VMKind) => {
start,
VmActionFactory.Restart(k8sModel, vm, { vmi }),
pause,
migrate,
VmActionFactory.Clone(k8sModel, vm, { vmi }),
migrate,
VmActionFactory.OpenConsole(k8sModel, vm, { vmi }),
// disabled until https://issues.redhat.com/browse/CNV-9746 is implemented
// VmActionFactory.CopySSH(k8sModel, vm, { vmi }),
CommonActionFactory.ModifyLabels(k8sModel, vm),
CommonActionFactory.ModifyAnnotations(k8sModel, vm),
VmActionFactory.Delete(k8sModel, vm, { vmi }),
Expand All @@ -71,10 +74,10 @@ export const useVmiActionsProvider = (vm: VMKind) => {
const actions = React.useMemo(() => {
return vmStatusBundle
? [
VmActionFactory.OpenConsole(k8sModel, vm, { vmi }),
...(vmi ? [VmActionFactory.OpenConsole(k8sModel, vm, { vmi })] : []),
CommonActionFactory.ModifyLabels(k8sModel, vm),
CommonActionFactory.ModifyAnnotations(k8sModel, vm),
VmActionFactory.Delete(k8sModel, vm, { vmi }),
...(vmi ? [VmiActionFactory.Delete(k8sModel, vmi)] : []),
]
: [];
}, [k8sModel, vm, vmStatusBundle, vmi]);
Expand Down
Expand Up @@ -223,7 +223,7 @@ export const CloneVMModal = withHandlePromise<CloneVMModalProps>((props) => {
warningMessage={vmRunningWarning}
inProgress={inProgress}
isDisabled={!isValid || inProgress}
submitButtonText={t('kubevirt-plugin~Clone Virtual Machine')}
submitButtonText={t('kubevirt-plugin~Clone')}
onSubmit={submit}
onCancel={onCancelClick}
/>
Expand Down
Expand Up @@ -45,7 +45,7 @@ export const DeleteVMIModal = withHandlePromise((props: DeleteVMIProps) => {
namespace,
getVMIVolumes(vmiUpToDate, null),
);
const isInProgress = inProgress || !isOwnedVolumeResourcesLoaded;
const isInProgress = inProgress || !isOwnedVolumeResourcesLoaded || !name || !namespace;
const numOfAllResources = ownedVolumeResources.length;

const submit = (e) => {
Expand Down

This file was deleted.

0 comments on commit db8d0a7

Please sign in to comment.