Skip to content

Commit

Permalink
Merge pull request #2517 from mareklibra/editVmFlavor.tests
Browse files Browse the repository at this point in the history
kubevirt: Add edit VM flavor integration test
  • Loading branch information
openshift-merge-robot committed Oct 1, 2019
2 parents 5310054 + c54d778 commit 07d3e8f
Show file tree
Hide file tree
Showing 13 changed files with 291 additions and 86 deletions.
Expand Up @@ -3,6 +3,7 @@ import { appHost, testName } from '../../../../../integration-tests/protractor.c
import { clickHorizontalTab } from '../../../../../integration-tests/views/horizontal-nav.view';
import { isLoaded, resourceTitle } from '../../../../../integration-tests/views/crud.view';
import { activeTab } from '../../views/detailView.view';
import * as VmsListView from '../../views/vms.list.view';

export class DetailView {
readonly name: string;
Expand Down Expand Up @@ -32,6 +33,15 @@ export class DetailView {
}
}

// Similar to navigateToTab(TABS.OVERVIEW) but passes through resource list page
async navigateToDetail() {
await this.navigateToListView();
await VmsListView.vmListByName(this.name).click();
await isLoaded();
await clickHorizontalTab('Overview');
await isLoaded();
}

async navigateToListView() {
const vmsListUrl = (namespace) =>
`${appHost}/k8s/${namespace === 'all-namespaces' ? '' : 'ns/'}${namespace}/${this.kind}`;
Expand Down
@@ -0,0 +1,10 @@
import { $ } from 'protractor';

export const flavorDropdownId = '#vm-flavor-modal-flavor-dropdown';

export const modalTitle = () => $('.modal-title');
export const flavorDropdownText = () =>
$('.kubevirt-vm-flavor-modal__dropdown .pf-c-dropdown__toggle-text');
export const saveButton = () => $('#confirm-action');
export const cpusInput = () => $('#vm-flavor-modal-cpu');
export const memoryInput = () => $('#vm-flavor-modal-memory');
Expand Up @@ -11,7 +11,9 @@ import { StorageResource, NetworkResource } from '../utils/types';
import { fillInput } from '../utils/utils';
import * as kubevirtDetailView from '../../views/kubevirtDetailView.view';
import { confirmAction } from '../../views/vm.actions.view';
import { vmDetailFlavorEditButton } from '../../views/virtualMachine.view';
import { DetailView } from './detailView';
import * as editFlavor from './editFlavorView';

export class KubevirtDetailView extends DetailView {
async getAttachedDisks(): Promise<StorageResource[]> {
Expand Down Expand Up @@ -77,4 +79,10 @@ export class KubevirtDetailView extends DetailView {
await confirmAction();
await browser.wait(until.and(waitForCount(resourceRows, count - 1)), PAGE_LOAD_TIMEOUT_SECS);
}

// pops-up modal dialog
async modalEditFlavor() {
await click(vmDetailFlavorEditButton(this.namespace, this.name));
await browser.wait(until.presenceOf(editFlavor.modalTitle()));
}
}
Expand Up @@ -13,6 +13,7 @@ export const VM_MIGRATION_TIMEOUT_SECS = 190 * SEC;
export const VM_STOP_TIMEOUT_SECS = 10 * SEC;
export const VM_IP_ASSIGNMENT_TIMEOUT_SECS = 180 * SEC;
export const WINDOWS_IMPORT_TIMEOUT_SECS = 150 * SEC;
export const VM_CREATE_AND_EDIT_TIMEOUT_SECS = 200 * SEC;

export const POD_CREATION_TIMEOUT_SECS = 40 * SEC;
export const POD_TERMINATION_TIMEOUT_SECS = 30 * SEC;
Expand Down
Expand Up @@ -49,3 +49,9 @@ export type VMConfig = {
storageResources: StorageResource[];
networkResources: NetworkResource[];
};

export type ProvisionConfig = {
provision: ProvisionOption;
networkResources: NetworkResource[];
storageResources: StorageResource[];
};
@@ -0,0 +1,119 @@
import { browser, ExpectedConditions as until } from 'protractor';
import { testName } from '../../../../integration-tests/protractor.conf';
import {
withResource,
selectDropdownOptionById,
click,
} from '../../../console-shared/src/test-utils/utils';
import * as virtualMachineView from '../views/virtualMachine.view';
import { VM_CREATE_AND_EDIT_TIMEOUT_SECS } from './utils/consts';
import { VirtualMachine } from './models/virtualMachine';
import { vmConfig, getProvisionConfigs, CONFIG_NAME_CONTAINER } from './vm.wizard.configs';
import * as editFlavorView from './models/editFlavorView';
import { fillInput } from './utils/utils';

describe('KubeVirt VM detail - edit flavor', () => {
const leakedResources = new Set<string>();
const provisionConfigs = getProvisionConfigs(testName);

const configName = CONFIG_NAME_CONTAINER;
const provisionConfig = provisionConfigs.get(configName);

// not needed for testing flavor
provisionConfig.networkResources = [];
provisionConfig.storageResources = [];

it(
'changes tiny to large',
async () => {
const vm1Config = vmConfig(configName.toLowerCase(), provisionConfig, testName);
vm1Config.startOnCreation = false;

const vm = new VirtualMachine(vmConfig(configName.toLowerCase(), provisionConfig, testName));
await withResource(leakedResources, vm.asResource(), async () => {
await vm.create(vm1Config);
await vm.navigateToDetail();
await browser.wait(
until.textToBePresentInElement(
virtualMachineView.vmDetailFlavor(vm.namespace, vm.name),
'Tiny: 1 vCPU, 1 GB Memory',
),
);
await vm.modalEditFlavor();
await browser.wait(
until.textToBePresentInElement(editFlavorView.flavorDropdownText(), 'Tiny'),
);
await selectDropdownOptionById(editFlavorView.flavorDropdownId, 'large-link');
await browser.wait(
until.textToBePresentInElement(editFlavorView.flavorDropdownText(), 'Large'),
);
await click(editFlavorView.saveButton());

await browser.wait(
until.textToBePresentInElement(
virtualMachineView.vmDetailFlavor(vm.namespace, vm.name),
'Large: 2 vCPUs, 6 GB Memory',
),
);
expect(
await virtualMachineView.vmDetailLabelValue('flavor.template.kubevirt.io/large'),
).toBe('true');
expect(
(await virtualMachineView.vmDetailLabelValue('vm.kubevirt.io/template')).startsWith(
'rhel7-desktop-tiny-', // template is not changed (might be in the future)
),
).toBeTruthy();
});
},
VM_CREATE_AND_EDIT_TIMEOUT_SECS,
);

it(
'changes tiny to custom',
async () => {
const vm1Config = vmConfig(configName.toLowerCase(), provisionConfig, testName);
vm1Config.startOnCreation = false;

const vm = new VirtualMachine(vmConfig(configName.toLowerCase(), provisionConfig, testName));
await withResource(leakedResources, vm.asResource(), async () => {
await vm.create(vm1Config);
await vm.navigateToDetail();
await browser.wait(
until.textToBePresentInElement(
virtualMachineView.vmDetailFlavor(vm.namespace, vm.name),
'Tiny: 1 vCPU, 1 GB Memory',
),
);
await vm.modalEditFlavor();

await browser.wait(
until.textToBePresentInElement(editFlavorView.flavorDropdownText(), 'Tiny'),
);
await selectDropdownOptionById(editFlavorView.flavorDropdownId, 'Custom-link');
await browser.wait(
until.textToBePresentInElement(editFlavorView.flavorDropdownText(), 'Custom'),
);
await fillInput(editFlavorView.cpusInput(), '2');
await fillInput(editFlavorView.memoryInput(), '356');
await click(editFlavorView.saveButton());

await browser.wait(
until.textToBePresentInElement(
virtualMachineView.vmDetailFlavor(vm.namespace, vm.name),
'Custom: 2 vCPUs, 356 MB Memory',
),
);

expect(
await virtualMachineView.vmDetailLabelValue('flavor.template.kubevirt.io/Custom'),
).toBe('true');
expect(
(await virtualMachineView.vmDetailLabelValue('vm.kubevirt.io/template')).startsWith(
'rhel7-desktop-tiny-', // template is not changed (might be in the future)
),
).toBeTruthy();
});
},
VM_CREATE_AND_EDIT_TIMEOUT_SECS,
);
});
@@ -0,0 +1,86 @@
import { OrderedMap } from 'immutable';
import {
basicVmConfig,
networkInterface,
rootDisk,
hddDisk,
dataVolumeManifest,
} from './utils/mocks';
import { StorageResource, ProvisionConfig } from './utils/types';

export const vmConfig = (name: string, provisionConfig, testName: string) => {
const commonSettings = {
startOnCreation: true,
cloudInit: {
useCloudInit: false,
},
namespace: testName,
description: `Default description ${testName}`,
flavor: basicVmConfig.flavor,
operatingSystem: basicVmConfig.operatingSystem,
workloadProfile: basicVmConfig.workloadProfile,
};

return {
...commonSettings,
name: `${name}-${testName}`,
provisionSource: provisionConfig.provision,
storageResources: provisionConfig.storageResources,
networkResources: provisionConfig.networkResources,
};
};

export const getTestDataVolume = (testName: string) =>
dataVolumeManifest({
name: `toclone-${testName}`,
namespace: testName,
sourceURL: basicVmConfig.sourceURL,
});

const getDiskToCloneFrom = (testName: string): StorageResource => {
const testDV = getTestDataVolume(testName);
return {
name: testDV.metadata.name,
size: '1',
storageClass: testDV.spec.pvc.storageClassName,
attached: true,
};
};

export const CONFIG_NAME_URL = 'URL';
export const CONFIG_NAME_CONTAINER = 'Container';
export const CONFIG_NAME_PXE = 'PXE';
export const CONFIG_NAME_CLONED_DISK = 'ClonedDisk';

export const getProvisionConfigs = (testName: string) =>
OrderedMap<string, ProvisionConfig>()
.set(CONFIG_NAME_URL, {
provision: {
method: CONFIG_NAME_URL,
source: basicVmConfig.sourceURL,
},
networkResources: [networkInterface],
storageResources: [rootDisk],
})
.set(CONFIG_NAME_CONTAINER, {
provision: {
method: CONFIG_NAME_CONTAINER,
source: basicVmConfig.sourceContainer,
},
networkResources: [networkInterface],
storageResources: [hddDisk],
})
.set(CONFIG_NAME_PXE, {
provision: {
method: CONFIG_NAME_PXE,
},
networkResources: [networkInterface],
storageResources: [rootDisk],
})
.set(CONFIG_NAME_CLONED_DISK, {
provision: {
method: 'Cloned Disk', // mind the space
},
networkResources: [networkInterface],
storageResources: [getDiskToCloneFrom(testName)],
});

0 comments on commit 07d3e8f

Please sign in to comment.