-
Notifications
You must be signed in to change notification settings - Fork 646
KubeVirt extension PoC #888
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,37 @@ | ||
import * as _ from 'lodash'; | ||
|
||
import { VirtualMachineModel } from '../../../../../public/models'; | ||
import { getVMStatus } from '../../../../../public/extend/kubevirt/module/k8s/vms'; | ||
|
||
// TODO: add this to __mocks__/k8sResourcesMocks module, should be in sync | ||
// with VirtualMachine YAML template defined in public/models/yaml-templates | ||
const testVirtualMachine = { | ||
apiVersion: `${VirtualMachineModel.apiGroup}/${VirtualMachineModel.apiVersion}`, | ||
kind: 'VirtualMachine', | ||
metadata: { | ||
name: 'example', | ||
namespace: 'default', | ||
}, | ||
spec: { | ||
running: false, | ||
template: { | ||
// TODO: empty for now, see above comment | ||
}, | ||
}, | ||
}; | ||
|
||
describe('getVMStatus', () => { | ||
it('returns the status string based on spec.running', () => { | ||
const vm1 = _.cloneDeep(testVirtualMachine); | ||
vm1.spec.running = true; | ||
expect(getVMStatus(vm1)).toBe('Running'); | ||
|
||
const vm2 = _.cloneDeep(testVirtualMachine); | ||
vm2.spec.running = false; | ||
expect(getVMStatus(vm2)).toBe('Stopped'); | ||
|
||
const vm3 = _.cloneDeep(testVirtualMachine); | ||
vm3.spec.running = undefined; | ||
expect(getVMStatus(vm3)).toBe('Stopped'); | ||
}); | ||
}); |
This file contains hidden or 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 hidden or 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,24 @@ | ||
/* eslint-disable no-undef */ | ||
|
||
import { addAlias } from 'module-alias'; | ||
|
||
// The `lodash-es` package ships code that uses ECMAScript modules. Since `ts-node` | ||
// excludes everything under `node_modules` directory from compilation, attempting | ||
// to import `lodash-es` code yields syntax errors. | ||
// | ||
// Integration tests already use the `lodash` package, so we simply register alias | ||
// to `lodash` in context of Node.js module resolution mechanism. | ||
|
||
addAlias('lodash-es', 'lodash'); | ||
|
||
declare global { | ||
interface window { | ||
SERVER_FLAGS: object; | ||
} | ||
} | ||
|
||
(global as any).window = { | ||
SERVER_FLAGS: { | ||
basePath: '/', | ||
}, | ||
}; |
This file contains hidden or 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 hidden or 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 hidden or 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,63 @@ | ||
/* 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', | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little confused why we're just seeing this problem now. Is there a reason we don't see errors for all of our integration tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both unit and integration tests use
lodash
instead oflodash-es
package.Application code in
public
directory useslodash-es
in order to get better webpack optimization (tree shaking of ES modules).Both unit and integration tests are executed within a Node.js (v8 LTS) env.
ts-node
avoids compiling files innode_modules
directory (link). So unless the test runner explicitly supports transpilation of source files, importing code directly fromnode_modules
may result in syntax errors.Jest is configured with
ts-jest
transformer applied to.(ts|tsx|js|jsx)
when loading any kind of module, i.e. including stuff innode_modules
. Your Jest config also includes:which means that Jest won't transform anything under
node_modules/lodash-es
.On the other hand, Protractor doesn't seem to have any file transformation capability - we simply rely on
ts-node
to augment/hack the default Node.js module loading impl. by runningtsc
on files with.tsx?
and.jsx?
extensions. Again,ts-node
does not process stuff innode_modules
.So, this problem occurs only in integration tests when trying to load (import) a module from
node_modules
directory which doesn't conform to supported Node.js (v8 LTS) syntax, such aslodash-es
.@spadgett Try adding following line into
integration-tests/tests/crud.scenario.ts
:and running
yarn test-suite --suite crud
- Protractor will fail:This PR fixes the problem by adding
lodash-es
➡️lodash
alias specifically for integration tests viaintegration-tests/preload.ts
.(It also fixes another related problem where expressions like
SERVER_FLAGS.whatever
throw because the globalSERVER_FLAGS
is not defined.)Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No integration test so far attempted to import code that eventually loaded
lodash-es
module.So when I tried to import the
referenceForModel
function incrud.scenario.ts
, I ran into this 😃There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this PR adds an explicit dev-dependency on
lodash
. Up to now,lodash
was pulled intonode_modules
through some other dependencies.