Skip to content

Commit

Permalink
[CY] add vm backup case
Browse files Browse the repository at this point in the history
  • Loading branch information
WuJun2016 authored and n313893254 committed Jul 20, 2023
1 parent c59fbff commit cfd6ee8
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 10 deletions.
2 changes: 0 additions & 2 deletions cypress/pageobjects/namespace.po.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { HCI } from '@/constants/types'
import CruResourcePo from '@/utils/components/cru-resource.po';



export default class NamespacePage extends CruResourcePo {
constructor() {
super({
Expand Down
12 changes: 11 additions & 1 deletion cypress/pageobjects/virtualmachine.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class VmsPage extends CruResourcePo {

checkVMState(name: string, state: string = 'Running', namespace: string = 'default') {
this.goToList();
this.censorInColumn(name, 3, namespace, 4, state, 2, { timeout: constants.timeout.maxTimeout, nameSelector: '.name-console a' });
this.censorInColumn(name, 3, namespace, 4, state, 2, { timeout: constants.timeout.uploadTimeout, nameSelector: '.name-console a' });
}

clickCloneAction(name: string) {
Expand All @@ -145,6 +145,16 @@ export class VmsPage extends CruResourcePo {
cy.get('.growl-container .growl-list').find('.growl-text div').contains('Succeed');
}


clickVMBackupAction(name: string, backupName: string) {
this.clickAction(name, 'Take Backup');
cy.get('.v--modal-box .card-title').find('h4').contains('Add Backup');

new LabeledInputPo('.v--modal-box .labeled-input', `:contains("Name")`).input(backupName)
cy.get('.v--modal-box button').contains('Create').click();
cy.get('.growl-container .growl-list').find('.growl-text div').contains('Succeed');
}

public setValue(value: ValueInterface) {
this.namespace().select({option: value?.namespace})
this.name().input(value?.name)
Expand Down
42 changes: 42 additions & 0 deletions cypress/pageobjects/vmBackup.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import LabeledInputPo from '@/utils/components/labeled-input.po';
import LabeledSelectPo from '@/utils/components/labeled-select.po';
import { HCI } from '@/constants/types'
import CruResourcePo from '@/utils/components/cru-resource.po';

import { Constants } from "@/constants/constants";
const constants = new Constants();

export default class VMBackup extends CruResourcePo {
constructor() {
super({
type: HCI.BACKUP,
});
}

checkState(name: string, state: string = 'Ready', namespace: string = 'default') {
this.censorInColumn(name, 3, namespace, 4, state, 2, { timeout: constants.timeout.uploadTimeout });
}

restoreNew(name: string, newVMName: string, namespace?: string) {
this.clickAction(name, 'Restore New');
if (namespace) {
new LabeledSelectPo('.labeled-select', `:contains("Namespace")`).select({option: namespace});
}

new LabeledInputPo('.labeled-input', `:contains("Virtual Machine Name ")`).input(newVMName);
new LabeledSelectPo('.labeled-select', `:contains("Backup")`).self().contains(name);
this.clickFooterBtn('Create');
}

restoreExistingVM(name: string) {
this.clickAction(name, 'Replace Existing');
new LabeledSelectPo('.labeled-select', `:contains("Namespace")`).isDisabled();
new LabeledInputPo('.labeled-input', `:contains("Virtual Machine Name")`).isDisabled();
new LabeledSelectPo('.labeled-select', `:contains("Backup")`).self().contains(name);
this.clickFooterBtn('Create');
}

clickFooterBtn(text: string = 'Create') {
cy.get('.footer .buttons').find('.btn').contains(text).click();
}
}
100 changes: 100 additions & 0 deletions cypress/testcases/backupAndSnapshot/vmBackup.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { onlyOn } from "@cypress/skip-test";
import { VmsPage } from "@/pageobjects/virtualmachine.po";
import VMBackup from '@/pageobjects/vmBackup.po';
import { PageUrl } from "@/constants/constants";

const vms = new VmsPage();
const vmBackups = new VMBackup();

describe('VM Backup Validation', () => {
const vmName = 'test';
let createVMBackupSuccess: boolean = false ;
const vmBackupName = 'test-vm-backup';

beforeEach(() => {
cy.login({url: PageUrl.virtualMachine});
});

it('Take a vm backup from vm', () => {
// Create a vm to test the backup operation
const namespace = 'default';

const id = `${namespace}/${vmName}`;
const imageEnv = Cypress.env('image');
const volume = [{
buttonText: 'Add Volume',
create: false,
size: '2',
image: `default/${Cypress._.toLower(imageEnv.name)}`,
}];

vmBackups.deleteFromStore(`${namespace}/${vmBackupName}`)
vms.deleteVMFromStore(id)
vms.goToCreate();
vms.deleteVMFromStore(`${namespace}/${vmName}`);
vms.setNameNsDescription(vmName, namespace);
vms.setBasics('1', '1');
vms.setVolumes(volume);
vms.save();

// create a vm snapshot
vms.checkVMState(vmName, 'Running');
vms.clickVMBackupAction(vmName, vmBackupName);

// check vm snapshot
vmBackups.goToList();
// vmBackups.checkState(vmBackupName, vmName);
vmBackups.censorInColumn(vmBackupName, 3, namespace, 4, vmName, 5, { timeout: 5000, nameSelector: 'a' });

createVMBackupSuccess = true
})

it('Resotre New VM from vm backup', () => {
onlyOn(createVMBackupSuccess);

const newVMName = 'create-new-from-backup';

vms.deleteVMFromStore(`default/${newVMName}`)
vmBackups.goToList();
vmBackups.restoreNew(vmBackupName, newVMName);
vms.checkVMState(newVMName);

// delete vm
vms.deleteVMFromStore(`default/${newVMName}`);
})

it('Resotre New VM in another namespace from vm backup', () => {
onlyOn(createVMBackupSuccess);

const newVMName = 'create-new-from-backup';

vms.deleteVMFromStore(`default/${newVMName}`)
vmBackups.goToList();
vmBackups.restoreNew(vmBackupName, newVMName, 'harvester-public');
vms.checkVMState(newVMName);

// delete vm
vms.deleteVMFromStore(`default/${newVMName}`);
})

it('Resotre Existing VM from vm backup', () => {
onlyOn(createVMBackupSuccess);

vms.goToList();
vms.clickAction(vmName, 'Stop');
vms.checkVMState(vmName, 'Off')
vmBackups.goToList();
vmBackups.restoreExistingVM(vmBackupName);
vms.checkVMState(vmName);

// delete vm
vms.deleteVMFromStore(`default/test`);
})

it('delete backup', () => {
onlyOn(createVMBackupSuccess);

vmBackups.goToList();
vmBackups.deleteFromStore(`default/${vmBackupName}`);
})
})
2 changes: 1 addition & 1 deletion cypress/testcases/dashboard/1_login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('login page for harvester', () => {
})

// https://harvester.github.io/tests/manual/authentication/logout-then-login/
it.only("Logout from the UI and login again", () => {
it("Logout from the UI and login again", () => {
const page = new LoginPage();
page.visit();
page.inputUsername();
Expand Down
11 changes: 5 additions & 6 deletions cypress/testcases/virtualmachines/virtual-machine.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ describe('VM runStategy Validation (Halted)', () => {

const namespace = 'default'

it('Craete VM use Halted (Run Strategy)', () => {
it.only('Craete VM use Halted (Run Strategy)', () => {
vms.goToCreate();

const imageEnv = Cypress.env('image');
Expand All @@ -191,12 +191,11 @@ describe('VM runStategy Validation (Halted)', () => {

vms.deleteVMFromStore(`${namespace}/${VM_NAME}`)
vms.setNameNsDescription(VM_NAME, namespace);
vms.setBasics('2', '4');
vms.setBasics('1', '1');
vms.setVolumes(volume);
vms.setAdvancedOption(advancedOption);
vms.save();

// TODO Verify VM is Off, Wait for other pr
vms.checkVMState(VM_NAME, 'Off')
});
})

Expand All @@ -206,8 +205,8 @@ describe('All Namespace filtering in VM list', () => {
});

// https://harvester.github.io/tests/manual/_incoming/2578-all-namespace-filtering/
// TODO: rancher cluster
it.only('Test Namespace filter', () => {
// TODO: go to rancher cluster
it('Test Namespace filter', () => {
const namespace = 'test'

// create a new namespace
Expand Down

0 comments on commit cfd6ee8

Please sign in to comment.