Skip to content

Commit

Permalink
add snapshots integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilad Lekner authored and glekner committed Dec 7, 2020
1 parent 7b07e5c commit 29ed70d
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 3 deletions.
Expand Up @@ -120,6 +120,11 @@ export class KubevirtUIResource<T extends BaseVMBuilderData> extends UIResource
await isLoaded();
}

async navigateToSnapshots() {
await this.navigateToTab(TAB.Snapshots);
await isLoaded();
}

async navigateToDisks() {
await this.navigateToTab(TAB.Disks);
await isLoaded();
Expand Down
Expand Up @@ -7,6 +7,7 @@ export enum TAB {
NetworkInterfaces = 'Network Interfaces',
Yaml = 'YAML',
Environment = 'Environment',
Snapshots = 'Snapshots',
}

export enum VM_ACTION {
Expand Down
@@ -0,0 +1,81 @@
import { browser, ExpectedConditions as until } from 'protractor';
import { listViewAction } from '@console/shared/src/test-utils/actions.view';
import { testName } from '@console/internal-integration-tests/protractor.conf';
import {
createResource,
click,
addLeakableResource,
removeLeakedResources,
} from '@console/shared/src/test-utils/utils';
import * as editVMSnapshotsView from '../views/vm.snapshots.view';
import { saveButton } from '../views/kubevirtUIResource.view';
import { VM_CREATE_AND_EDIT_TIMEOUT_SECS } from './utils/constants/common';
import { VirtualMachine } from './models/virtualMachine';
import { getVMManifest } from './mocks/mocks';
import { getRandStr } from './utils/utils';
import { READY } from '../../src/utils/strings';
import { ProvisionSource } from './utils/constants/enums/provisionSource';

const TEST_SNAPSHOT = 'test-snapshot';

describe('KubeVirt VM Snapshots', () => {
const leakedResources = new Set<string>();
const testVM = getVMManifest(
ProvisionSource.CONTAINER,
testName,
`snapshotresourcevm-${getRandStr(5)}`,
);
const vm = new VirtualMachine(testVM.metadata);

beforeAll(async () => {
createResource(testVM);
addLeakableResource(leakedResources, testVM);
});

afterAll(() => {
removeLeakedResources(leakedResources);
});

it(
'ID(CNV-4717) create, restore and delete a snapshot',
async () => {
await vm.navigateToSnapshots();
await click(editVMSnapshotsView.addSnapshotBtn);
await editVMSnapshotsView.snapshotNameInput
.clear()
.then(() => editVMSnapshotsView.snapshotNameInput.sendKeys(TEST_SNAPSHOT));
if (editVMSnapshotsView.approveUnsupportedCheckbox.isPresent()) {
await click(editVMSnapshotsView.approveUnsupportedCheckbox);
}
await click(saveButton);

// wait for snapshot to be ready
await browser.wait(
until.textToBePresentInElement(editVMSnapshotsView.getStatusElement(TEST_SNAPSHOT), READY),
);

// restore and wait for completion
await click(editVMSnapshotsView.getRestoreButton(TEST_SNAPSHOT));
await click(editVMSnapshotsView.restoreModalButton);

await browser.wait(
until.not(
until.textToBePresentInElement(
editVMSnapshotsView.getRestoreTimestamp(TEST_SNAPSHOT),
'-',
),
),
);

// delete snapshot
await listViewAction(TEST_SNAPSHOT)(editVMSnapshotsView.DELETE_SNAPSHOT_TEXT, true);
await browser.wait(
until.textToBePresentInElement(
editVMSnapshotsView.snapshotStatusBox,
editVMSnapshotsView.EMPTY_SNAPSHOTS_TEXT,
),
);
},
VM_CREATE_AND_EDIT_TIMEOUT_SECS,
);
});
@@ -0,0 +1,13 @@
import { $ } from 'protractor';

export const addSnapshotBtn = $('#add-snapshot');
export const snapshotNameInput = $('#snapshot-name');
export const snapshotStatusBox = $('.cos-status-box');
export const restoreModalButton = $('#confirm-action');
export const approveUnsupportedCheckbox = $('#approve-checkbox');
export const getStatusElement = (snapName) => $(`#${snapName}-snapshot-status`);
export const getRestoreButton = (snapName) => $(`#${snapName}-restore-btn`);
export const getRestoreTimestamp = (snapName) => $(`#${snapName}-restore-time`);

export const DELETE_SNAPSHOT_TEXT = 'Delete Virtual Machine Snapshot';
export const EMPTY_SNAPSHOTS_TEXT = 'No Snapshots found';
3 changes: 2 additions & 1 deletion frontend/packages/kubevirt-plugin/package.json
Expand Up @@ -36,7 +36,8 @@
],
"kubevirt-gating": [
"integration-tests/tests/example.scenario.ts",
"integration-tests/tests/vm.action.base.scenario.ts"
"integration-tests/tests/vm.action.base.scenario.ts",
"integration-tests/tests/vm.tab.snapshots.scenario.ts"
]
}
}
Expand Down
Expand Up @@ -53,14 +53,15 @@ export const VMSnapshotSimpleRow: React.FC<VMSnapshotSimpleRowProps> = ({
<TableData className={dimensify()}>
<Timestamp timestamp={getCreationTimestamp(snapshot)} />
</TableData>
<TableData className={dimensify()}>
<TableData id={`${snapshotName}-snapshot-status`} className={dimensify()}>
<VMSnapshotStatus snapshot={snapshot} restore={relevantRestore} />
</TableData>
<TableData className={dimensify()}>
<TableData id={`${snapshotName}-restore-time`} className={dimensify()}>
{relevantRestore ? <Timestamp timestamp={getVmRestoreTime(relevantRestore)} /> : DASH}
</TableData>
<TableData className={dimensify()}>
<Button
id={`${snapshotName}-restore-btn`}
variant="secondary"
onClick={() => snapshotRestoreModal({ snapshot })}
isDisabled={
Expand Down

0 comments on commit 29ed70d

Please sign in to comment.