This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
forked from openshift/console
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for vm list/vies actions (start, stop, ...) (#163)
- Loading branch information
Showing
7 changed files
with
292 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* eslint-disable no-undef */ | ||
import { testName } from '../../protractor.conf'; | ||
|
||
const testLabel = 'automatedTestName'; | ||
|
||
export const testVM = { | ||
apiVersion: 'kubevirt.io/v1alpha2', | ||
kind: 'VirtualMachine', | ||
metadata: { | ||
name: `vm-${testName}`, | ||
namespace: testName, | ||
labels: {[testLabel]: testName}, | ||
}, | ||
spec: { | ||
running: false, | ||
template: { | ||
spec: { | ||
domain: { | ||
cpu: { | ||
cores: 1, | ||
}, | ||
devices: { | ||
disks: [ | ||
{ | ||
bootOrder: 1, | ||
disk: { | ||
bus: 'virtio', | ||
}, | ||
name: 'rootdisk', | ||
volumeName: 'rootdisk', | ||
}, | ||
], | ||
interfaces: [ | ||
{ | ||
bridge: {}, | ||
name: 'eth0', | ||
}, | ||
], | ||
}, | ||
resources: { | ||
requests: { | ||
memory: '1G', | ||
}, | ||
}, | ||
}, | ||
networks: [ | ||
{ | ||
name: 'eth0', | ||
pod: {}, | ||
}, | ||
], | ||
volumes: [ | ||
{ | ||
containerDisk: { | ||
image: 'kubevirt/cirros-registry-disk-demo:latest', | ||
}, | ||
name: 'rootdisk', | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export const testNAD = { | ||
apiVersion: 'k8s.cni.cncf.io/v1', | ||
kind: 'NetworkAttachmentDefinition', | ||
metadata: { | ||
name: `ovs-net-1${testName}-${testName}`, | ||
namespace: testName, | ||
labels: {[testLabel]: testName}, | ||
}, | ||
spec: { | ||
config: '{ "cniVersion": "0.3.1", "type": "ovs", "bridge": "br0" }', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* eslint-disable no-undef */ | ||
import { execSync } from 'child_process'; | ||
|
||
export function removeLeakedResources(leakedResources: Set<string>){ | ||
const leakedArray: Array<string> = [...leakedResources]; | ||
if (leakedArray.length > 0) { | ||
console.error(`Leaked ${leakedArray.join()}`); | ||
leakedArray.map(r => JSON.parse(r) as {name: string, namespace: string, kind: string}) | ||
.forEach(({name, namespace, kind}) => { | ||
try { | ||
execSync(`kubectl delete -n ${namespace} --cascade ${kind} ${name}`); | ||
} catch (error) { | ||
console.error(`Failed to delete ${kind} ${name}:\n${error}`); | ||
} | ||
}); | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
frontend/integration-tests/tests/kubevirt/vm.actions.scenario.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* eslint-disable no-undef */ | ||
|
||
import { execSync } from 'child_process'; | ||
import { browser, ExpectedConditions as until } from 'protractor'; | ||
|
||
import { appHost, testName } from '../../protractor.conf'; | ||
import { resourceRowsPresent, filterForName, isLoaded } from '../../views/crud.view'; | ||
import { testVM } from './mocks'; | ||
import { removeLeakedResources } from './utils'; | ||
import {detailViewAction, detailViewVMmStatus, listViewAction, listViewVMmStatus} from '../../views/kubevirt/vm.actions.view'; | ||
|
||
const VM_BOOTUP_TIMEOUT = 60000; | ||
const VM_ACTIONS_TIMEOUT = 90000; | ||
|
||
describe('Test VM actions', () => { | ||
const leakedResources = new Set<string>(); | ||
afterAll(async() => { | ||
removeLeakedResources(leakedResources); | ||
}); | ||
|
||
describe('Test VM list view kebab actions', () => { | ||
const vmName = `vm-list-view-actions-${testName}`; | ||
beforeAll(async() => { | ||
testVM.metadata.name = vmName; | ||
execSync(`echo '${JSON.stringify(testVM)}' | kubectl create -f -`); | ||
leakedResources.add(JSON.stringify({name: vmName, namespace: testName, kind: 'vm'})); | ||
}); | ||
|
||
// Workaround for https://github.com/kubevirt/web-ui/issues/177, remove when resolved | ||
afterEach(async() => await browser.sleep(1000)); | ||
|
||
it('Navigates to VMs', async() => { | ||
await browser.get(`${appHost}/k8s/all-namespaces/virtualmachines`); | ||
await isLoaded(); | ||
await filterForName(vmName); | ||
await resourceRowsPresent(); | ||
}); | ||
|
||
it('Starts VM', async() => { | ||
await listViewAction(vmName)('Start'); | ||
await browser.wait(until.textToBePresentInElement(listViewVMmStatus(vmName), 'Running'), VM_BOOTUP_TIMEOUT); | ||
}); | ||
|
||
it('Restarts VM', async() => { | ||
await listViewAction(vmName)('Restart'); | ||
await browser.wait(until.textToBePresentInElement(listViewVMmStatus(vmName), 'Starting'), VM_BOOTUP_TIMEOUT); | ||
await browser.wait(until.textToBePresentInElement(listViewVMmStatus(vmName), 'Running'), VM_BOOTUP_TIMEOUT); | ||
}, VM_ACTIONS_TIMEOUT); | ||
|
||
it('Stops VM', async() => { | ||
await listViewAction(vmName)('Stop'); | ||
await browser.wait(until.textToBePresentInElement(listViewVMmStatus(vmName), 'Off'), 10000); | ||
}); | ||
|
||
it('Deletes VM', async() => { | ||
await listViewAction(vmName)('Delete'); | ||
await browser.wait(until.not(until.presenceOf(listViewVMmStatus(vmName)))); | ||
leakedResources.delete(JSON.stringify({name: vmName, namespace: testName, kind: 'vm'})); | ||
}); | ||
}); | ||
|
||
describe('Test VM detail view kebab actions', () => { | ||
const vmName = `vm-detail-view-actions-${testName}`; | ||
beforeAll(async() => { | ||
testVM.metadata.name = vmName; | ||
execSync(`echo '${JSON.stringify(testVM)}' | kubectl create -f -`); | ||
leakedResources.add(JSON.stringify({name: vmName, namespace: testName, kind: 'vm'})); | ||
}); | ||
|
||
it('Navigates to VMs detail page', async() => { | ||
await browser.get(`${appHost}/k8s/all-namespaces/virtualmachines/${vmName}`); | ||
await isLoaded(); | ||
}); | ||
|
||
it('Starts VM', async() => { | ||
await detailViewAction('Start'); | ||
await browser.wait(until.textToBePresentInElement(detailViewVMmStatus, 'Running'), VM_BOOTUP_TIMEOUT); | ||
}); | ||
|
||
it('Restarts VM', async() => { | ||
await detailViewAction('Restart'); | ||
await browser.wait(until.textToBePresentInElement(detailViewVMmStatus, 'Starting'), VM_BOOTUP_TIMEOUT); | ||
await browser.wait(until.textToBePresentInElement(detailViewVMmStatus, 'Running'), VM_BOOTUP_TIMEOUT); | ||
}, VM_ACTIONS_TIMEOUT); | ||
|
||
it('Stops VM', async() => { | ||
await detailViewAction('Stop'); | ||
await browser.wait(until.textToBePresentInElement(detailViewVMmStatus, 'Off'), 10000); | ||
}); | ||
|
||
it('Deletes VM', async() => { | ||
await detailViewAction('Delete'); | ||
leakedResources.delete(JSON.stringify({name: vmName, namespace: testName, kind: 'vm'})); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.