Skip to content

Commit

Permalink
add kubevirt pvc upload test
Browse files Browse the repository at this point in the history
  • Loading branch information
gouyang committed Jun 17, 2021
1 parent 8e79b58 commit a43cdda
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ Cypress.Commands.add('createProject', (name: string, devConsole: boolean = false
listPage.rows.shouldBeLoaded();
listPage.clickCreateYAMLbutton();
modal.shouldBeOpened();
cy.byTestID('input-name')
.type(name, { force: true })
.should('have.value', name);
cy.byTestID('input-name').type(name);
cy.testA11y('Create Project modal');
modal.submit();
modal.shouldBeClosed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ declare global {
Login(): void;
deleteTestProject(namespace: string): void;
pauseVM(vmData: VirtualMachineData): void;
uploadFromCLI(dvName: string, ns: string, imagePath: string, size: string): void;
}
}
}
Expand Down Expand Up @@ -146,7 +147,7 @@ Cypress.Commands.add('cdiCloner', (namespace: string) => {
Cypress.Commands.add('waitForLoginPrompt', (vmName: string, namespace: string) => {
cy.exec(`expect ${EXPECT_LOGIN_SCRIPT_PATH} ${vmName} ${namespace}`, {
failOnNonZeroExit: false,
timeout: 180000,
timeout: 600000,
});
});

Expand All @@ -169,3 +170,19 @@ Cypress.Commands.add('pauseVM', (vmData: VirtualMachineData) => {
timeout: 180000,
});
});

Cypress.Commands.add(
'uploadFromCLI',
(dvName: string, ns: string, imagePath: string, size: string) => {
if (Cypress.env('STORAGE_CLASS') === 'ocs-storagecluster-ceph-rbd') {
cy.exec(
`virtctl image-upload dv ${dvName} --image-path=${imagePath} --size=${size}Gi --storage-class=ocs-storagecluster-ceph-rbd --access-mode=ReadWriteMany --block-volume -n ${ns} --insecure || true`,
);
}
if (Cypress.env('STORAGE_CLASS') === 'hostpath-provisioner') {
cy.exec(
`virtctl image-upload dv ${dvName} --image-path=${imagePath} --size=${size}Gi --storage-class=hostpath-provisioner --access-mode=ReadWriteOnce -n ${ns} --insecure || true`,
);
}
},
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { TEMPLATE_BASE_IMAGE, TEMPLATE_NAME, OS_IMAGES_NS } from '../../const/index';
import { ProvisionSource } from '../../enums/provisionSource';
import { testName } from '../../support';
import { VirtualMachineData } from '../../types/vm';
import { pvc } from '../../view/pvc';
import { virtualization } from '../../view/virtualization';
import { vm } from '../../view/vm';

const imageFormats = ['/tmp/cirros.iso', '/tmp/cirros.gz', '/tmp/cirros.xz'];
const invalidImage = '/tmp/cirros.txt';
const os = 'Red Hat Enterprise Linux 6.0 or higher - Default data image already exists';
const vmData: VirtualMachineData = {
name: `pvc-test-vm-${testName}`,
namespace: testName,
template: TEMPLATE_NAME,
sshEnable: false,
startOnCreation: true,
sourceAvailable: true,
};

describe('kubevirt PVC upload', () => {
before(() => {
cy.Login();
cy.visit('/');
cy.createProject(testName);
});

after(() => {
cy.deleteResource({
kind: 'DataVolume',
metadata: {
name: TEMPLATE_BASE_IMAGE,
namespace: OS_IMAGES_NS,
},
});
cy.deleteResource({
kind: 'VirtualMachine',
metadata: {
name: vmData.name,
namespace: vmData.namespace,
},
});
cy.exec('rm -fr /tmp/cirros.*');
});

describe('test PVC upload via form', () => {
it('ID(CNV-4778) No warning message shows when image format is supported', () => {
pvc.form.open();
for (const img of imageFormats) {
cy.exec(`touch ${img} || true`);
cy.dropFile(img, img.split('/').pop(), '.pf-c-file-upload');
cy.get('.pf-c-alert__title')
.contains('File type extension')
.should('not.exist');
}
});

it('ID(CNV-4891) It shows a warning message when image format is not supported', () => {
pvc.form.open();
cy.exec(`touch ${invalidImage} || true`);
cy.dropFile(invalidImage, invalidImage.split('/').pop(), '.pf-c-file-upload');
cy.contains('File type extension').should('be.visible');
});

it('ID(CNV-5176) It shows an error when uploading data to golden OS again', () => {
cy.createDataVolume(TEMPLATE_BASE_IMAGE, OS_IMAGES_NS);
pvc.form.open();
pvc.form.selectOS(os);
cy.get('.pf-c-alert__title')
.contains('Operating system source already defined')
.should('exist');
});

it('ID(CNV-5041) VM can be up after deleting the uploaded PVC', () => {
vm.create(vmData);
vm.stop(vmData);
// only delete template pvc for ocs, hpp does not support this
if (Cypress.env('STORAGE_CLASS') === 'ocs-storagecluster-ceph-rbd') {
cy.deleteResource({
kind: 'DataVolume',
metadata: {
name: TEMPLATE_BASE_IMAGE,
namespace: OS_IMAGES_NS,
},
});
}
vm.start(vmData);
vm.delete();
});
});

describe('test PVC upload via CLI', () => {
it('ID(CNV-5044) Verify boot source is available for template after upload via cli', () => {
cy.exec(
`test -f ${Cypress.env(
'UPLOAD_IMG',
)} || curl --fail -L ${ProvisionSource.URL.getSource()} -o ${Cypress.env('UPLOAD_IMG')}`,
{ timeout: 600000 },
);

cy.uploadFromCLI(TEMPLATE_BASE_IMAGE, OS_IMAGES_NS, Cypress.env('UPLOAD_IMG'), '1');

virtualization.templates.visit();
virtualization.templates.testSource(TEMPLATE_NAME, 'Unknown');
});

it('ID(CNV-5597) Verify create VM from the template which source is uploaded via CLI', () => {
vm.create(vmData);
vm.stop(vmData);
vm.delete();
});

it('ID(CNV-5598) Delete DV/PVC from CLI', () => {
cy.deleteResource({
kind: 'DataVolume',
metadata: {
name: TEMPLATE_BASE_IMAGE,
namespace: OS_IMAGES_NS,
},
});
virtualization.templates.visit();
virtualization.templates.testSource(TEMPLATE_NAME, 'Add source');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ export type VirtualMachineData = {
cdrom?: boolean;
sshEnable?: boolean;
startOnCreation?: boolean;
sourceAvailable?: boolean;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export const pvc = {
form: {
open: () => {
cy.clickNavLink(['Storage', 'PersistentVolumeClaims']);
cy.byTestID('item-create').click();
cy.byLegacyTestID('dropdown-menu')
.contains('With Data upload form')
.click();
},
fillImageName: (name: string) => {
cy.get('#file-upload-filename')
.type(name, { force: true })
.should('have.value', name);
},
selectOS: (name: string) => {
cy.get('#golden-os-switch').click();
cy.get('#golden-os-select').select(name);
},
fillPVCName: (name: string) => {
cy.get('#pvc-name')
.clear()
.type(name);
},
fillPVCSize: (size: string) => {
cy.get('#request-size-input')
.clear()
.type(size);
},
selectSC: (name: string) => {
cy.get('#upload-form-ds-sc-select').click();
cy.get('.pf-c-select__menu-item')
.contains(name)
.click();
},
create: () => {
cy.get('#save-changes').click();
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ export const vm = {
sshEnable,
startOnCreation,
template,
sourceAvailable,
} = vmData;
virtualization.vms.visit();
wizard.vm.open();
wizard.vm.processSelectTemplate(template);
wizard.vm.processBootSource(provisionSource, cdrom, pvcSize, pvcName, pvcNS);
if (!sourceAvailable) {
wizard.vm.processBootSource(provisionSource, cdrom, pvcSize, pvcName, pvcNS);
}
wizard.vm.processReview(namespace, name, flavor, sshEnable, startOnCreation);
if (startOnCreation) {
waitForStatus(VM_STATUS.Starting, vmData, VM_ACTION_TIMEOUT.VM_IMPORT_AND_BOOTUP);
Expand Down

0 comments on commit a43cdda

Please sign in to comment.