Skip to content

Commit

Permalink
Bug 1910263: Make existing tests be able to run
Browse files Browse the repository at this point in the history
  • Loading branch information
gouyang committed Dec 23, 2020
1 parent 45f0e68 commit bfaca2d
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,14 @@ describe('KubeVirt Auto Clone', () => {
.setOS(rhel7PVC.os)
.generateNameForPrefix('auto-clone-vm1')
.setStartOnCreation(true)
.setCustomize(true)
.build();

const vm2 = new VMBuilder(getBasicVMBuilder())
.setOS(rhel7PVC.os)
.generateNameForPrefix('auto-clone-vm2')
.setStartOnCreation(true)
.setCustomize(true)
.build();

await withResources(
Expand All @@ -175,6 +177,7 @@ describe('KubeVirt Auto Clone', () => {
.setOS(fedoraPVC.os)
.generateNameForPrefix('auto-clone-vm-with-pvc-deleted')
.setStartOnCreation(false)
.setCustomize(true)
.build();

await withResources(
Expand Down Expand Up @@ -202,6 +205,7 @@ describe('KubeVirt Auto Clone', () => {
.setFlavor(flavorConfigs.Medium)
.generateNameForPrefix('auto-clone-win10-vm')
.setStartOnCreation(true)
.setCustomize(true)
.build();

await withResources(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
resolveStorageDataAttribute,
deepFreeze,
} from '../utils/utils';
import { Flavor } from '../utils/constants/wizard';
import { Flavor, TemplateByName } from '../utils/constants/wizard';
import {
NIC_MODEL,
NIC_TYPE,
Expand Down Expand Up @@ -480,3 +480,7 @@ export const v2vUIDeployment = {
},
};
deepFreeze(v2vUIDeployment);

export const basicCommonTemplate = {
name: TemplateByName.RHEL7,
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
containerRootDisk,
flavorConfigs,
getDiskToCloneFrom,
basicCommonTemplate,
} from './mocks';
import { VirtualMachine } from '../models/virtualMachine';
import { VMTemplateBuilder } from '../models/vmtemplateBuilder';
Expand Down Expand Up @@ -91,6 +92,7 @@ export const getBasicVMBuilder = () =>
new VMBuilder()
.setNamespace(testName)
.setDescription('Default vm description')
.setCommonTemplate(basicCommonTemplate)
.setFlavor(flavorConfigs.Tiny)
.setOS(OperatingSystem.RHEL7)
.setWorkload(Workload.DESKTOP)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cloneDeepWithEnum } from '@console/shared/src/constants/object-enum';
import { OperatingSystem, Workload, OSIDLookup } from '../utils/constants/wizard';
import { FlavorConfig, Disk, Network, CloudInitConfig } from '../types/types';
import { BaseVMBuilderData } from '../types/vm';
import { BaseVMBuilderData, CommonTemplate } from '../types/vm';
import { K8sKind } from '@console/internal/module/k8s';
import { getRandStr } from '../utils/utils';
import { ProvisionSource } from '../utils/constants/enums/provisionSource';
Expand Down Expand Up @@ -61,6 +61,11 @@ export abstract class BaseVMBuilder<T extends BaseVMBuilderData> {
return this;
}

public setCommonTemplate(commonTemplate: CommonTemplate) {
this.data.commonTemplate = commonTemplate;
return this;
}

public setFlavor(flavor: FlavorConfig) {
this.data.flavor = flavor;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export class VMBuilder extends BaseVMBuilder<VMBuilderData> {
return this;
}

public setCustomize(customize: boolean) {
this.data.customize = customize;
return this;
}

build() {
if (!this.getData().name) {
super.generateName();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-await-in-loop */
import { browser, ExpectedConditions as until } from 'protractor';
import { createItemButton, isLoaded } from '@console/internal-integration-tests/views/crud.view';
import { isLoaded } from '@console/internal-integration-tests/views/crud.view';
import { clickNavLink } from '@console/internal-integration-tests/views/sidenav.view';
import { click, fillInput, asyncForEach } from '@console/shared/src/test-utils/utils';
import { K8sKind } from '@console/internal/module/k8s';
Expand Down Expand Up @@ -52,7 +52,7 @@ export class Wizard {
await isLoaded();
}

await click(createItemButton);
await click(view.createItemButton);
await click(view.createWithWizardButton);
await view.waitForNoLoaders();
}
Expand Down Expand Up @@ -86,6 +86,10 @@ export class Wizard {
}
}

async selectTemplate(name: string) {
await click(view.templateByName(name));
}

async fillName(name: string) {
await fillInput(view.nameInput, name);
return checkForError(view.vmNameHelper);
Expand All @@ -100,7 +104,7 @@ export class Wizard {
}

async selectFlavor(flavor: FlavorConfig) {
await selectItemFromDropdown(view.flavorSelect, dropDownItemMain(flavor.flavor));
await selectItemFromDropdown(view.flavorSelect, dropDownItem(flavor.flavor));
if (flavor.flavor === Flavor.CUSTOM && (!flavor.memory || !flavor.cpu)) {
throw Error('Custom Flavor requires memory and cpu values.');
}
Expand Down Expand Up @@ -237,6 +241,24 @@ export class Wizard {
);
}

async processSelectTemplate(data: VMBuilderData, ignoreWarnings: boolean = false) {
const { commonTemplate } = data;
if (commonTemplate) {
await this.selectTemplate(commonTemplate.name);
}
await this.next(ignoreWarnings);
}

async processBootSource(data: VMBuilderData, ignoreWarnings: boolean = false) {
// TODO: add processStep for bootsource
await this.next(ignoreWarnings);
}

async processReviewAndCreate(data: VMBuilderData, ignoreWarnings: boolean = false) {
// TODO: add processStep for review and create
await this.next(ignoreWarnings);
}

async processGeneralStep(data: VMBuilderData, ignoreWarnings: boolean = false) {
const { name, description, provisionSource, os, flavor, workload } = data;
if (name) {
Expand Down Expand Up @@ -322,15 +344,19 @@ export class Wizard {
}

async processWizard(data: VMBuilderData) {
await this.processGeneralStep(data);
await this.processNetworkStep(data);
await this.processStorageStep(data);
await this.processAdvanceStep(data);
await this.processReviewStep(data);

// Create
await this.confirmAndCreate();
await this.waitForCreation();
// TODO check for error and in case of error throw Error
await this.processSelectTemplate(data);
const { customize } = data;
if (customize) {
await click(view.customizeButton);
await this.processGeneralStep(data);
await this.processNetworkStep(data);
await this.processStorageStep(data);
await this.processAdvanceStep(data);
await this.processReviewStep(data);

// Create
await this.confirmAndCreate();
await this.waitForCreation();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('Kubevirt non-admin Flow', () => {
.setNamespace(testNonAdminNamespace)
.setProvisionSource(ProvisionSource.URL)
.setDisks([rootDisk])
.setCustomize(true)
.build();

it(
Expand Down Expand Up @@ -94,6 +95,7 @@ describe('Kubevirt non-admin Flow', () => {
.setNamespace(testNonAdminNamespace)
.setOS(pvc.os)
.setStartOnCreation(true)
.setCustomize(true)
.generateNameForPrefix('auto-clone-vm-with-normal-user')
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,9 @@ export const VirtualMachineTemplateModel: K8sKind = {
kind: 'Template',
id: 'template',
};

export type DiskAdvance = {
StorageClass?: string;
AccessMode?: string;
VolumeMode?: string;
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FlavorConfig, Network, Disk, CloudInitConfig } from './types';
import { FlavorConfig, Network, Disk, CloudInitConfig, DiskAdvance } from './types';
import { V1Disk } from '../../../src/types/vm/disk/V1Disk';
import { V1Volume } from '../../../src/types/vm/disk/V1Volume';
import { V1alpha1DataVolume } from '../../../src/types/vm/disk/V1alpha1DataVolume';
Expand All @@ -20,7 +20,15 @@ export type TestDisk = {
pvc?: V1PersistentVolumeClaim;
};

export type CommonTemplate = {
name?: string;
bootSourceAvailable?: boolean;
bootSource?: ProvisionSource;
diskAdvance?: DiskAdvance;
};

export type BaseVMBuilderData = {
commonTemplate?: CommonTemplate;
name?: string;
description?: string;
namespace?: string;
Expand All @@ -38,6 +46,7 @@ export type VMBuilderData = BaseVMBuilderData & {
waitForDiskImport?: boolean;
startOnCreation?: boolean;
template?: string;
customize?: boolean;
};

export type KubevirtResourceConfig = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import { ObjectEnum } from '@console/shared/src/constants/object-enum';
export class ProvisionSource extends ObjectEnum<string> {
static readonly URL = new ProvisionSource(
'URL',
'URL (adds disk)',
'Import via URL (creates PVC)',
'https://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img',
);

static readonly CONTAINER = new ProvisionSource(
'Container',
'Container',
'Import via Registry (creates PVC)',
'kubevirt/fedora-cloud-container-disk-demo:latest',
);

static readonly PXE = new ProvisionSource('PXE', 'PXE (network boot - adds network interface)');

static readonly DISK = new ProvisionSource('Disk', 'Existing PVC (adds disk)');
static readonly DISK = new ProvisionSource('Disk', 'Clone existing PVC (creates PVC)');

private readonly description: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,11 @@ export enum Provider {
RHV = 'Red Hat Virtualisation (RHV)',
VMware = 'VMware',
}

export enum TemplateByName {
RHEL6 = 'Red Hat Enterprise Linux 6.0+ VM',
RHEL7 = 'Red Hat Enterprise Linux 7.0+ VM',
RHEL8 = 'Red Hat Enterprise Linux 8.0+ VM',
FEDORA = 'Fedora 31+ VM',
WINDOWS_10 = 'Microsoft Windows 10 VM',
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ describe('Test clone VM.', () => {
.setDisks([rootDisk])
.setCloudInit(cloudInitCustomScriptConfig)
.setWaitForImport(true)
.setCustomize(true)
.build();
await vm.create();
clonedVM = await vm.clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('Test VM Migration', () => {
const vm = new VMBuilder(getBasicVMBuilder())
.setProvisionSource(ProvisionSource.URL)
.setDisks([rwxRootDisk])
.setCustomize(true)
.generateNameForPrefix('vm-for-migration-test')
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
} from '@console/shared/src/test-utils/utils';
import * as virtualMachineView from '../views/virtualMachine.view';
import { saveButton } from '../views/kubevirtUIResource.view';
import { VM_CREATE_AND_EDIT_TIMEOUT_SECS } from './utils/constants/common';
import * as editFlavorView from '../views/dialogs/editFlavorView';
import { selectOptionByText } from './utils/utils';
import { getCPU, getMemory } from '../../src/selectors/vm/selectors';
Expand All @@ -18,33 +17,30 @@ describe('KubeVirt VM detail - edit flavor', () => {
const leakedResources = new Set<string>();
const vm = new VMBuilder(getBasicVMBuilder())
.setProvisionSource(ProvisionSource.CONTAINER)
.setCustomize(true)
.build();

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

it(
'ID(CNV-3076) Changes tiny to custom',
async () => {
await vm.create();
await withResource(leakedResources, vm.asResource(), async () => {
await vm.navigateToDetail();
await vm.modalEditFlavor();
await selectOptionByText(editFlavorView.flavorDropdown, 'Custom');
await fillInput(editFlavorView.cpusInput(), '2');
await fillInput(editFlavorView.memoryInput(), '3');
await click(saveButton);
it('ID(CNV-3076) Changes tiny to custom', async () => {
await vm.create();
await withResource(leakedResources, vm.asResource(), async () => {
await vm.navigateToDetail();
await vm.modalEditFlavor();
await selectOptionByText(editFlavorView.flavorDropdown, 'Custom');
await fillInput(editFlavorView.cpusInput(), '2');
await fillInput(editFlavorView.memoryInput(), '3');
await click(saveButton);

expect(getCPU(vm.getResource()).cores).toEqual(2);
expect(getMemory(vm.getResource())).toEqual('3Gi');
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,
);
expect(getCPU(vm.getResource()).cores).toEqual(2);
expect(getMemory(vm.getResource())).toEqual('3Gi');
expect(
(await virtualMachineView.vmDetailLabelValue('vm.kubevirt.io/template')).startsWith(
'rhel7-desktop-tiny-', // template is not changed (might be in the future)
),
).toBeTruthy();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ describe('Test network type presets and options', () => {

const vm = new VMBuilder(getBasicVMBuilder())
.setProvisionSource(ProvisionSource.CONTAINER)
.setCustomize(true)
.build();

beforeAll(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('Kubevirt create VM using cloud-init', () => {
const vm = new VMBuilder(getBasicVMBuilder())
.setProvisionSource(ProvisionSource.CONTAINER)
.setCloudInit(cloudinitConfig)
.setCustomize(true)
.build();

await vm.create();
Expand All @@ -47,6 +48,7 @@ describe('Kubevirt create VM using cloud-init', () => {
const vm = new VMBuilder(getBasicVMBuilder())
.setProvisionSource(ProvisionSource.CONTAINER)
.setCloudInit(customScript)
.setCustomize(true)
.build();

await vm.create();
Expand Down

0 comments on commit bfaca2d

Please sign in to comment.