-
Notifications
You must be signed in to change notification settings - Fork 592
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
bug 1832371: CNV-4046: Add integration test for vm environment tab #5280
Merged
openshift-merge-robot
merged 1 commit into
openshift:master
from
irosenzw:vm-env-disk-integration-tests
May 6, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
87 changes: 87 additions & 0 deletions
87
.../packages/kubevirt-plugin/integration-tests/tests/utils/scripts/expect-vm-env-readable.sh
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,87 @@ | ||
#!/usr/bin/expect -f | ||
|
||
set vm_name [lindex $argv 0] | ||
set vm_namespace [lindex $argv 1] | ||
set hostname vm-example | ||
set username fedora | ||
set password fedora | ||
|
||
set login_prompt "$hostname login: " | ||
set password_prompt "Password: " | ||
set prompt "$" | ||
|
||
set response_delay 3 | ||
set timeout 10 | ||
set send_human {.1 .3 1 .05 2} | ||
|
||
set source_path1 "/home/fedora/source1" | ||
set source_path2 "/home/fedora/source2" | ||
set source_path3 "/home/fedora/source3" | ||
|
||
spawn virtctl console $vm_name -n $vm_namespace | ||
|
||
send -h "\n" | ||
|
||
sleep 1 | ||
|
||
send -h \004 | ||
|
||
# Enter username | ||
expect $login_prompt { | ||
sleep $response_delay | ||
send -h "$username\n" | ||
} | ||
|
||
# Enter Password | ||
expect $password_prompt { | ||
sleep $response_delay | ||
send -h "$password\n" | ||
} | ||
|
||
# Run tests | ||
expect $prompt { | ||
sleep $response_delay | ||
|
||
send -h "mkdir ${source_path1} \n" | ||
send -h "mkdir ${source_path2} \n" | ||
send -h "mkdir ${source_path3} \n" | ||
|
||
# mount source 1 | ||
send -h "sudo mount /dev/vdc ${source_path1} \n" | ||
|
||
# mount source 2 | ||
send -h "sudo mount /dev/vdd ${source_path2} \n" | ||
|
||
# mount source 3 | ||
send -h "sudo mount /dev/vde ${source_path3} \n" | ||
|
||
# Create readableFile func | ||
send -h "function _rf() { test -r \$1 && echo SUCCESS || echo FAILED; };\n" | ||
|
||
# Check if source1 files are readable | ||
send -h "_rf ${source_path1}/data1 \n"; | ||
send -h "_rf ${source_path1}/data2 \n"; | ||
send -h "_rf ${source_path1}/data3 \n"; | ||
|
||
# Check if source2 files are readable | ||
send -h "_rf ${source_path2}/ca.crt \n"; | ||
send -h "_rf ${source_path2}/namespace \n"; | ||
send -h "_rf ${source_path2}/service-ca.crt \n"; | ||
send -h "_rf ${source_path2}/token \n"; | ||
|
||
# Check if source3 files are readable | ||
send -h "_rf ${source_path3}/ca.crt \n"; | ||
send -h "_rf ${source_path3}/namespace \n"; | ||
send -h "_rf ${source_path3}/service-ca.crt \n"; | ||
send -h "_rf ${source_path3}/token \n"; | ||
|
||
} | ||
|
||
# exit to login prompt | ||
expect $prompt { | ||
send -h \004 | ||
expect -re $login_prompt | ||
} | ||
|
||
# exit console | ||
send \003] |
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
133 changes: 133 additions & 0 deletions
133
frontend/packages/kubevirt-plugin/integration-tests/tests/vm.environment.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,133 @@ | ||
import { getSecret, getConfigMap, getServiceAccount } from './utils/mocks'; | ||
import { createResource, deleteResource, click } from '@console/shared/src/test-utils/utils'; | ||
import { browser, ExpectedConditions as until, Key, element, by } from 'protractor'; | ||
import { createExampleVMViaYAML } from './utils/utils'; | ||
import { testName } from '@console/internal-integration-tests/protractor.conf'; | ||
import { isLoaded } from '@console/internal-integration-tests/views/crud.view'; | ||
import * as vmEnv from '../views/vm.environment.view'; | ||
import { addVariableFrom } from '@console/internal-integration-tests/views/environment.view'; | ||
import { | ||
PAGE_LOAD_TIMEOUT_SECS, | ||
KUBEVIRT_SCRIPTS_PATH, | ||
VM_BOOTUP_TIMEOUT_SECS, | ||
VM_ACTION, | ||
} from './utils/consts'; | ||
import { execSync } from 'child_process'; | ||
import { VirtualMachine } from './models/virtualMachine'; | ||
|
||
const expecScriptPath = `${KUBEVIRT_SCRIPTS_PATH}/expect-vm-env-readable.sh`; | ||
const vmName = 'vm-example'; | ||
const configmapName = 'configmap-mock'; | ||
const secretName = 'secret-mock'; | ||
const serviceAccountName = 'service-account-mock'; | ||
|
||
describe('Test VM enviromnet tab', () => { | ||
const secret = getSecret(testName, secretName); | ||
const configmap = getConfigMap(testName, configmapName); | ||
const serviceAccount = getServiceAccount(testName, serviceAccountName); | ||
let vm: VirtualMachine; | ||
|
||
beforeAll(async () => { | ||
createResource(secret); | ||
createResource(configmap); | ||
createResource(serviceAccount); | ||
const vmObj = await createExampleVMViaYAML(true); | ||
vm = new VirtualMachine(vmObj.metadata); | ||
}); | ||
|
||
afterAll(() => { | ||
deleteResource(secret); | ||
deleteResource(configmap); | ||
deleteResource(serviceAccount); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await vm.navigateToEnvironment(); | ||
}); | ||
|
||
it('Add configmap, secret and service account', async () => { | ||
await vmEnv.addSource(configmapName); | ||
await vmEnv.addSource(secretName); | ||
|
||
// Add Service Account | ||
await click( | ||
element(by.buttonText('Add All From Config Map or Secret')), | ||
PAGE_LOAD_TIMEOUT_SECS, | ||
); | ||
await addVariableFrom(serviceAccountName, null, true); | ||
await browser.wait(until.presenceOf(vmEnv.successAlert)); | ||
expect(vmEnv.successAlert.isDisplayed()).toEqual(true); | ||
}); | ||
|
||
it('Verify all the sources are present at the disks tab', async () => { | ||
const disks = await vm.getAttachedDisks(); | ||
expect(!!disks.find((d) => d.name.includes(configmapName))).toBeTruthy(); | ||
expect(!!disks.find((d) => d.name.includes(secretName))).toBeTruthy(); | ||
expect(!!disks.find((d) => d.name.includes(serviceAccountName))).toBeTruthy(); | ||
}); | ||
|
||
it( | ||
'Verify all sources are readable inside the VM', | ||
async () => { | ||
await vm.action(VM_ACTION.Start); | ||
const out = execSync(`expect ${expecScriptPath} ${vmName} ${testName}`).toString(); | ||
const isFailedTest = out.split('\n').find((line) => line === 'FAILED'); | ||
expect(!isFailedTest).toBeTruthy(); | ||
}, | ||
VM_BOOTUP_TIMEOUT_SECS * 2, // VM boot time + test sources time | ||
); | ||
|
||
it('Error when resource has no serial', async () => { | ||
await vmEnv.serialField.get(1).clear(); | ||
await vmEnv.serialField.get(1).sendKeys('i', Key.BACK_SPACE); // workaround: for some reason clear() is not enough | ||
await browser.wait(until.elementToBeClickable(vmEnv.saveBtn), PAGE_LOAD_TIMEOUT_SECS); | ||
await click(vmEnv.saveBtn, PAGE_LOAD_TIMEOUT_SECS); | ||
await browser.wait(until.presenceOf(vmEnv.errorAlert), PAGE_LOAD_TIMEOUT_SECS); | ||
const errorText = await vmEnv.errorAlert.getText(); | ||
expect(vmEnv.errorAlert.isDisplayed()).toEqual(true); | ||
expect(errorText).toContain(vmEnv.noSerialError); | ||
}); | ||
|
||
it('Error when two sources have the same serial', async () => { | ||
const firstSerial = await vmEnv.serialField.get(0).getAttribute('value'); | ||
await vmEnv.serialField.get(1).clear(); | ||
await vmEnv.serialField.get(1).sendKeys(firstSerial); | ||
await browser.wait(until.elementToBeClickable(vmEnv.saveBtn), PAGE_LOAD_TIMEOUT_SECS); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again, you could use click as mentioned before |
||
await click(vmEnv.saveBtn, PAGE_LOAD_TIMEOUT_SECS); | ||
await browser.wait(until.presenceOf(vmEnv.errorAlert), PAGE_LOAD_TIMEOUT_SECS); | ||
expect(vmEnv.errorAlert.isDisplayed()).toEqual(true); | ||
const errorText = await vmEnv.errorAlert.getText(); | ||
expect(errorText).toContain(vmEnv.dupSerialsError); | ||
}); | ||
|
||
it('Cannot use the same resource more than once', async () => { | ||
await click( | ||
element(by.buttonText('Add All From Config Map or Secret')), | ||
PAGE_LOAD_TIMEOUT_SECS, | ||
); | ||
await isLoaded(); | ||
await vmEnv.dropDownBtn | ||
.filter(async (elem) => { | ||
const elemText = await elem.getText(); | ||
return elemText === 'Select a resource'; | ||
}) | ||
.first() | ||
.click(); | ||
await vmEnv.textFilter.sendKeys(configmapName); | ||
const optionSize = await vmEnv.option | ||
.filter(async (elem) => { | ||
return (await elem.$('.co-resource-item__resource-name').getText()) === configmapName; | ||
}) | ||
.count(); | ||
expect(optionSize).toEqual(0); | ||
}); | ||
|
||
it('Delete a source', async () => { | ||
const pairCountBefore = await vmEnv.allPairRows.count(); | ||
await vmEnv.deleteButton.first().click(); | ||
await browser.wait(until.elementToBeClickable(vmEnv.saveBtn), PAGE_LOAD_TIMEOUT_SECS); | ||
await click(vmEnv.saveBtn, PAGE_LOAD_TIMEOUT_SECS); | ||
const pairCountAfter = await vmEnv.allPairRows.count(); | ||
expect(pairCountBefore).toEqual(pairCountAfter + 1); | ||
}); | ||
}); |
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 not sure if this is a good way to select a dropdown button, if I understand, this doesn't allow to change the selection in the dropdown for the second time, does it?
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.
it allows you to change the selection. this is why I need to select the dropdown which have no value.