Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CY] Add template and fix vm #359

Merged
merged 6 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions cypress/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ export default defineConfig({
fixturesFolder: './fixtures',
viewportWidth: 1920,
viewportHeight: 1080,
numTestsKeptInMemory: 5,
defaultCommandTimeout: 30000,
requestTimeout: 20000,
responseTimeout: 20000,
numTestsKeptInMemory: 0,
defaultCommandTimeout: 60000,
requestTimeout: 30000,
responseTimeout: 30000,
env: {
NODE_ENV: 'production',
username: 'admin',
Expand All @@ -24,10 +24,11 @@ export default defineConfig({
],
},
image: {
name: 'openSUSE-Leap-15.3-3-DVD-x86_64-Build38.1-Media.iso',
url: 'https://mirrors.bfsu.edu.cn/opensuse/distribution/leap/15.3/iso/openSUSE-Leap-15.3-3-DVD-x86_64-Build38.1-Media.iso',
name: 'openSUSE-Leap-15.3-3-NET-x86_64.qcow2',
url: 'https://download.opensuse.org/pub/opensuse/distribution/leap/15.3/appliances/openSUSE-Leap-15.3-JeOS.x86_64-15.3-OpenStack-Cloud-Current.qcow2',
},
nfsEndPoint: 'nfs://ip',
vlans: ['[vlan name1]', '[vlan name2]'],
},
retries: {
runMode: 1,
Expand Down
2 changes: 1 addition & 1 deletion cypress/cypress.env.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"image":
{
"name": "openSUSE-Leap-15.3-3-DVD-x86_64-Build38.1-Media.iso",
"url": "https://mirrors.bfsu.edu.cn/opensuse/distribution/leap/15.3/iso/openSUSE-Leap-15.3-3-DVD-x86_64-Build38.1-Media.iso"
"url": "https://download.opensuse.org/distribution/leap/15.3/iso/openSUSE-Leap-15.3-3-DVD-x86_64-Build38.1-Media.iso"
}
}
18 changes: 9 additions & 9 deletions cypress/pageobjects/image.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class ImagePage {
private pageHead = 'main .outlet header h1';

name() {
return new LabeledInputPo('.namespace-select > .labeled-input', `:contains("Name")`)
return new LabeledInputPo('.span-3 > .labeled-input', `:contains("Name")`)
}

url() {
Expand Down Expand Up @@ -73,8 +73,8 @@ export class ImagePage {
cy.get('.tab#labels').click();
keys.forEach((key, index) => {
cy.contains('Add Label').click();
cy.get('.kv-item.key input').eq(index + 2).type(key);
cy.get('.kv-item.value input').eq(index + 2).type(value.labels[key]);
cy.get('.kv-item.key input').eq(-1).type(key);
cy.get('.kv-item.value input').eq(-1).type(value.labels[key]);
});
}

Expand Down Expand Up @@ -125,10 +125,6 @@ export class ImagePage {
cy.contains(value.name).parentsUntil('tbody', 'tr').find('td.col-image-percentage-bar').contains(valid ? 'Completed' : '0%', { timeout: constants.timeout.uploadTimeout }).should('be.visible');
// state indicator for status of image upload status e.g. active or uploading
cy.contains(value.name).parentsUntil('tbody', 'tr').find('td.col-badge-state-formatter').contains(valid ? 'Active' : 'Failed', { timeout: constants.timeout.uploadTimeout }).should('be.visible');

if (valid) {
cy.contains(value.size || 'Size need to be string').should('be.visible');
}
}

// public checkImageInLH(imageName: string) {
Expand Down Expand Up @@ -159,11 +155,15 @@ export class ImagePage {
// });
// }

public save( { upload, edit }: { upload?: boolean; edit?: boolean } = {} ) {
public save( { upload, edit, depth }: { upload?: boolean; edit?: boolean; depth?: number; } = {} ) {
cy.intercept(edit? 'PUT' : 'POST', `/v1/harvester/harvesterhci.io.virtualmachineimages${ upload ? '/*' : edit ? '/*/*' : '' }`).as('createImage');
cy.get('.cru-resource-footer').contains(!edit ? 'Create' : 'Save').click();
cy.wait('@createImage').then(res => {
expect(res.response?.statusCode).to.equal( edit ? 200 : 201 );
if (edit && res.response?.statusCode === 409 && depth === 0) {
this.save({ upload, edit, depth: depth + 1})
} else {
expect(res.response?.statusCode, `Check save success`).to.equal( edit ? 200 : 201 );
}
});
}

Expand Down
41 changes: 41 additions & 0 deletions cypress/pageobjects/template.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Constants } from "@/constants/constants";
import LabeledInputPo from '@/utils/components/labeled-input.po';
import LabeledSelectPo from '@/utils/components/labeled-select.po';
import LabeledTextAreaPo from '@/utils/components/labeled-textarea.po';
import { HCI } from '@/constants/types'
import CruResourcePo from '@/utils/components/cru-resource.po';

const constants = new Constants();

interface ValueInterface {
namespace?: string,
name?: string,
description?: string,
cpu?: string,
memory?: string,
}

export default class TemplatePage extends CruResourcePo {
constructor() {
super({
type: HCI.VM_VERSION,
realType: HCI.VM_TEMPLATE,
});
}

public setValue(value: ValueInterface) {
this.namespace().select(value?.namespace)
this.name().input(value?.name)
this.description().input(value?.description)
this.cpu().input(value?.cpu)
this.memory().input(value?.memory)
}

cpu() {
return new LabeledInputPo('.labeled-input', `:contains("CPU")`)
}

memory() {
return new LabeledInputPo('.labeled-input', `:contains("Memory")`)
}
}
59 changes: 12 additions & 47 deletions cypress/pageobjects/virtualmachine.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import LabeledInputPo from '@/utils/components/labeled-input.po';
import CheckboxPo from '@/utils/components/checkbox.po';
import { ImagePage } from "@/pageobjects/image.po";
import { find } from "cypress/types/lodash";
import CruResourcePo from '@/utils/components/cru-resource.po';

const constants = new Constants();
const image = new ImagePage();
Expand All @@ -26,11 +27,17 @@ interface ValueInterface {
efiEnabled?: boolean,
}

export class VmsPage {
export class VmsPage extends CruResourcePo {
private actionButton = '.outlet .actions-container';
private pageHead = 'main .outlet header h1';
private sideBar = 'nav.side-nav .list-unstyled';

constructor() {
super({
type: HCI.VM
});
}

public goToList() {
cy.visit(constants.vmPage);

Expand Down Expand Up @@ -68,18 +75,6 @@ export class VmsPage {
})
}

namespace() {
return new LabeledSelectPo('.labeled-select', `:contains("Namespace")`)
}

name() {
return new LabeledInputPo('.namespace-select > .labeled-input', `:contains("Name")`)
}

description() {
return new LabeledInputPo('.labeled-input', `:contains("Description")`)
}

cpu() {
return new LabeledInputPo('.labeled-input', `:contains("CPU")`)
}
Expand Down Expand Up @@ -133,17 +128,10 @@ export class VmsPage {
cy.url().should('contain', 'as=config')
}

goToYamlDetail(name: string) {
goToYamlEdit(name: string) {
this.goToList();
cy.get('.search').type(name)
const vm = cy.contains(name)
expect(vm.should('be.visible'))
vm.click()

const config = cy.get('.masthead button').contains('YAML')
expect(config.should('be.visible'));
config.click()
cy.url().should('contain', 'as=yaml')
this.clickAction(name, 'Edit YAML')
}

public init() {
Expand All @@ -161,11 +149,10 @@ export class VmsPage {

const imageEnv = Cypress.env('image');

const name = imageEnv.name
const name = Cypress._.toLower(imageEnv.name)
const url = imageEnv.url
const imageFound = images.find((i:any) => i?.spec?.displayName === name)
console.log(imageFound, 'imageFound')
console.log(res, 'res')

if (imageFound) {
return
} else {
Expand All @@ -179,28 +166,6 @@ export class VmsPage {
})
}

public create(value: ValueInterface) {
this.init()
this.goToCreate();
this.setValue(value);
this.save();
}

public delete(name: string) {
this.goToList()
cy.get('.search').type(name)
const vm = cy.contains(name)
expect(vm.should('be.visible'))
vm.parentsUntil('tbody', 'tr').click()
cy.contains('Delete').click()

cy.intercept('DELETE', `/v1/harvester/kubevirt.io.virtualmachines/*/${name}?*`).as('delete');
cy.get('.card-container.prompt-remove').contains('Delete').click();
cy.wait('@delete').then(res => {
expect(res.response?.statusCode).to.equal(200);
})
}

public goToEdit(name: string) {
this.goToList()
cy.get('.search').type(name)
Expand Down
7 changes: 5 additions & 2 deletions cypress/pageobjects/volume.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class VolumePage {
cy.visit(constants.volumePage)
cy.intercept('GET', '/v1/harvester/persistentvolumeclaims').as('goToVolumeList');
cy.wait('@goToVolumeList');
cy.url().should('eq', constants.volumePage)
cy.url().should('eq', `${this.basePath()}${constants.volumePage}`)
}

public goToCreate() {
Expand Down Expand Up @@ -67,9 +67,12 @@ export class VolumePage {
cy.intercept('POST', `v1/harvester/persistentvolumeclaims/*/${ volumeName }?action=export`).as('exportImage');
cy.get(this.exportImageActions).contains('Create').click();
cy.wait('@exportImage').then(res => {
expect(res.response?.statusCode).to.equal(200);
expect(res.response?.statusCode, `Check Export Image`).to.be.oneOf([200, 204]);
expect(cy.contains('Succeed'));
});
}

basePath() {
return Cypress.env('NODE_ENV') === 'dev' ? Cypress.env('baseUrl') : `${Cypress.env('baseUrl')}/dashboard`;
}
}
Loading