Skip to content

Commit

Permalink
Bug 1856622: Add integration test for vm scheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
wulax committed Jul 17, 2020
1 parent dddbe9e commit 3c88312
Show file tree
Hide file tree
Showing 12 changed files with 306 additions and 237 deletions.

This file was deleted.

@@ -0,0 +1,49 @@
/* eslint-disable no-await-in-loop */
import * as view from '../../views/dialogs/editLabelView';
import { asyncForEach, click, fillInput } from '@console/shared/src/test-utils/utils';
import { MatchLabels } from '@console/internal/module/k8s';

export class AddDialog {
private extractID(id: string) {
return id.split('-')[1];
}

/**
* Adds new row if needed.
* Returns string with index of next empty row.
*/
async addRow(placeholder: string): Promise<string> {
if ((await view.emptyKeyInputs(placeholder).count()) === 0) {
await click(view.addLabelBtn);
}
return this.extractID(
await view
.emptyKeyInputs(placeholder)
.first()
.getAttribute('id'),
);
}

async addLabel(name: string, placeholder: string, key: string, value: string) {
const id = await this.addRow(placeholder);
await fillInput(view.keyInputByID(name, id), key);
await fillInput(view.valueInputByID(name, id), value);
}

async addLabels(name: string, placeholder: string, labels: MatchLabels) {
for (const [key, value] of Object.entries(labels)) {
await this.addLabel(name, placeholder, key, value);
}
}

async deleteLabel(name: string, placeholder: string, value: string) {
const id = this.extractID(await view.keyInputByKey(placeholder, value).getAttribute('id'));
await click(view.deleteBtnByID(name, id));
}

async deleteLabels(name: string, placeholder: string, labels: MatchLabels) {
return asyncForEach(Object.keys(labels), async (key: string) => {
await this.deleteLabel(name, placeholder, key);
});
}
}
Expand Up @@ -4,20 +4,20 @@ import { browser, ExpectedConditions as until } from 'protractor';
import {
waitForStringNotInElement,
click,
asyncForEach,
waitForStringInElement,
} from '@console/shared/src/test-utils/utils';
import { detailViewAction, listViewAction } from '@console/shared/src/test-utils/actions.view';
import { VirtualMachineModel } from '@console/kubevirt-plugin/src/models';
import { annotationDialogOverlay } from '@console/internal-integration-tests/views/modal-annotations.view';
import * as vmView from '../../views/virtualMachine.view';
import {
VM_MIGRATION_TIMEOUT_SECS,
PAGE_LOAD_TIMEOUT_SECS,
UNEXPECTED_ACTION_ERROR,
VM_BOOTUP_TIMEOUT_SECS,
VM_MIGRATION_TIMEOUT_SECS,
} from '../utils/constants/common';
import { BaseVirtualMachine } from './baseVirtualMachine';
import { NodeSelectorDialog } from '../dialogs/nodeSelectorDialog';
import { AddDialog } from '../dialogs/schedulingDialog';
import { saveButton } from '../../views/kubevirtUIResource.view';
import { VMBuilderData } from '../types/vm';
import { VM_ACTION, TAB, VM_STATUS } from '../utils/constants/vm';
Expand Down Expand Up @@ -78,30 +78,42 @@ export class VirtualMachine extends BaseVirtualMachine {
);
}

async addNodeSelectors(labels: MatchLabels) {
const nodeSelectorDialog = new NodeSelectorDialog();
async nodeSelectorsAction(action: string, labels: MatchLabels) {
const dialog = new AddDialog();
await this.navigateToDetail();
await this.modalEditNodeSelector();
await nodeSelectorDialog.addLabels(labels);
switch (action) {
case 'add':
await dialog.addLabels('label', 'key', labels);
break;
case 'delete':
await dialog.deleteLabels('label', 'key', labels);
break;
default:
throw Error(UNEXPECTED_ACTION_ERROR);
}
await click(saveButton);
await browser.wait(until.invisibilityOf(annotationDialogOverlay), PAGE_LOAD_TIMEOUT_SECS);
}

async deleteNodeSelector(key: string) {
const nodeSelectorDialog = new NodeSelectorDialog();
async tolerationsAction(action: string, labels: MatchLabels) {
const dialog = new AddDialog();
await this.navigateToDetail();
await this.modalEditNodeSelector();
await nodeSelectorDialog.deleteLabel(key);
await this.modalEditTolerations();
switch (action) {
case 'add':
await dialog.addLabels('toleration', 'taint key', labels);
break;
case 'delete':
await dialog.deleteLabels('toleration', 'taint key', labels);
break;
default:
throw Error(UNEXPECTED_ACTION_ERROR);
}
await click(saveButton);
await browser.wait(until.invisibilityOf(annotationDialogOverlay), PAGE_LOAD_TIMEOUT_SECS);
}

async deleteNodeSelectors(keys: string[]) {
return asyncForEach(keys, async (key: string) => {
await this.deleteNodeSelector(key);
});
}

async start(waitForAction = true) {
await this.action(VM_ACTION.Start, waitForAction);
}
Expand Down
Expand Up @@ -22,6 +22,7 @@ import { STORAGE_CLASS, PAGE_LOAD_TIMEOUT_SECS, SEC } from './constants/common';
import { NodePortService, Status } from '../types/types';
import { filterCount } from '../../views/vms.list.view';
import { diskVolumeMode, diskAccessMode } from './constants/vm';
import { MatchLabels } from '@console/internal/module/k8s';

export async function setCheckboxState(elem: any, targetState: boolean) {
const checkboxState = await elem.isSelected();
Expand Down Expand Up @@ -217,3 +218,34 @@ export function deepFreeze(o: {}) {
});
return o;
}

export function getNodes() {
const nodes = execSync(`kubectl get node -l cpumanager=true | awk 'NR>1{print $1}'`)
.toString()
.trim();
return nodes.split('\n');
}

export function labelNode(node: string, labels: MatchLabels, add?: boolean) {
if (add) {
for (const [key, value] of Object.entries(labels)) {
execSync(`kubectl label --overwrite=true nodes ${node} ${key}=${value}`);
}
} else {
for (const key of Object.keys(labels)) {
execSync(`kubectl label nodes ${node} ${key}-`);
}
}
}

export function taintNode(node: string, labels: MatchLabels, effect: string, add?: boolean) {
if (add) {
for (const [key, value] of Object.entries(labels)) {
execSync(`kubectl taint --overwrite=true nodes ${node} ${key}=${value}:${effect}`);
}
} else {
for (const key of Object.keys(labels)) {
execSync(`kubectl taint nodes ${node} ${key}:${effect}-`);
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 3c88312

Please sign in to comment.