-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add 'AnsibleDevFileAPI' E2E test #23456
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
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
74b13d6
Add mmethods to pageobject
artaleks9 f0b6e28
Add 'AnsibleDevFileAP' E2E test
artaleks9 639ed17
Fix up
artaleks9 8790aff
Merge branch 'main' of github.com:eclipse/che into crw-7997
artaleks9 fddeacb
Add changes accordig to review
artaleks9 ec65529
Increase timeout to reliability
artaleks9 2ecc167
Change method according to the review
artaleks9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,313 @@ | ||
/** ******************************************************************* | ||
* copyright (c) 2025 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
**********************************************************************/ | ||
|
||
import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS'; | ||
import { e2eContainer } from '../../configs/inversify.config'; | ||
import { CLASSES } from '../../configs/inversify.types'; | ||
import { DevfilesHelper } from '../../utils/DevfilesHelper'; | ||
import { ContainerTerminal, KubernetesCommandLineToolsExecutor } from '../../utils/KubernetesCommandLineToolsExecutor'; | ||
import { DevWorkspaceConfigurationHelper } from '../../utils/DevWorkspaceConfigurationHelper'; | ||
import { DevfileContext } from '@eclipse-che/che-devworkspace-generator/lib/api/devfile-context'; | ||
import { ShellString } from 'shelljs'; | ||
import { expect } from 'chai'; | ||
import { API_TEST_CONSTANTS } from '../../constants/API_TEST_CONSTANTS'; | ||
import YAML from 'yaml'; | ||
import { Logger } from '../../utils/Logger'; | ||
import crypto from 'crypto'; | ||
|
||
suite('Ansible devfile API test', function (): void { | ||
const devfilesRegistryHelper: DevfilesHelper = e2eContainer.get(CLASSES.DevfilesRegistryHelper); | ||
const kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = e2eContainer.get( | ||
CLASSES.KubernetesCommandLineToolsExecutor | ||
); | ||
const devfileID: string = 'ansible'; | ||
const serviceNameToPortForward: string = BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME() + '-dashboard'; | ||
// namespace where the application is deployed to port-forward the service | ||
const applicationNamespace: string = 'openshift-' + BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME(); | ||
const containerTerminal: ContainerTerminal = e2eContainer.get(CLASSES.ContainerTerminal); | ||
let devWorkspaceConfigurationHelper: DevWorkspaceConfigurationHelper; | ||
let devfileContext: DevfileContext; | ||
let devfileContent: string = ''; | ||
let devfileName: string = ''; | ||
|
||
suiteSetup(`Prepare login ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void { | ||
kubernetesCommandLineToolsExecutor.loginToOcp(); | ||
}); | ||
|
||
test(`Create ${devfileID} workspace`, async function (): Promise<void> { | ||
const randomPref: string = crypto.randomBytes(4).toString('hex'); | ||
kubernetesCommandLineToolsExecutor.namespace = API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE; | ||
devfileContent = devfilesRegistryHelper.getDevfileContent(devfileID); | ||
const editorDevfileContent: string = devfilesRegistryHelper.obtainCheDevFileEditorFromCheConfigMap('editors-definitions'); | ||
devfileName = YAML.parse(devfileContent).metadata.name; | ||
const uniqueName: string = YAML.parse(devfileContent).metadata.name + randomPref; | ||
kubernetesCommandLineToolsExecutor.workspaceName = uniqueName; | ||
|
||
devWorkspaceConfigurationHelper = new DevWorkspaceConfigurationHelper({ | ||
editorContent: editorDevfileContent, | ||
devfileContent: devfileContent | ||
}); | ||
devfileContext = await devWorkspaceConfigurationHelper.generateDevfileContext(); | ||
if (devfileContext.devWorkspace.metadata) { | ||
devfileContext.devWorkspace.metadata.name = uniqueName; | ||
} | ||
const devWorkspaceConfigurationYamlString: string = | ||
devWorkspaceConfigurationHelper.getDevWorkspaceConfigurationYamlAsString(devfileContext); | ||
const output: ShellString = kubernetesCommandLineToolsExecutor.applyAndWaitDevWorkspace(devWorkspaceConfigurationYamlString); | ||
expect(output.stdout).contains('condition met'); | ||
|
||
Logger.info('Inject kubeconfig to workspace'); | ||
kubernetesCommandLineToolsExecutor.startTcpPortForward(serviceNameToPortForward, applicationNamespace); | ||
const devworkspaceId: string = kubernetesCommandLineToolsExecutor.getDevWorkspaceId(); | ||
kubernetesCommandLineToolsExecutor.injectKubeConfig(devworkspaceId); | ||
}); | ||
|
||
test('Check "molecule-create" command', function (): void { | ||
const containerName: string = YAML.parse(devfileContent).commands[0].exec.component; | ||
const workdir: string = YAML.parse(devfileContent).commands[0].exec.workingDir; | ||
const commandLine: string = YAML.parse(devfileContent).commands[0].exec.commandLine; | ||
Logger.info(`workdir from exec section of DevWorkspace file: ${workdir}`); | ||
Logger.info(`commandLine from exec section of DevWorkspace file: ${commandLine}`); | ||
|
||
const safeCommandLine: string = commandLine.replace( | ||
'/source\s+\$HOME\/\.bashrc/', | ||
'[ -f "$HOME/.bashrc" ] && . "$HOME/.bashrc" || true' | ||
); | ||
|
||
let runCommandInBash: string; | ||
if (workdir) { | ||
runCommandInBash = `cd ${workdir} && ${safeCommandLine}`; | ||
} else { | ||
runCommandInBash = `${safeCommandLine}`; | ||
} | ||
|
||
const output: ShellString = containerTerminal.execInContainerCommand(runCommandInBash, containerName); | ||
expect(output.code).eqls(0); | ||
|
||
const recapBlocks: string[] = output.stdout.split(/PLAY RECAP/g).slice(1); | ||
recapBlocks.forEach((block): void => { | ||
expect(block).match(/failed\s*=\s*0/); | ||
}); | ||
|
||
const outputText: string = output.stdout.trim(); | ||
expect(outputText).to.include('was installed successfully'); | ||
expect(outputText).to.not.include('failed=1'); | ||
}); | ||
|
||
test('Check "molecule-list" command', function (): void { | ||
const containerName: string = YAML.parse(devfileContent).commands[1].exec.component; | ||
const workdir: string = YAML.parse(devfileContent).commands[1].exec.workingDir; | ||
const commandLine: string = YAML.parse(devfileContent).commands[1].exec.commandLine; | ||
Logger.info(`workdir from exec section of DevWorkspace file: ${workdir}`); | ||
Logger.info(`commandLine from exec section of DevWorkspace file: ${commandLine}`); | ||
|
||
const safeCommandLine: string = commandLine.replace( | ||
'/source\s+\$HOME\/\.bashrc/', | ||
'[ -f "$HOME/.bashrc" ] && . "$HOME/.bashrc" || true' | ||
); | ||
|
||
let runCommandInBash: string; | ||
if (workdir) { | ||
runCommandInBash = `cd ${workdir} && ${safeCommandLine}`; | ||
} else { | ||
runCommandInBash = `${safeCommandLine}`; | ||
} | ||
|
||
const output: ShellString = containerTerminal.execInContainerCommand(runCommandInBash, containerName); | ||
expect(output.code).eqls(0); | ||
|
||
const outputText: string = output.stdout.trim(); | ||
expect(outputText).to.include('molecule'); | ||
expect(outputText).to.include('ansible'); | ||
expect(outputText).to.include('default'); | ||
expect(outputText).to.include('true'); | ||
}); | ||
|
||
test('Check "molecule-converge" command', function (): void { | ||
const containerName: string = YAML.parse(devfileContent).commands[2].exec.component; | ||
const workdir: string = YAML.parse(devfileContent).commands[2].exec.workingDir; | ||
const commandLine: string = YAML.parse(devfileContent).commands[2].exec.commandLine; | ||
Logger.info(`workdir from exec section of DevWorkspace file: ${workdir}`); | ||
Logger.info(`commandLine from exec section of DevWorkspace file: ${commandLine}`); | ||
|
||
const safeCommandLine: string = commandLine.replace( | ||
'/source\s+\$HOME\/\.bashrc/', | ||
'[ -f "$HOME/.bashrc" ] && . "$HOME/.bashrc" || true' | ||
); | ||
|
||
let runCommandInBash: string; | ||
if (workdir) { | ||
runCommandInBash = `cd ${workdir} && ${safeCommandLine}`; | ||
} else { | ||
runCommandInBash = `${safeCommandLine}`; | ||
} | ||
|
||
const output: ShellString = containerTerminal.execInContainerCommand(runCommandInBash, containerName); | ||
expect(output.code).eqls(0); | ||
|
||
const recapBlocks: string[] = output.stdout.split(/PLAY RECAP/g).slice(1); | ||
recapBlocks.forEach((block): void => { | ||
expect(block).match(/failed\s*=\s*0/); | ||
}); | ||
|
||
const outputText: string = output.stdout.trim(); | ||
expect(outputText).to.include('PLAY [Converge]'); | ||
expect(outputText).to.not.include('failed=1'); | ||
}); | ||
|
||
test('Check "molecule-verify" command', function (): void { | ||
const containerName: string = YAML.parse(devfileContent).commands[3].exec.component; | ||
const workdir: string = YAML.parse(devfileContent).commands[3].exec.workingDir; | ||
const commandLine: string = YAML.parse(devfileContent).commands[3].exec.commandLine; | ||
Logger.info(`workdir from exec section of DevWorkspace file: ${workdir}`); | ||
Logger.info(`commandLine from exec section of DevWorkspace file: ${commandLine}`); | ||
|
||
const safeCommandLine: string = commandLine.replace( | ||
'/source\s+\$HOME\/\.bashrc/', | ||
'[ -f "$HOME/.bashrc" ] && . "$HOME/.bashrc" || true' | ||
); | ||
|
||
let runCommandInBash: string; | ||
if (workdir) { | ||
runCommandInBash = `cd ${workdir} && ${safeCommandLine}`; | ||
} else { | ||
runCommandInBash = `${safeCommandLine}`; | ||
} | ||
|
||
const output: ShellString = containerTerminal.execInContainerCommand(runCommandInBash, containerName); | ||
expect(output.code).eqls(0); | ||
|
||
const recapBlocks: string[] = output.stdout.split(/PLAY RECAP/g).slice(1); | ||
recapBlocks.forEach((block): void => { | ||
expect(block).match(/failed\s*=\s*0/); | ||
}); | ||
|
||
const outputText: string = output.stdout.trim(); | ||
expect(outputText).to.include('PLAY [Verify]'); | ||
expect(outputText).to.not.include('failed=1'); | ||
}); | ||
|
||
test('Check "molecule-destroy" command', function (): void { | ||
const containerName: string = YAML.parse(devfileContent).commands[4].exec.component; | ||
const workdir: string = YAML.parse(devfileContent).commands[4].exec.workingDir; | ||
const commandLine: string = YAML.parse(devfileContent).commands[4].exec.commandLine; | ||
Logger.info(`workdir from exec section of DevWorkspace file: ${workdir}`); | ||
Logger.info(`commandLine from exec section of DevWorkspace file: ${commandLine}`); | ||
|
||
const safeCommandLine: string = commandLine.replace( | ||
'/source\s+\$HOME\/\.bashrc/', | ||
'[ -f "$HOME/.bashrc" ] && . "$HOME/.bashrc" || true' | ||
); | ||
|
||
let runCommandInBash: string; | ||
if (workdir) { | ||
runCommandInBash = `cd ${workdir} && ${safeCommandLine}`; | ||
} else { | ||
runCommandInBash = `${safeCommandLine}`; | ||
} | ||
|
||
const output: ShellString = containerTerminal.execInContainerCommand(runCommandInBash, containerName); | ||
expect(output.code).eqls(0); | ||
|
||
const recapBlocks: string[] = output.stdout.split(/PLAY RECAP/g).slice(1); | ||
recapBlocks.forEach((block): void => { | ||
expect(block).match(/failed\s*=\s*0/); | ||
}); | ||
|
||
const outputText: string = output.stdout.trim(); | ||
expect(outputText).to.include('PLAY [Destroy]'); | ||
expect(outputText).to.not.include('failed=1'); | ||
}); | ||
|
||
test('Check "molecule-test" command', function (): void { | ||
const containerName: string = YAML.parse(devfileContent).commands[5].exec.component; | ||
const workdir: string = YAML.parse(devfileContent).commands[5].exec.workingDir; | ||
const commandLine: string = YAML.parse(devfileContent).commands[5].exec.commandLine; | ||
Logger.info(`workdir from exec section of DevWorkspace file: ${workdir}`); | ||
Logger.info(`commandLine from exec section of DevWorkspace file: ${commandLine}`); | ||
|
||
const safeCommandLine: string = commandLine.replace( | ||
'/source\s+\$HOME\/\.bashrc/', | ||
'[ -f "$HOME/.bashrc" ] && . "$HOME/.bashrc" || true' | ||
); | ||
|
||
let runCommandInBash: string; | ||
if (workdir) { | ||
runCommandInBash = `cd ${workdir} && ${safeCommandLine}`; | ||
} else { | ||
runCommandInBash = `${safeCommandLine}`; | ||
} | ||
|
||
const output: ShellString = containerTerminal.execInContainerCommand(runCommandInBash, containerName); | ||
expect(output.code).eqls(0); | ||
|
||
const recapBlocks: string[] = output.stdout.split(/PLAY RECAP/g).slice(1); | ||
recapBlocks.forEach((block): void => { | ||
expect(block).match(/failed\s*=\s*0/); | ||
}); | ||
|
||
const outputText: string = output.stdout.trim(); | ||
expect(outputText).to.include('PLAY [Create]'); | ||
expect(outputText).to.include('PLAY [Converge]'); | ||
expect(outputText).to.include('PLAY [Verify]'); | ||
expect(outputText).to.not.include('failed=1'); | ||
}); | ||
|
||
test('Check "ansible-navigator" command', function (): void { | ||
const containerName: string = YAML.parse(devfileContent).commands[6].exec.component; | ||
const workdir: string = YAML.parse(devfileContent).commands[6].exec.workingDir; | ||
const rawCommandLines: string = YAML.parse(devfileContent).commands[6].exec.commandLine; | ||
Logger.info(`workdir from exec section of DevWorkspace file: ${workdir}`); | ||
Logger.info(`commandLine from exec section of DevWorkspace file: \n${rawCommandLines}`); | ||
|
||
const modifiedLines: string[] = rawCommandLines | ||
.trim() | ||
.split('\n') | ||
.map((line): string => { | ||
const trimmed: string = line.trim(); | ||
if (trimmed.startsWith('if [ ! -d') || trimmed === 'fi') { | ||
return ''; // remove conditional checks | ||
} | ||
if (trimmed.startsWith('ansible-navigator')) { | ||
// '--help' with '--mode stdout' disables interactive mode and ensures stable, testable output from ansible-navigator | ||
const safeCommandLine: string = trimmed + ' --help --mode stdout'; | ||
return safeCommandLine; | ||
} | ||
|
||
return trimmed; | ||
}) | ||
.filter(Boolean); | ||
|
||
const modifiedScript: string = modifiedLines.join(' && '); | ||
const patchedCommandLine: string = `bash -c \"${modifiedScript}\"`; | ||
|
||
let runCommandInBash: string; | ||
if (workdir) { | ||
runCommandInBash = `cd ${workdir} && ${patchedCommandLine}`; | ||
} else { | ||
runCommandInBash = `${patchedCommandLine}`; | ||
} | ||
|
||
const output: ShellString = containerTerminal.execInContainerCommand(runCommandInBash, containerName); | ||
expect(output.code).eqls(0); | ||
|
||
const outputText: string = output.stdout.trim(); | ||
expect(outputText).to.include('ansible-navigator'); | ||
expect(outputText).to.include('collections'); | ||
expect(outputText).to.include('config'); | ||
expect(outputText).to.include('settings'); | ||
expect(outputText).to.include('welcome'); | ||
}); | ||
|
||
suiteTeardown('Delete DevWorkspace', function (): void { | ||
kubernetesCommandLineToolsExecutor.stopTcpPortForward(); | ||
kubernetesCommandLineToolsExecutor.deleteDevWorkspace(devfileName); | ||
}); | ||
}); |
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.
Uh oh!
There was an error while loading. Please reload this page.