Skip to content

Commit

Permalink
Add vm stop
Browse files Browse the repository at this point in the history
  • Loading branch information
n313893254 committed Dec 6, 2022
1 parent 283ca07 commit 8de455b
Show file tree
Hide file tree
Showing 22 changed files with 387 additions and 335 deletions.
2 changes: 2 additions & 0 deletions cypress/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export default defineConfig({
},
nfsEndPoint: 'nfs://ip',
vlanIDs: [1, 2],
sshKey: 'Your ssh public key, use for validate connect VM. e.g. ssh-rsa xxx',
privateKeyPath: 'Your ssh private Key Path'
},
retries: {
runMode: 1,
Expand Down
6 changes: 4 additions & 2 deletions cypress/cypress.env.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@
"image": {
"name": "cirros-0.5.2-aarch64-disk.img",
"url": "https://github.com/cirros-dev/cirros/releases/download/0.5.2/cirros-0.5.2-aarch64-disk.img"
}
}
},
"sshKey": "ssh-rsa GgVY6KnKpJqrBd/BGuUoHhh/C3CXhDojb1G1Td6hktaUwH+Q== username@email.com",
"privateKeyPath": "/Users/username/.ssh/id_rsa"
}
86 changes: 61 additions & 25 deletions cypress/pageobjects/template.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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';
import CheckboxPo from '@/utils/components/checkbox.po';

const constants = new Constants();

Expand All @@ -13,6 +14,13 @@ interface ValueInterface {
description?: string,
cpu?: string,
memory?: string,
image?: string,
}

interface Volume {
buttonText: string,
create?: boolean,
[index: string]: any
}

export default class TemplatePage extends CruResourcePo {
Expand All @@ -23,17 +31,6 @@ export default class TemplatePage extends CruResourcePo {
});
}

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

cy.get('.tab#Volume').click()
this.image().select({option: value?.image})
}

cpu() {
return new LabeledInputPo('.labeled-input', `:contains("CPU")`)
}
Expand All @@ -51,20 +48,6 @@ export default class TemplatePage extends CruResourcePo {
this.clickAction(name, 'Add templateVersion')
}

deleteProgramlly(id:string) {
cy.window().then((window: any) => {
const store = window.$nuxt.$store

const resource = store.getters['harvester/byId'](HCI.VM_TEMPLATE, id)

cy.intercept('DELETE', `/v1/harvester/${this.realType}s/${id}*`).as('delete');
resource.remove()
cy.wait('@delete').then(res => {
expect(res.response?.statusCode, `Delete ${this.type}`).to.be.oneOf([200, 204]);
})
})
}

setBasics(cpu?: string, memery?: string, ssh?: {id?: string, createNew?: boolean, value?: string}) {
this.clickTab('Basics');
this.cpu().input(cpu);
Expand All @@ -81,4 +64,57 @@ export default class TemplatePage extends CruResourcePo {
cy.get('.v--modal-box .card-container').contains('Create').click();
}
}

setVolumes(volumes: Array<Volume>) {
this.clickTab('Volume');
cy.wrap('async').then(() => {
volumes.map((volume) => {
if (volume.create) {
cy.get('.tab-container button').contains(volume.buttonText).click()
}
});

volumes.map((volume, index) => {
let imageEl: any;
let volumeEl: any;
cy.get('.info-box').eq(index).within(() => {
if (volume.image) {
imageEl = new LabeledSelectPo('.labeled-select', `:contains("Image")`);
}

if (volume.size) {
new LabeledInputPo('.labeled-input', `:contains("Size")`).input(volume.size);
}

if (volume.volume) {
volumeEl = new LabeledSelectPo('.labeled-select', `:contains("Volume")`);
}
}).then(() => {
if (imageEl) {
imageEl.select({option: volume.image});
}

if (volumeEl) {
volumeEl.select({option: volume.volume});
}
})
})
})
}

setAdvancedOption(option: {[index: string]: any}) {
this.clickTab('advanced');

if (option.runStrategy) {
new LabeledSelectPo('.labeled-select', `:contains("Run Strategy")`).select({option: option.runStrategy});
}

if ([true, false].includes(option.efiEnabled)) {
this.efiEnabled().check(option.efiEnabled)
}
}

efiEnabled() {
return new CheckboxPo('.checkbox-container', `:contains("Booting in EFI mode")`)
}
}
62 changes: 50 additions & 12 deletions cypress/pageobjects/virtualmachine.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ interface ValueInterface {
createRunning?: boolean,
usbTablet?: boolean,
efiEnabled?: boolean,
userData?: string,
networkData?: string,
}

interface Volume {
Expand Down Expand Up @@ -106,6 +108,14 @@ export class VmsPage extends CruResourcePo {
if ([true, false].includes(option.efiEnabled)) {
this.efiEnabled().check(option.efiEnabled)
}

if (option.userData) {
this.userData().input(option?.userData)
}

if (option.networkData) {
this.networkData().input(option?.networkData)
}
}

clickCloneAction(name: string) {
Expand Down Expand Up @@ -304,7 +314,7 @@ export class VmsPage extends CruResourcePo {
cy.wait('@delete').then(res => {
cy.window().then((win) => {
const id = `${namespace}/${name}`;
super.checkDelete(this.type, id)
super.checkDelete(this.type, id, 80)
expect(res.response?.statusCode, `Delete ${this.type}`).to.be.oneOf([200, 204]);
})
})
Expand Down Expand Up @@ -364,14 +374,12 @@ export class VmsPage extends CruResourcePo {
return new YamlEditorPo(selector)
}

public checkState(target: string, valid: boolean = true, state: string) {
cy.wait(1000).get(this.searchInput).then(($search) => {
cy.wrap($search).click().type(target);
cy.contains(target).parentsUntil('tbody', 'tr').find('td.col-badge-state-formatter').contains(valid ? state : 'Pending', { timeout: constants.timeout.provisionTimeout }).should('be.visible');
});
}

public selectTemplateAndVersion({name, namespace, id, version}) {
public selectTemplateAndVersion({name, namespace, id, version}: {
name?: string,
namespace?: string,
id?: string,
version?: string,
}) {
cy.contains('Use VM Template').click()
this.template().select({option: id || `${namespace}/${name}`})
this.version().select({
Expand All @@ -384,9 +392,39 @@ export class VmsPage extends CruResourcePo {
this.multipleInstance().input('Multiple Instance')
}

setMultipleInstance(value) {
setMultipleInstance({namePrefix, count}: {
namePrefix?: string,
count?: string,
}) {
this.selectMultipleInstance()
this.namePrefix().input(value.namePrefix)
this.count().input(value.count)
this.namePrefix().input(namePrefix)
this.count().input(count)
}

setNodeScheduling({
radio, nodeName, selector
}: {
radio?: string,
nodeName?: string,
selector?: any,
}) {
this.clickTab('nodeScheduling');

const anyRadio = new RadioButtonPo('.radio-group', ':contains("Run VM on any available node")')
const specificRadio = new RadioButtonPo('.radio-group', ':contains("Run VM on specific node")')
const rulesRadio = new RadioButtonPo('.radio-group', ':contains("Run VM on node(s) matching scheduling rules")')

if (radio === 'any') {
// anyRadio.input(null)
} else if (radio = 'Run VM on any available node') {
specificRadio.input('Run VM on specific node')

const nodeNameSelector = new LabeledSelectPo('.labeled-select', `:contains("Node Name")`)
nodeNameSelector.select({
option: nodeName,
})
} else if (radio === 'rules') {
rulesRadio.input('Run VM on node(s) matching scheduling rules')
}
}
}
4 changes: 3 additions & 1 deletion cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ module.exports = (on, config) => {
const {NodeSSH} = require('node-ssh')
const ssh = new NodeSSH()

const privateKeyPath = config.env.privateKeyPath;

ssh.connect({
host: host.trim(),
username,
privateKeyPath: '/Users/doublesheep/.ssh/id_rsa',
privateKeyPath,
})
.then(function() {
ssh.execCommand(remoteCommand, { cwd:'/var/www' })
Expand Down
22 changes: 0 additions & 22 deletions cypress/poi.js

This file was deleted.

18 changes: 18 additions & 0 deletions cypress/testcases/VM settings/ssh-keys.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,21 @@ describe('Create a ssh key', () => {
ssh.delete(namespace, cloneName)
});
});

export function PresetSsh() {}
describe('Preset a ssh key', () => {
it('Preset a ssh key', () => {
cy.login();

const name = 'preset-ssh';
const namespace = 'default'

const sshKey = Cypress.env('sshKey');

ssh.create({
name,
namespace,
sshKey,
})
});
});
68 changes: 42 additions & 26 deletions cypress/testcases/templates/advanced.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,69 @@ import templatePage from "@/pageobjects/template.po";
const vmPO = new VmsPage();
const templates = new templatePage();

/**
* 1. Go to Template, create a VM template with Boot in EFI mode selected.
* 2. Go to Virtual Machines, click Create, select Multiple instance, type in a random name prefix, and select the VM template we just created.
* 3. Create a VM with template
* Expected Results
* 1. Check VM setting, the booting in EFI mode is checked
*/
describe("template with EFI", () => {
it('Create a new VM with Booting in EFI mode checked', () => {
it('template with EFI', () => {
cy.login();

const NAME = generateName('test-efi-template')
const namespace = 'default'

templates.goToCreate()

const value = {
name: NAME,
cpu: '1',
memory: '1',
namespace,
efiEnabled: true,
}
const imageEnv = Cypress.env('image');
const volume = [{
buttonText: 'Add Volume',
create: false,
image: `default/${Cypress._.toLower(imageEnv.name)}`,
}];

templates.setNameNsDescription(NAME, namespace);
templates.setBasics('1', '1')
templates.setVolumes(volume)
templates.setAdvancedOption({
efiEnabled: true
})

templates.create(value, true);
templates.save(namespace)

vmPO.goToCreate()

vmPO.selectTemplateAndVersion({id: templateId, version: '2'})
vmPO.selectTemplateAndVersion({id: `${namespace}/${NAME}`, version: '1'})

const VM_NAME = generateName('test-efi')
const namePrefix = 'test-multiple-efi'

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

const value = {
name: VM_NAME,
cpu: '1',
memory: '1',
image: Cypress._.toLower(imageEnv.name),
}
vmPO.setMultipleInstance({
namePrefix,
count: '3',
})
vmPO.setNameNsDescription(namePrefix, namespace);

cy.intercept('POST', '/v1/harvester/kubevirt.io.virtualmachines/*').as('createVM');

vms.create(value);
vmPO.save();

cy.wait('@createVM').then(res => {
expect(res.response?.statusCode, 'Check create VM').to.equal(201);
expect(res.response?.body?.spec?.template?.spec?.domain?.features?.smm?.enabled, 'Check smm.enabled').to.equal(false);
expect(res.response?.body?.spec?.template?.spec?.domain?.firmware?.bootloader?.efi?.secureBoot, 'Check efi.secureBoot').to.equal(false);
})

vms.goToConfigDetail(VM_NAME);

cy.get('.tab#advanced').click()
vms.efiEnabled().expectChecked()

vms.deleteProgramlly(`${NAMESPACE}/${VM_NAME}`)
vmPO.goToList()
cy.get('.search').type(namePrefix)
cy.get('tr.main-row').should($els => {
expect($els).to.have.length(3)
})
cy.get('tr.main-row').each(row => {
cy.wrap(row).find('td').eq(0).click()
cy.get('button#promptRemove').click()
cy.get('[data-testid="prompt-remove-confirm-button"]').click()
})
})
})
Loading

0 comments on commit 8de455b

Please sign in to comment.