Skip to content

Commit

Permalink
Merge pull request #6735 from gouyang/cdi
Browse files Browse the repository at this point in the history
Bug 1882197: Add test for golden image upload
  • Loading branch information
openshift-merge-robot committed Sep 26, 2020
2 parents 2f74e8e + ea90e82 commit a7a2761
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { execSync } from 'child_process';
import { testName } from '@console/internal-integration-tests/protractor.conf';
import { browser, ExpectedConditions as until } from 'protractor';
import { click } from '@console/shared/src/test-utils/utils';
import { errorMessage, saveChangesBtn } from '@console/internal-integration-tests/views/crud.view';
import { pvcStatus } from '@console/ceph-storage-plugin/integration-tests/views/pvc.view';
import { PVC_STATUS } from '@console/ceph-storage-plugin/integration-tests/utils/consts';
import { CDI_UPLOAD_TIMEOUT_SECS, STORAGE_CLASS } from './utils/constants/common';
import { OperatingSystem } from './utils/constants/wizard';
import * as cdiUploadView from '../views/cdiUploadView';
import { PVCData } from './types/pvc';
import { UploadForm } from './models/pvcUploadForm';

// this scenario tests the upload procedure, without creating a vm from the uploaded resource.
// https://issues.redhat.com/browse/CNV-6020

describe('KubeVirt CDI Upload', () => {
const uploadForm = new UploadForm();
const srcImage =
'http://cnv-qe-server.rhevdev.lab.eng.rdu2.redhat.com/files/cnv-tests/cirros-images/cirros-0.4.0-x86_64-disk.qcow2';
const desImage = '/tmp/cirros.qcow2';
const invalidImage = '/tmp/cirros.txt';
const pvcName = `upload-pvc-${testName}`;

beforeAll(async () => {
execSync(`curl ${srcImage} -o ${desImage}`);
execSync(`ln -s -f ${desImage} ${invalidImage}`);
});

afterAll(async () => {
execSync(`rm ${desImage} ${invalidImage}`);
execSync(`kubectl delete -n ${testName} dv ${pvcName}`);
});

it(
'ID(CNV-4718) Upload data to CDI',
async () => {
const pvc: PVCData = {
image: desImage,
pvcName: `upload-pvc-${testName}`,
pvcSize: '1',
pvcSizeUnits: 'Gi',
storageClass: STORAGE_CLASS,
};

await uploadForm.upload(pvc);

await browser.wait(until.textToBePresentInElement(cdiUploadView.uploadProgress, '100%'));
await click(cdiUploadView.viewStatusID);
await browser.wait(until.textToBePresentInElement(pvcStatus, PVC_STATUS.BOUND));
},
CDI_UPLOAD_TIMEOUT_SECS,
);

it(
'ID(CNV-4891) It shows error messsages when image format is not supported',
async () => {
const pvc: PVCData = {
image: invalidImage,
pvcName: `upload-pvc-${testName}-invalid`,
pvcSize: '1',
pvcSizeUnits: 'Gi',
storageClass: STORAGE_CLASS,
};

await uploadForm.upload(pvc);
await browser.wait(until.presenceOf(errorMessage));
expect(errorMessage.getText()).toContain('not supported');
},
CDI_UPLOAD_TIMEOUT_SECS,
);

it(
'ID(CNV-4890) Upload image for golden OS',
async () => {
const pvc: PVCData = {
image: desImage,
os: OperatingSystem.RHEL7,
pvcSize: '1',
pvcSizeUnits: 'Gi',
storageClass: STORAGE_CLASS,
};

await uploadForm.upload(pvc);
// It has to click the upload button again to trigger uploading based on actual test results.
await click(saveChangesBtn);
await browser.wait(until.textToBePresentInElement(cdiUploadView.uploadProgress, '100%'));
await click(cdiUploadView.viewStatusID);
await browser.wait(until.textToBePresentInElement(pvcStatus, PVC_STATUS.BOUND));
},
CDI_UPLOAD_TIMEOUT_SECS,
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/* eslint-disable no-await-in-loop */
import { browser, ExpectedConditions as until } from 'protractor';
import {
createItemButton,
isLoaded,
saveChangesBtn,
} from '@console/internal-integration-tests/views/crud.view';
import { clickNavLink } from '@console/internal-integration-tests/views/sidenav.view';
import {
inputPVCName,
inputPVCSize,
selectItemFromDropdown,
storageclassDropdown,
selectAccessMode,
sizeUnitsDropdown,
} from '@console/ceph-storage-plugin/integration-tests/views/pvc.view';
import { click, fillInput } from '@console/shared/src/test-utils/utils';
import { selectOptionByText } from '../utils/utils';
import * as cdiUploadView from '../../views/cdiUploadView';
import { PVCData } from '../types/pvc';

export class UploadForm {
async openForm() {
await clickNavLink(['Storage', 'Persistent Volume Claims']);
await isLoaded();
await click(createItemButton);
await click(cdiUploadView.uploadCdiFormButton);

await browser.wait(
until.textToBePresentInElement(
$('.co-m-pane__heading'),
'Upload Data to Persistent Volume Claim',
),
);
}

async fillUploadImage(name: string) {
// firefox needs the input to be shown
await browser.executeAsyncScript((callback) => {
(document.querySelector('input[type="file"]') as HTMLElement).style.display = 'inline';
callback();
});
await cdiUploadView.uploadInput.sendKeys(name);
}

async selectGoldenOS(os: string) {
await click(cdiUploadView.goldenOSCheckbox);
await selectOptionByText(cdiUploadView.goldenOSDropDownID, os);
}

async fillPVCName(pvcName: string) {
await fillInput(inputPVCName, pvcName);
}

async selectStorageClass(sc: string) {
await selectItemFromDropdown(sc, storageclassDropdown);
}

async fillPVCSize(pvcSize: string, pvcSizeUnits: string) {
await inputPVCSize.sendKeys(pvcSize);
await selectItemFromDropdown(pvcSizeUnits, sizeUnitsDropdown);
}

async selectAccessMode(accessMode: string) {
await click(selectAccessMode(accessMode));
}

async fillAll(data: PVCData) {
const { image, os, pvcName, pvcSize, pvcSizeUnits, storageClass, accessMode } = data;
await this.selectStorageClass(storageClass);
await this.fillPVCSize(pvcSize, pvcSizeUnits);
if (accessMode) {
await this.selectAccessMode(accessMode);
}
if (os) {
this.selectGoldenOS(os);
} else {
await this.fillPVCName(pvcName);
}
await this.fillUploadImage(image);
}

async upload(data: PVCData) {
await this.openForm();
await this.fillAll(data);
await click(saveChangesBtn);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export type PVCData = {
image: string;
os?: string;
pvcName?: string;
pvcSize: string;
pvcSizeUnits: string;
storageClass: string;
accessMode?: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export const JASMINE_EXTENDED_TIMEOUT_INTERVAL = 500 * SEC;
export const V2V_INSTANCE_CONNECTION_TIMEOUT = 30 * SEC;
export const V2V_VM_IMPORT_TIMEOUT = 3600 * SEC;

export const CDI_UPLOAD_TIMEOUT_SECS = 300 * SEC;

export const VIRTUALIZATION_TITLE = 'Virtualization';

// Wizard strings
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { element, by, $ } from 'protractor';

export const uploadCdiFormButton = element(by.partialButtonText('Data upload'));
export const uploadInput = $('input[type="file"]');
export const unitDropdown = $('button[data-test-id="dropdown-button"]');
export const uploadProgress = element.all(by.css('.pf-c-progress__measure')).first();
export const goldenOSCheckbox = $('#golden-os-switch');
export const goldenOSDropDownID = $('#golden-os-select');
export const viewStatusID = $('#cdi-upload-primary-pvc');

0 comments on commit a7a2761

Please sign in to comment.