Skip to content

Commit

Permalink
Bug 1861957: Overhaul kubevirt plugin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gouyang committed Jul 31, 2020
1 parent 70846a1 commit cab4a83
Show file tree
Hide file tree
Showing 22 changed files with 87 additions and 187 deletions.
8 changes: 6 additions & 2 deletions frontend/packages/console-shared/src/test-utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export function removeLeakedResources(leakedResources: Set<string>) {
.map((r) => JSON.parse(r) as { name: string; namespace: string; kind: string })
.forEach(({ name, namespace, kind }) => {
try {
execSync(`kubectl delete -n ${namespace} --cascade ${kind} ${name}`);
execSync(
`kubectl delete --ignore-not-found=true -n ${namespace} --cascade ${kind} ${name}`,
);
} catch (error) {
console.error(`Failed to delete ${kind} ${name}:\n${error}`);
}
Expand Down Expand Up @@ -46,6 +48,8 @@ export function removeLeakableResource(leakedResources: Set<string>, resource) {
}

export function createResource(resource) {
// ensure not return error even the source is existed by deleting it before adding it
execSync(`echo '${JSON.stringify(resource)}' | kubectl delete --ignore-not-found=true -f -`);
execSync(`echo '${JSON.stringify(resource)}' | kubectl create -f -`);
}

Expand All @@ -56,7 +60,7 @@ export function createResources(resources) {
export function deleteResource(resource) {
const kind = resource.kind === 'NetworkAttachmentDefinition' ? 'net-attach-def' : resource.kind;
execSync(
`kubectl delete -n ${resource.metadata.namespace} --cascade ${kind} ${resource.metadata.name}`,
`kubectl delete --ignore-not-found=true -n ${resource.metadata.namespace} --cascade ${kind} ${resource.metadata.name}`,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,18 @@ export const computedVMBuilders = deepFreeze(
),
);

export const getBasicVMBuilder = () =>
export const getBasicVMBuilder = (namespace?: string) =>
new VMBuilder()
.setNamespace(testName)
.setNamespace(namespace || testName)
.setDescription('Default vm description')
.setFlavor(flavorConfigs.Tiny)
.setOS(OperatingSystem.RHEL7)
.setWorkload(Workload.DESKTOP)
.setStartOnCreation(false);

export const getBasicVMTBuilder = () =>
export const getBasicVMTBuilder = (namespace?: string) =>
new VMTemplateBuilder()
.setNamespace(testName)
.setNamespace(namespace || testName)
.setDescription('Default vmt description')
.setFlavor(flavorConfigs.Tiny)
.setOS(OperatingSystem.RHEL7)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class KubevirtUIResource<T extends BaseVMBuilderData> extends UIResource
await isLoaded();
}

async navigateToConsoles() {
async navigateToConsole() {
await this.navigateToTab(TAB.Console);
await isLoaded();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import {
import { isLoaded, resourceRows } from '@console/internal-integration-tests/views/crud.view';
import { restrictedAccessBlock } from '../views/vms.list.view';
import { createProject } from './utils/utils';
import {
JASMINE_EXTENDED_TIMEOUT_INTERVAL,
PAGE_LOAD_TIMEOUT_SECS,
} from './utils/constants/common';
import { PAGE_LOAD_TIMEOUT_SECS, VM_CREATE_AND_EDIT_TIMEOUT_SECS } from './utils/constants/common';
import { VM_STATUS, VM_ACTION } from './utils/constants/vm';
import { VMBuilder } from './models/vmBuilder';
import { getBasicVMBuilder } from './mocks/vmBuilderPresets';
Expand All @@ -32,7 +29,7 @@ const {

describe('Kubevirt non-admin Flow', () => {
const leakedResources = new Set<string>();
const vm = new VMBuilder(getBasicVMBuilder())
const vm = new VMBuilder(getBasicVMBuilder(testNonAdminNamespace))
.setProvisionSource(provisionSources.URL)
.setDisks([rootDisk])
.build();
Expand All @@ -47,13 +44,13 @@ describe('Kubevirt non-admin Flow', () => {

afterAll(async () => {
removeLeakedResources(leakedResources);
execSync(`kubectl delete project ${testNonAdminNamespace}`);
execSync(`kubectl delete --ignore-not-found=true project ${testNonAdminNamespace}`);
await loginView.logout();
await loginView.login(KUBEADMIN_IDP, KUBEADMIN_USERNAME, BRIDGE_KUBEADMIN_PASSWORD);
});

it(
'ID(CNV-1718) non-admin create and remove a vm',
'ID(CNV-1718) Non-admin create and remove a vm in its own namespace',
async () => {
await vm.create();
await withResource(
Expand All @@ -71,13 +68,12 @@ describe('Kubevirt non-admin Flow', () => {
);
removeLeakableResource(leakedResources, vm.asResource());
},
JASMINE_EXTENDED_TIMEOUT_INTERVAL,
VM_CREATE_AND_EDIT_TIMEOUT_SECS,
);

it('ID(CNV-1720) non-admin cannot create vm in foreign namespace', async () => {
// Navigate to Virtual Machines page with foreign default namespace
it('ID(CNV-1720) Non-admin cannot create vm in a foreign namespace', async () => {
// Check access is restricted on foreign namespace.
await browser.get(`${appHost}/k8s/ns/default/virtualmachines`);
// Check to make sure Access is Restricted.
await browser.wait(until.textToBePresentInElement(restrictedAccessBlock, 'Restricted Access'));
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { execSync } from 'child_process';

export const { STORAGE_CLASS = 'rook-ceph-block' } = process.env;
export const { STORAGE_CLASS = 'standard' } = process.env;

const rhelTinyCommonTemplateName = execSync(
"kubectl get template -n openshift | grep rhel7-desktop-tiny | awk '{print $1}'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('Test VM actions', () => {
async () => {
pauseVM(vmName, testName);
await vm.listViewAction(VM_ACTION.Unpause);
await vm.waitForStatus(VM_STATUS.Running);
},
VM_ACTIONS_TIMEOUT_SECS,
);
Expand Down Expand Up @@ -118,7 +119,9 @@ describe('Test VM actions', () => {
'ID(CNV-1794) Unpauses VM',
async () => {
pauseVM(vmName, testName);
await vm.waitForStatus(VM_STATUS.Paused);
await vm.detailViewAction(VM_ACTION.Unpause);
await vm.waitForStatus(VM_STATUS.Running);
},
VM_ACTIONS_TIMEOUT_SECS,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('Test clone VM.', () => {
});

afterAll(() => {
execSync(`kubectl delete namespace ${testCloningNamespace}`);
execSync(`kubectl delete --ignore-not-found=true namespace ${testCloningNamespace}`);
});

describe('Test Clone VM dialog validation', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { VM_STATUS } from './utils/constants/vm';
import { NodePortService } from './types/types';
import { OperatingSystem, Workload } from './utils/constants/wizard';

describe('Test VM overview', () => {
describe('Kubevirt VM details tab', () => {
const vmName = `vm-${testName}`;
const cloudInit = `#cloud-config\nuser: cloud-user\npassword: atomic\nchpasswd: {expire: False}`;
const serviceCommon = { name: vmName, kind: 'vm', type: 'NodePort', namespace: testName };
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('Test VM overview', () => {
await vm.navigateToDetail();
});

it('ID(CNV-763) Check VM details in overview when VM is off', async () => {
it('ID(CNV-763) Check VM details when VM is off', async () => {
const expectation = {
name: vmName,
status: VM_STATUS.Off,
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('Test VM overview', () => {
});

it(
'ID(CNV-4037) Check VM details in overview when VM is running',
'ID(CNV-4037) Check VM details when VM is running',
async () => {
await vm.start();
// Empty fields turn into non-empty
Expand All @@ -109,7 +109,7 @@ describe('Test VM overview', () => {
VM_BOOTUP_TIMEOUT_SECS,
);

it('ID(CNV-2081) Check exposed vm services', async () => {
it('ID(CNV-2081) Check exposed services', async () => {
await asyncForEach(nodePortServices, async (srv) => {
expect(await vmView.vmDetailService(srv.exposeName).getText()).toEqual(srv.exposeName);
expect(await vmView.vmDetailService(srv.exposeName).getAttribute('href')).toContain(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@ describe('KubeVirt VM detail - Boot Order Dialog', () => {
beforeAll(async () => {
createResource(testVM);
await vm.addDisk(hddDisk);
await vm.navigateToDetail();
});

afterAll(() => {
deleteResource(testVM);
});

beforeEach(async () => {
await vm.navigateToDetail();
await vm.modalEditBootOrder();
});

afterEach(async () => {
await vm.closeModalDialog();
});
Expand All @@ -51,6 +47,7 @@ describe('KubeVirt VM detail - Boot Order Dialog', () => {
it(
'ID(CNV-3549) Deletes bootable device',
async () => {
await vm.modalEditBootOrder();
const FIRST_DEVICE_POSITION = 1;
const initialBootableDevices = getBootableDevicesInOrder(vm.getResource());
await click(bootOrderView.deleteDeviceButton(FIRST_DEVICE_POSITION));
Expand All @@ -75,6 +72,7 @@ describe('KubeVirt VM detail - Boot Order Dialog', () => {
it(
'ID(CNV-3548) Adds bootable device',
async () => {
await vm.modalEditBootOrder();
const initialVMObject = vm.getResource();
const initialBootableDevices = getBootableDevicesInOrder(initialVMObject);
const nonBootableDevices = getNonBootableDevices(initialVMObject).map(
Expand Down Expand Up @@ -113,13 +111,14 @@ describe('KubeVirt VM detail - Boot Order Dialog', () => {
it(
'ID(CNV-3547) Drags and drops to change boot order',
async () => {
await vm.modalEditBootOrder();
const initialBootableDevices = getBootableDevicesInOrder(vm.getResource()).map(
(device) => `${_.get(device, 'value.name')}`,
);

// Find devices at indexes 0 and 1 representing first and second device
const source = bootOrderView.draggablePointer(0);
const destination = bootOrderView.draggablePointer(1);
const source = bootOrderView.draggablePointer(1);
const destination = bootOrderView.draggablePointer(2);

await browser.executeScript(dragAndDrop, source, destination);
// Wait for the DOM structure to update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('KubeVirt VM detail - edit Dedicated Resources', () => {
});

it(
'ID(CNV-3731) enables dedicated resources guaranteed policy, then disables it',
'ID(CNV-3731) Enables dedicated resources guaranteed policy, then disables it',
async () => {
await vm.navigateToDetail();
await vm.modalEditDedicatedResources();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('KubeVirt VM detail - edit flavor', () => {
});

it(
'ID(CNV-3076) changes tiny to custom',
'ID(CNV-3076) Changes tiny to custom',
async () => {
await vm.create();
await withResource(leakedResources, vm.asResource(), async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ describe('KubeVirt VM scheduling', () => {
await editAffinityView.affinityKeyInputByID('expression', 0).sendKeys('key1');
await click(editAffinityView.valuesSelectElement.first());
await editAffinityView.valuesSelectElement.sendKeys(labels.key1);
await click(editAffinityView.createValueBtn);
await click(editAffinityView.createValueBtn(labels.key1));

await click(editAffinityView.addLabelBtn.get(1));
await editAffinityView.affinityKeyInputByID('field', 0).sendKeys('metadata.name');
await click(editAffinityView.valuesSelectElement.get(1));
await editAffinityView.valuesSelectElement.get(1).sendKeys(fields['metadata.name']);
await click(editAffinityView.createValueBtn);
await click(editAffinityView.createValueBtn(fields['metadata.name']));

await click(editAffinityView.editSubmitBtn);
await click(saveButton);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { testName } from '@console/internal-integration-tests/protractor.conf';
import { createResource, deleteResource } from '@console/shared/src/test-utils/utils';
import { getVMManifest } from './mocks/mocks';
import { PAGE_LOAD_TIMEOUT_SECS } from './utils/constants/common';
import { VM_STATUS } from './utils/constants/vm';
import { VM_ACTION, VM_STATUS } from './utils/constants/vm';
import { VirtualMachine } from './models/virtualMachine';
import { filterCount } from '../views/vms.list.view';
import { browser } from 'protractor';
Expand All @@ -12,21 +12,25 @@ describe('Test List View Filtering', () => {
const testVM = getVMManifest('URL', testName);
const vm = new VirtualMachine(testVM.metadata);

beforeAll(() => {
createResource(testVM);
});

afterAll(() => {
deleteResource(testVM);
});

it('ID(CNV-3614) Displays correct count of Importing VMs', async () => {
it('ID(CNV-3614) Displays correct count of Pending VMs', async () => {
await vm.navigateToListView();
// Create the VM after navigating to the list view because importing phase is very short
createResource(testVM);
await browser.wait(waitForFilterCount(VM_STATUS.Importing, 1), PAGE_LOAD_TIMEOUT_SECS);
const importingCount = await filterCount(VM_STATUS.Importing);
await vm.action(VM_ACTION.Start, false);
await browser.wait(waitForFilterCount(VM_STATUS.Pending, 1), PAGE_LOAD_TIMEOUT_SECS);
const importingCount = await filterCount(VM_STATUS.Pending);
expect(importingCount).toEqual(1);
await vm.waitForStatus(VM_STATUS.Running);
});

it('ID(CNV-3615) Displays correct count of Off VMs', async () => {
await vm.waitForStatus(VM_STATUS.Off);
await vm.stop();
await vm.navigateToListView();
const offCount = await filterCount(VM_STATUS.Off);
expect(offCount).toEqual(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('KubeVirt VM console - RDP', () => {
const vmName = 'windows-rdp';

// for cmd-line scripts only
execSync(`kubectl config set-context --current --namespace=${testName}`, { stdio: 'inherit' });
execSync(`kubectl config set-context --current --namespace=${testName}`);
execSync('kubectl create -f -', {
input: getWindowsVM({
name: vmName,
Expand All @@ -56,13 +56,13 @@ describe('KubeVirt VM console - RDP', () => {
afterAll(async () => {
deleteResource(multusNAD);
deleteResource(vm.asResource());
execSync(`kubectl config set-context --current --namespace=default`, { stdio: 'inherit' });
execSync(`kubectl config set-context --current --namespace=default`);
});

it(
'ID(CNV-1721) connects via exposed service',
async () => {
await vm.navigateToConsoles();
await vm.navigateToConsole();
await browser.wait(until.presenceOf(consoleTypeSelector));
await click(consoleTypeSelector);
await browser.wait(
Expand All @@ -84,7 +84,6 @@ describe('KubeVirt VM console - RDP', () => {
// the next command follows recommendation by documentation
execSync(
`virtctl expose virtualmachine ${vm.name} --name ${vm.name}-rdp --port 4567 --target-port 3389 --type NodePort`,
{ stdio: 'inherit' },
);

await browser.wait(until.presenceOf(desktopClientTitle));
Expand Down Expand Up @@ -138,17 +137,13 @@ describe('KubeVirt VM console - RDP', () => {
*/

await vm.navigateToDetail();
// eslint-disable-next-line no-console
console.log(
'Waiting for static IP to be reported by the guest-agent (can take up to several minutes ...)',
);
// Waiting for instllation & start of the guest-agent and reporting the static IP back
await browser.wait(
waitForStringInElement(vmDetailIP(vm.namespace, vm.name), VM_IP),
VM_CREATE_AND_EDIT_AND_CLOUDINIT_TIMEOUT_SECS,
);

await vm.navigateToConsoles();
await vm.navigateToConsole();

await browser.wait(until.presenceOf(consoleTypeSelector));
await click(consoleTypeSelector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import { VirtualMachine } from './models/virtualMachine';
import { ProvisionSource } from './utils/constants/wizard';
import { getVMManifest } from './mocks/mocks';

describe('KubeVirt VM VNC/Serial consoles', () => {
const vmResource = getVMManifest(ProvisionSource.CONTAINER, testName, 'cirros-vm');
describe('KubeVirt VM console - VNC/Serial', () => {
const vmResource = getVMManifest(ProvisionSource.URL, testName, 'cirros-vm');
const vm = new VirtualMachine(vmResource.metadata);
const cirrosUsername = 'cirros';
const cirrosPassword = 'gocubsgo';
Expand All @@ -53,7 +53,7 @@ describe('KubeVirt VM VNC/Serial consoles', () => {
await vm.detailViewAction(VM_ACTION.Start);
// wait for the VM to boot up
execSync(`expect ${expectLoginScriptPath} ${vm.name} ${vm.namespace}`);
await vm.navigateToConsoles();
await vm.navigateToConsole();
}, VM_BOOTUP_TIMEOUT_SECS);

afterAll(async () => {
Expand Down

0 comments on commit cab4a83

Please sign in to comment.