Skip to content

Commit

Permalink
Merge pull request #6152 from gouyang/fix_bootorder
Browse files Browse the repository at this point in the history
Bug 1861957: Overhaul kubevirt plugin tests
  • Loading branch information
openshift-merge-robot committed Aug 17, 2020
2 parents 99788a2 + 4560b49 commit 0c53fd2
Show file tree
Hide file tree
Showing 25 changed files with 100 additions and 229 deletions.
12 changes: 9 additions & 3 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 @@ -53,10 +55,14 @@ export function createResources(resources) {
resources.forEach(createResource);
}

export function deleteResource(resource) {
export function applyResource(resource) {
execSync(`echo '${JSON.stringify(resource)}' | kubectl apply -f -`);
}

export function deleteResource(resource, ignoreNotFound = true) {
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=${ignoreNotFound} -n ${resource.metadata.namespace} --cascade ${kind} ${resource.metadata.name}`,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
switchClusterNamespace,
} from '../../views/uiResource.view';
import * as vmsListView from '../../views/vms.list.view';
import * as editBootOrder from '../../views/dialogs/editBootOrderView';
import * as editDedicatedResourcesView from '../../views/dialogs/editDedicatedResourcesView';
import * as editStatusView from '../../views/dialogs/editStatusView';
import { NetworkInterfaceDialog } from '../dialogs/networkInterfaceDialog';
Expand Down Expand Up @@ -109,7 +108,7 @@ export class KubevirtUIResource<T extends BaseVMBuilderData> extends UIResource
await isLoaded();
}

async navigateToConsoles() {
async navigateToConsole() {
await this.navigateToTab(TAB.Console);
await isLoaded();
}
Expand Down Expand Up @@ -137,6 +136,7 @@ export class KubevirtUIResource<T extends BaseVMBuilderData> extends UIResource
return {
name: cols[diskTabCol.name],
size: cols[diskTabCol.size].slice(0, -4),
drive: cols[diskTabCol.drive],
interface: cols[diskTabCol.interface],
storageClass: cols[diskTabCol.storageClass],
};
Expand Down Expand Up @@ -164,6 +164,7 @@ export class KubevirtUIResource<T extends BaseVMBuilderData> extends UIResource
await click(kubevirtDetailView.createDiskButton);
const dialog = new DiskDialog();
await dialog.create(disk);
await isLoaded();
await browser.wait(until.and(waitForCount(resourceRows, count + 1)), PAGE_LOAD_TIMEOUT_SECS);
}

Expand All @@ -172,6 +173,7 @@ export class KubevirtUIResource<T extends BaseVMBuilderData> extends UIResource
const count = await resourceRows.count();
await kubevirtDetailView.selectKebabOption(name, 'Delete');
await confirmAction();
await isLoaded();
await browser.wait(until.and(waitForCount(resourceRows, count - 1)), PAGE_LOAD_TIMEOUT_SECS);
}

Expand All @@ -181,6 +183,7 @@ export class KubevirtUIResource<T extends BaseVMBuilderData> extends UIResource
await click(kubevirtDetailView.createNICButton);
const dialog = new NetworkInterfaceDialog();
await dialog.create(nic);
await isLoaded();
await browser.wait(until.and(waitForCount(resourceRows, count + 1)), PAGE_LOAD_TIMEOUT_SECS);
}

Expand All @@ -189,6 +192,7 @@ export class KubevirtUIResource<T extends BaseVMBuilderData> extends UIResource
const count = await resourceRows.count();
await kubevirtDetailView.selectKebabOption(name, 'Delete');
await confirmAction();
await isLoaded();
await browser.wait(until.and(waitForCount(resourceRows, count - 1)), PAGE_LOAD_TIMEOUT_SECS);
}

Expand All @@ -200,7 +204,7 @@ export class KubevirtUIResource<T extends BaseVMBuilderData> extends UIResource

async modalEditBootOrder() {
await click(vmDetailBootOrderEditButton(this.namespace, this.name));
await browser.wait(until.presenceOf(editBootOrder.bootOrderDialog));
await browser.wait(until.presenceOf(kubevirtDetailView.modalTitle));
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 @@ -33,6 +30,7 @@ const {
describe('Kubevirt non-admin Flow', () => {
const leakedResources = new Set<string>();
const vm = new VMBuilder(getBasicVMBuilder())
.setNamespace(testNonAdminNamespace)
.setProvisionSource(provisionSources.URL)
.setDisks([rootDisk])
.build();
Expand All @@ -47,13 +45,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 +69,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 @@ -117,7 +117,8 @@ export const diskTabCol = {
name: 0,
source: 1,
size: 2,
interface: 3,
storageClass: 4,
drive: 3,
interface: 4,
storageClass: 5,
};
Object.freeze(diskTabCol);
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

0 comments on commit 0c53fd2

Please sign in to comment.