From 9c3a9280f988d26f68cdfe6835682ea87ed53539 Mon Sep 17 00:00:00 2001 From: mmusiien Date: Fri, 11 Oct 2024 00:28:48 +0300 Subject: [PATCH 1/7] init commit --- tests/e2e/specs/api/AnsibleDevFileAPI.spec.ts | 39 +++++++++++++++++++ tests/e2e/specs/api/EmptyWorkspaceAPI.spec.ts | 3 +- tests/e2e/utils/DevfilesRegistryHelper.ts | 34 ++++++++++++++-- 3 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 tests/e2e/specs/api/AnsibleDevFileAPI.spec.ts diff --git a/tests/e2e/specs/api/AnsibleDevFileAPI.spec.ts b/tests/e2e/specs/api/AnsibleDevFileAPI.spec.ts new file mode 100644 index 00000000000..812999f0e6c --- /dev/null +++ b/tests/e2e/specs/api/AnsibleDevFileAPI.spec.ts @@ -0,0 +1,39 @@ +/** ******************************************************************* + * copyright (c) 2023 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 {Logger} from "../../utils/Logger"; +import {DevfilesRegistryHelper} from "../../utils/DevfilesRegistryHelper"; +import {KubernetesCommandLineToolsExecutor} from "../../utils/KubernetesCommandLineToolsExecutor"; +import {ShellExecutor} from "../../utils/ShellExecutor"; + +suite('Ansible devfile API test', function (): void { + const devfilesRegistryHelper: DevfilesRegistryHelper = e2eContainer.get(CLASSES.DevfilesRegistryHelper); + const kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = e2eContainer.get(CLASSES.KubernetesCommandLineToolsExecutor); + const shellExecutor: ShellExecutor = e2eContainer.get(CLASSES.ShellExecutor); + + suiteSetup(`Prepare login ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, async function (): Promise { + kubernetesCommandLineToolsExecutor.loginToOcp(); + }); + + test('Test getting URL', function (): void { + const podName: string = shellExecutor.executeArbitraryShellScript(`oc get pods -n ${BASE_TEST_CONSTANTS.TEST_NAMESPACE} | grep dashboard | awk \'{print $1}\'`).trim() + const containerName: string = shellExecutor.executeArbitraryShellScript(`oc get pod -n ${BASE_TEST_CONSTANTS.TEST_NAMESPACE} ${podName} -o jsonpath=\'{.spec.containers[*].name}\'`) + const devFileContent: string = devfilesRegistryHelper.obtainDevFileContentUsingPod(podName,containerName,'ansible'); + + }); + + + + suiteTeardown('Delete workspace', function (): void { + Logger.trace('Tearing down the workspace'); + }); +}); diff --git a/tests/e2e/specs/api/EmptyWorkspaceAPI.spec.ts b/tests/e2e/specs/api/EmptyWorkspaceAPI.spec.ts index 7a508ec91e9..cca2122e3a7 100644 --- a/tests/e2e/specs/api/EmptyWorkspaceAPI.spec.ts +++ b/tests/e2e/specs/api/EmptyWorkspaceAPI.spec.ts @@ -34,9 +34,10 @@ suite('Empty workspace API test', function (): void { suiteSetup(`Create empty workspace with OC client ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, async function (): Promise { const workspaceName: string = 'empty-' + Math.floor(Math.random() * 1000); const devfileContent: string = 'schemaVersion: 2.2.0\n' + 'metadata:\n' + ` name: ${workspaceName}\n`; + const editorContent:string=''; devWorkspaceConfigurationHelper = new DevWorkspaceConfigurationHelper({ - devfileContent + devfileContent, editorContent }); devfileContext = await devWorkspaceConfigurationHelper.generateDevfileContext(); devWorkspaceName = devfileContext?.devWorkspace?.metadata?.name; diff --git a/tests/e2e/utils/DevfilesRegistryHelper.ts b/tests/e2e/utils/DevfilesRegistryHelper.ts index 74834be0c1d..bb0c4120863 100644 --- a/tests/e2e/utils/DevfilesRegistryHelper.ts +++ b/tests/e2e/utils/DevfilesRegistryHelper.ts @@ -13,9 +13,19 @@ import YAML from 'yaml'; import { API_TEST_CONSTANTS, SUPPORTED_DEVFILE_REGISTRIES } from '../constants/API_TEST_CONSTANTS'; import { injectable } from 'inversify'; import { BASE_TEST_CONSTANTS, Platform } from '../constants/BASE_TEST_CONSTANTS'; +import {ShellExecutor} from "./ShellExecutor"; +import {e2eContainer} from "../configs/inversify.config"; +import {CLASSES} from "../configs/inversify.types"; @injectable() export class DevfilesRegistryHelper { + private getShellExecutor(): ShellExecutor { + return e2eContainer.get(CLASSES.ShellExecutor); + } + /** + * @deprecated applicable only for inbuilt devfiles + * @param sampleNamePatterns + */ async getInbuiltDevfilesRegistryContent(sampleNamePatterns?: string[]): Promise { Logger.trace(); @@ -35,6 +45,12 @@ export class DevfilesRegistryHelper { return await this.getContent(url); } + /** + * + * @deprecated applicable only for inbuilt devfiles + * @param isInbuilt + * @param sampleNamePatterns + */ async collectPathsToDevfilesFromRegistry(isInbuilt: boolean, sampleNamePatterns?: string[]): Promise { Logger.debug(); @@ -86,9 +102,6 @@ export class DevfilesRegistryHelper { return devfileSamples; } - async getEditorContent(entry: string): Promise { - return await this.getContent(`${BASE_TEST_CONSTANTS.TS_SELENIUM_BASE_URL}/${entry}`); - } private filterSamples(sampleNamePatterns: string[] | undefined, content: any): Promise { if (sampleNamePatterns) { @@ -120,4 +133,19 @@ export class DevfilesRegistryHelper { } return response?.data; } + + public getInternalClusterURLToDevFile(devFileName:string): string { + let devfileSampleURIPrefix:string = `/dashboard/api/airgap-sample/devfile/download?id=${devFileName}`; + let serviceClusterIp:string = '' + let servicePort:string = '' + serviceClusterIp = this.getShellExecutor().executeArbitraryShellScript(`oc get svc devspaces-dashboard -n ${BASE_TEST_CONSTANTS.TEST_NAMESPACE} -o=jsonpath='{.spec.clusterIP}'`); + servicePort = this.getShellExecutor().executeArbitraryShellScript(`oc get svc devspaces-dashboard -n ${BASE_TEST_CONSTANTS.TEST_NAMESPACE} -o=jsonpath='{.spec.ports[*].port}'`); + return `http://${serviceClusterIp}:${servicePort}${devfileSampleURIPrefix}`; + } + + public obtainDevFileContentUsingPod(podName:string, containerName:string, devFileName:string): string { + const clusterURL:string = this.getInternalClusterURLToDevFile(devFileName); + this.getShellExecutor().executeCommand(`oc exec -i ${podName} -n ${BASE_TEST_CONSTANTS.TEST_NAMESPACE} -c ${containerName} -- sh -c 'curl -o /tmp/${devFileName}-devfile.yaml ${clusterURL}'`); + return this.getShellExecutor().executeArbitraryShellScript(`oc exec -i ${podName} -n ${BASE_TEST_CONSTANTS.TEST_NAMESPACE} -c ${containerName} -- cat /tmp/${devFileName}-devfile.yaml`).toString(); + } } From c0c507dc9eedb0820b82ec3cf411f46e72819a06 Mon Sep 17 00:00:00 2001 From: mmusiien Date: Thu, 17 Oct 2024 15:53:46 +0300 Subject: [PATCH 2/7] Add POC wich extract and generate the Ansible devfile and create the DevWorkspace --- tests/e2e/specs/api/AnsibleDevFileAPI.spec.ts | 28 ++++++++++++++++--- tests/e2e/utils/DevfilesRegistryHelper.ts | 12 +++++--- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/tests/e2e/specs/api/AnsibleDevFileAPI.spec.ts b/tests/e2e/specs/api/AnsibleDevFileAPI.spec.ts index 812999f0e6c..bd1427eb5d5 100644 --- a/tests/e2e/specs/api/AnsibleDevFileAPI.spec.ts +++ b/tests/e2e/specs/api/AnsibleDevFileAPI.spec.ts @@ -14,21 +14,41 @@ import {Logger} from "../../utils/Logger"; import {DevfilesRegistryHelper} from "../../utils/DevfilesRegistryHelper"; import {KubernetesCommandLineToolsExecutor} from "../../utils/KubernetesCommandLineToolsExecutor"; import {ShellExecutor} from "../../utils/ShellExecutor"; +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"; suite('Ansible devfile API test', function (): void { const devfilesRegistryHelper: DevfilesRegistryHelper = e2eContainer.get(CLASSES.DevfilesRegistryHelper); const kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = e2eContainer.get(CLASSES.KubernetesCommandLineToolsExecutor); const shellExecutor: ShellExecutor = e2eContainer.get(CLASSES.ShellExecutor); + let devWorkspaceConfigurationHelper: DevWorkspaceConfigurationHelper; + let devfileContext: DevfileContext; suiteSetup(`Prepare login ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, async function (): Promise { kubernetesCommandLineToolsExecutor.loginToOcp(); + }); - test('Test getting URL', function (): void { - const podName: string = shellExecutor.executeArbitraryShellScript(`oc get pods -n ${BASE_TEST_CONSTANTS.TEST_NAMESPACE} | grep dashboard | awk \'{print $1}\'`).trim() - const containerName: string = shellExecutor.executeArbitraryShellScript(`oc get pod -n ${BASE_TEST_CONSTANTS.TEST_NAMESPACE} ${podName} -o jsonpath=\'{.spec.containers[*].name}\'`) - const devFileContent: string = devfilesRegistryHelper.obtainDevFileContentUsingPod(podName,containerName,'ansible'); + test('Create ', async function (): Promise { + kubernetesCommandLineToolsExecutor.namespace = 'admin-devspaces'; + const podName: string = shellExecutor.executeArbitraryShellScript(`oc get pods -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE} | grep dashboard | awk \'{print $1}\'`).trim() + const containerName: string = shellExecutor.executeArbitraryShellScript(`oc get pod -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE} ${podName} -o jsonpath=\'{.spec.containers[*].name}\'`) + const devfileContent: string = devfilesRegistryHelper.obtainDevFileContentUsingPod(podName,containerName,'ansible'); + const editorDevfileContent: string = devfilesRegistryHelper.obtainCheDevFileEditor('editors-definitions'); + + + devWorkspaceConfigurationHelper = new DevWorkspaceConfigurationHelper({ + editorContent: editorDevfileContent, devfileContent: devfileContent + }); + devfileContext = await devWorkspaceConfigurationHelper.generateDevfileContext(); + const devWorkspaceConfigurationYamlString: string = + devWorkspaceConfigurationHelper.getDevWorkspaceConfigurationYamlAsString(devfileContext); + const output: ShellString = kubernetesCommandLineToolsExecutor.applyAndWaitDevWorkspace(devWorkspaceConfigurationYamlString); + expect(output.stdout).contains('condition met'); }); diff --git a/tests/e2e/utils/DevfilesRegistryHelper.ts b/tests/e2e/utils/DevfilesRegistryHelper.ts index bb0c4120863..ff12a9adbc1 100644 --- a/tests/e2e/utils/DevfilesRegistryHelper.ts +++ b/tests/e2e/utils/DevfilesRegistryHelper.ts @@ -138,14 +138,18 @@ export class DevfilesRegistryHelper { let devfileSampleURIPrefix:string = `/dashboard/api/airgap-sample/devfile/download?id=${devFileName}`; let serviceClusterIp:string = '' let servicePort:string = '' - serviceClusterIp = this.getShellExecutor().executeArbitraryShellScript(`oc get svc devspaces-dashboard -n ${BASE_TEST_CONSTANTS.TEST_NAMESPACE} -o=jsonpath='{.spec.clusterIP}'`); - servicePort = this.getShellExecutor().executeArbitraryShellScript(`oc get svc devspaces-dashboard -n ${BASE_TEST_CONSTANTS.TEST_NAMESPACE} -o=jsonpath='{.spec.ports[*].port}'`); + serviceClusterIp = this.getShellExecutor().executeArbitraryShellScript(`oc get svc devspaces-dashboard -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE} -o=jsonpath='{.spec.clusterIP}'`); + servicePort = this.getShellExecutor().executeArbitraryShellScript(`oc get svc devspaces-dashboard -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE} -o=jsonpath='{.spec.ports[*].port}'`); return `http://${serviceClusterIp}:${servicePort}${devfileSampleURIPrefix}`; } public obtainDevFileContentUsingPod(podName:string, containerName:string, devFileName:string): string { const clusterURL:string = this.getInternalClusterURLToDevFile(devFileName); - this.getShellExecutor().executeCommand(`oc exec -i ${podName} -n ${BASE_TEST_CONSTANTS.TEST_NAMESPACE} -c ${containerName} -- sh -c 'curl -o /tmp/${devFileName}-devfile.yaml ${clusterURL}'`); - return this.getShellExecutor().executeArbitraryShellScript(`oc exec -i ${podName} -n ${BASE_TEST_CONSTANTS.TEST_NAMESPACE} -c ${containerName} -- cat /tmp/${devFileName}-devfile.yaml`).toString(); + this.getShellExecutor().executeCommand(`oc exec -i ${podName} -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE} -c ${containerName} -- sh -c 'curl -o /tmp/${devFileName}-devfile.yaml ${clusterURL}'`); + return this.getShellExecutor().executeArbitraryShellScript(`oc exec -i ${podName} -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE} -c ${containerName} -- cat /tmp/${devFileName}-devfile.yaml`).toString(); + } + + public obtainCheDevFileEditor(configMapName: string): string { + return this.getShellExecutor().executeCommand(`oc get configmap ${configMapName} -o jsonpath="{.data.che-code\\.yaml}" -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE}`); } } From 7ecb3555cf958cbe68c9a3bc9ce7566b78ad6545 Mon Sep 17 00:00:00 2001 From: mmusiien Date: Mon, 21 Oct 2024 00:09:31 +0300 Subject: [PATCH 3/7] add working POC for php --- ...vFileAPI.spec.ts => PhpDevFileAPI.spec.ts} | 29 +++++++++++++------ .../utils/DevWorkspaceConfigurationHelper.ts | 2 ++ tests/e2e/utils/DevfilesRegistryHelper.ts | 9 ++++++ 3 files changed, 31 insertions(+), 9 deletions(-) rename tests/e2e/specs/api/{AnsibleDevFileAPI.spec.ts => PhpDevFileAPI.spec.ts} (66%) diff --git a/tests/e2e/specs/api/AnsibleDevFileAPI.spec.ts b/tests/e2e/specs/api/PhpDevFileAPI.spec.ts similarity index 66% rename from tests/e2e/specs/api/AnsibleDevFileAPI.spec.ts rename to tests/e2e/specs/api/PhpDevFileAPI.spec.ts index bd1427eb5d5..a4775597cfd 100644 --- a/tests/e2e/specs/api/AnsibleDevFileAPI.spec.ts +++ b/tests/e2e/specs/api/PhpDevFileAPI.spec.ts @@ -12,33 +12,35 @@ import { e2eContainer } from '../../configs/inversify.config'; import { CLASSES } from '../../configs/inversify.types'; import {Logger} from "../../utils/Logger"; import {DevfilesRegistryHelper} from "../../utils/DevfilesRegistryHelper"; -import {KubernetesCommandLineToolsExecutor} from "../../utils/KubernetesCommandLineToolsExecutor"; +import {ContainerTerminal, KubernetesCommandLineToolsExecutor} from "../../utils/KubernetesCommandLineToolsExecutor"; import {ShellExecutor} from "../../utils/ShellExecutor"; 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 {StringUtil} from "../../utils/StringUtil"; +import {string} from "yaml/dist/schema/common/string"; + suite('Ansible devfile API test', function (): void { const devfilesRegistryHelper: DevfilesRegistryHelper = e2eContainer.get(CLASSES.DevfilesRegistryHelper); const kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = e2eContainer.get(CLASSES.KubernetesCommandLineToolsExecutor); - const shellExecutor: ShellExecutor = e2eContainer.get(CLASSES.ShellExecutor); + let containerTerminal: ContainerTerminal = e2eContainer.get(CLASSES.ContainerTerminal); let devWorkspaceConfigurationHelper: DevWorkspaceConfigurationHelper; let devfileContext: DevfileContext; + let devfileContent: string =''; suiteSetup(`Prepare login ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, async function (): Promise { kubernetesCommandLineToolsExecutor.loginToOcp(); - }); - test('Create ', async function (): Promise { + test('Create PHP DevSpace', async function (): Promise { kubernetesCommandLineToolsExecutor.namespace = 'admin-devspaces'; - const podName: string = shellExecutor.executeArbitraryShellScript(`oc get pods -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE} | grep dashboard | awk \'{print $1}\'`).trim() - const containerName: string = shellExecutor.executeArbitraryShellScript(`oc get pod -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE} ${podName} -o jsonpath=\'{.spec.containers[*].name}\'`) - const devfileContent: string = devfilesRegistryHelper.obtainDevFileContentUsingPod(podName,containerName,'ansible'); + devfileContent = devfilesRegistryHelper.getDevfileContent('php'); const editorDevfileContent: string = devfilesRegistryHelper.obtainCheDevFileEditor('editors-definitions'); - + kubernetesCommandLineToolsExecutor.workspaceName = YAML.parse(devfileContent).metadata.name; devWorkspaceConfigurationHelper = new DevWorkspaceConfigurationHelper({ editorContent: editorDevfileContent, devfileContent: devfileContent @@ -51,9 +53,18 @@ suite('Ansible devfile API test', function (): void { expect(output.stdout).contains('condition met'); }); + test('Check running application', async function (): Promise { + const workdir:string = YAML.parse(devfileContent).commands[0].exec.workingDir; + const commandLine:string = YAML.parse(devfileContent).commands[0].exec.commandLine; + const containerName:string = YAML.parse(devfileContent).commands[0].exec.component; + const runCommandInBash:string = `cd ${workdir} && ${commandLine}`; + const output: ShellString = containerTerminal.execInContainerCommand(runCommandInBash, containerName); + expect(output.code).eqls(0); + expect(output.stdout.trim()).contains('Hello, world!'); + }); suiteTeardown('Delete workspace', function (): void { - Logger.trace('Tearing down the workspace'); + kubernetesCommandLineToolsExecutor.deleteDevWorkspace(); }); }); diff --git a/tests/e2e/utils/DevWorkspaceConfigurationHelper.ts b/tests/e2e/utils/DevWorkspaceConfigurationHelper.ts index c2289ebd5ba..0bc746f7751 100644 --- a/tests/e2e/utils/DevWorkspaceConfigurationHelper.ts +++ b/tests/e2e/utils/DevWorkspaceConfigurationHelper.ts @@ -20,6 +20,7 @@ import { IContextParams } from './IContextParams'; import { e2eContainer } from '../configs/inversify.config'; import { CLASSES, EXTERNAL_CLASSES } from '../configs/inversify.types'; import getDecorators from 'inversify-inject-decorators'; +import {DevfilesRegistryHelper} from "./DevfilesRegistryHelper"; const { lazyInject } = getDecorators(e2eContainer); @@ -98,6 +99,7 @@ export class DevWorkspaceConfigurationHelper { return content; } + patchDevWorkspaceConfigWithBuildContainerAttribute(devfileContextDevWorkspace: any): void { Logger.debug(); devfileContextDevWorkspace.spec.template.attributes = YAML.parse(` diff --git a/tests/e2e/utils/DevfilesRegistryHelper.ts b/tests/e2e/utils/DevfilesRegistryHelper.ts index ff12a9adbc1..7e662ca8ecb 100644 --- a/tests/e2e/utils/DevfilesRegistryHelper.ts +++ b/tests/e2e/utils/DevfilesRegistryHelper.ts @@ -19,6 +19,7 @@ import {CLASSES} from "../configs/inversify.types"; @injectable() export class DevfilesRegistryHelper { + private getShellExecutor(): ShellExecutor { return e2eContainer.get(CLASSES.ShellExecutor); } @@ -152,4 +153,12 @@ export class DevfilesRegistryHelper { public obtainCheDevFileEditor(configMapName: string): string { return this.getShellExecutor().executeCommand(`oc get configmap ${configMapName} -o jsonpath="{.data.che-code\\.yaml}" -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE}`); } + + public getDevfileContent( devSample: string): string { + const podName: string = this.getShellExecutor().executeArbitraryShellScript(`oc get pods -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE} | grep dashboard | awk \'{print $1}\'`).trim() + const containerName: string = this.getShellExecutor().executeArbitraryShellScript(`oc get pod -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE} ${podName} -o jsonpath=\'{.spec.containers[*].name}\'`) + const devfileContent: string = this.obtainDevFileContentUsingPod(podName, containerName, devSample); + return devfileContent; + } + } From ba6352d8a16695950660d697ace53941b4e9f5d7 Mon Sep 17 00:00:00 2001 From: mmusiien Date: Mon, 21 Oct 2024 18:14:02 +0300 Subject: [PATCH 4/7] add comments --- tests/e2e/specs/api/PhpDevFileAPI.spec.ts | 4 ++-- tests/e2e/utils/DevfilesRegistryHelper.ts | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/e2e/specs/api/PhpDevFileAPI.spec.ts b/tests/e2e/specs/api/PhpDevFileAPI.spec.ts index a4775597cfd..32f6f96a3b1 100644 --- a/tests/e2e/specs/api/PhpDevFileAPI.spec.ts +++ b/tests/e2e/specs/api/PhpDevFileAPI.spec.ts @@ -24,7 +24,7 @@ import {StringUtil} from "../../utils/StringUtil"; import {string} from "yaml/dist/schema/common/string"; -suite('Ansible devfile API test', function (): void { +suite('PHP devfile API test', function (): void { const devfilesRegistryHelper: DevfilesRegistryHelper = e2eContainer.get(CLASSES.DevfilesRegistryHelper); const kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = e2eContainer.get(CLASSES.KubernetesCommandLineToolsExecutor); let containerTerminal: ContainerTerminal = e2eContainer.get(CLASSES.ContainerTerminal); @@ -39,7 +39,7 @@ suite('Ansible devfile API test', function (): void { test('Create PHP DevSpace', async function (): Promise { kubernetesCommandLineToolsExecutor.namespace = 'admin-devspaces'; devfileContent = devfilesRegistryHelper.getDevfileContent('php'); - const editorDevfileContent: string = devfilesRegistryHelper.obtainCheDevFileEditor('editors-definitions'); + const editorDevfileContent: string = devfilesRegistryHelper.obtainCheDevFileEditorFromCheConfigMap('editors-definitions'); kubernetesCommandLineToolsExecutor.workspaceName = YAML.parse(devfileContent).metadata.name; devWorkspaceConfigurationHelper = new DevWorkspaceConfigurationHelper({ diff --git a/tests/e2e/utils/DevfilesRegistryHelper.ts b/tests/e2e/utils/DevfilesRegistryHelper.ts index 7e662ca8ecb..94c00f2b05e 100644 --- a/tests/e2e/utils/DevfilesRegistryHelper.ts +++ b/tests/e2e/utils/DevfilesRegistryHelper.ts @@ -144,17 +144,31 @@ export class DevfilesRegistryHelper { return `http://${serviceClusterIp}:${servicePort}${devfileSampleURIPrefix}`; } + /** + * grab devfile content from the Dashboard pod (currently, in the image of dashboard builds with devfile content and we use it for getting devfile description) + * @param podName + * @param containerName + * @param devFileName + */ public obtainDevFileContentUsingPod(podName:string, containerName:string, devFileName:string): string { const clusterURL:string = this.getInternalClusterURLToDevFile(devFileName); this.getShellExecutor().executeCommand(`oc exec -i ${podName} -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE} -c ${containerName} -- sh -c 'curl -o /tmp/${devFileName}-devfile.yaml ${clusterURL}'`); return this.getShellExecutor().executeArbitraryShellScript(`oc exec -i ${podName} -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE} -c ${containerName} -- cat /tmp/${devFileName}-devfile.yaml`).toString(); } - public obtainCheDevFileEditor(configMapName: string): string { + /** + * use internal CHE config map for getting description of CHE editor + * @param configMapName + */ + public obtainCheDevFileEditorFromCheConfigMap(configMapName: string): string { return this.getShellExecutor().executeCommand(`oc get configmap ${configMapName} -o jsonpath="{.data.che-code\\.yaml}" -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE}`); } - public getDevfileContent( devSample: string): string { + /** + * find the Dashboard pod and container name and grab devfile content from it + * @param devSample + */ + public getDevfileContent(devSample: string): string { const podName: string = this.getShellExecutor().executeArbitraryShellScript(`oc get pods -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE} | grep dashboard | awk \'{print $1}\'`).trim() const containerName: string = this.getShellExecutor().executeArbitraryShellScript(`oc get pod -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE} ${podName} -o jsonpath=\'{.spec.containers[*].name}\'`) const devfileContent: string = this.obtainDevFileContentUsingPod(podName, containerName, devSample); From 4410b823d1523e090df6243fb03e2e66bbf4c37b Mon Sep 17 00:00:00 2001 From: mmusiien Date: Tue, 22 Oct 2024 19:14:17 +0300 Subject: [PATCH 5/7] change env vars for platform --- tests/e2e/utils/DevfilesRegistryHelper.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/e2e/utils/DevfilesRegistryHelper.ts b/tests/e2e/utils/DevfilesRegistryHelper.ts index 94c00f2b05e..9ba185fcce4 100644 --- a/tests/e2e/utils/DevfilesRegistryHelper.ts +++ b/tests/e2e/utils/DevfilesRegistryHelper.ts @@ -139,8 +139,8 @@ export class DevfilesRegistryHelper { let devfileSampleURIPrefix:string = `/dashboard/api/airgap-sample/devfile/download?id=${devFileName}`; let serviceClusterIp:string = '' let servicePort:string = '' - serviceClusterIp = this.getShellExecutor().executeArbitraryShellScript(`oc get svc devspaces-dashboard -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE} -o=jsonpath='{.spec.clusterIP}'`); - servicePort = this.getShellExecutor().executeArbitraryShellScript(`oc get svc devspaces-dashboard -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE} -o=jsonpath='{.spec.ports[*].port}'`); + serviceClusterIp = this.getShellExecutor().executeArbitraryShellScript(`oc get svc devspaces-dashboard -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()} -o=jsonpath='{.spec.clusterIP}'`); + servicePort = this.getShellExecutor().executeArbitraryShellScript(`oc get svc devspaces-dashboard -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()} -o=jsonpath='{.spec.ports[*].port}'`); return `http://${serviceClusterIp}:${servicePort}${devfileSampleURIPrefix}`; } @@ -152,8 +152,8 @@ export class DevfilesRegistryHelper { */ public obtainDevFileContentUsingPod(podName:string, containerName:string, devFileName:string): string { const clusterURL:string = this.getInternalClusterURLToDevFile(devFileName); - this.getShellExecutor().executeCommand(`oc exec -i ${podName} -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE} -c ${containerName} -- sh -c 'curl -o /tmp/${devFileName}-devfile.yaml ${clusterURL}'`); - return this.getShellExecutor().executeArbitraryShellScript(`oc exec -i ${podName} -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE} -c ${containerName} -- cat /tmp/${devFileName}-devfile.yaml`).toString(); + this.getShellExecutor().executeCommand(`oc exec -i ${podName} -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()} -c ${containerName} -- sh -c 'curl -o /tmp/${devFileName}-devfile.yaml ${clusterURL}'`); + return this.getShellExecutor().executeArbitraryShellScript(`oc exec -i ${podName} -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()} -c ${containerName} -- cat /tmp/${devFileName}-devfile.yaml`).toString(); } /** @@ -161,7 +161,7 @@ export class DevfilesRegistryHelper { * @param configMapName */ public obtainCheDevFileEditorFromCheConfigMap(configMapName: string): string { - return this.getShellExecutor().executeCommand(`oc get configmap ${configMapName} -o jsonpath="{.data.che-code\\.yaml}" -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE}`); + return this.getShellExecutor().executeCommand(`oc get configmap ${configMapName} -o jsonpath="{.data.che-code\\.yaml}" -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()}`); } /** @@ -169,8 +169,10 @@ export class DevfilesRegistryHelper { * @param devSample */ public getDevfileContent(devSample: string): string { - const podName: string = this.getShellExecutor().executeArbitraryShellScript(`oc get pods -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE} | grep dashboard | awk \'{print $1}\'`).trim() - const containerName: string = this.getShellExecutor().executeArbitraryShellScript(`oc get pod -n ${API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE} ${podName} -o jsonpath=\'{.spec.containers[*].name}\'`) + const command: string = `oc get pods -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()}`; + console.log(`command: ${command}`); + const podName: string = this.getShellExecutor().executeArbitraryShellScript(`oc get pods -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()} | grep dashboard | awk \'{print $1}\'`).trim() + const containerName: string = this.getShellExecutor().executeArbitraryShellScript(`oc get pod -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()} ${podName} -o jsonpath=\'{.spec.containers[*].name}\'`) const devfileContent: string = this.obtainDevFileContentUsingPod(podName, containerName, devSample); return devfileContent; } From 75c9f632c2329a9b3b39f6fd6c59d23695e02b82 Mon Sep 17 00:00:00 2001 From: mmusiien Date: Fri, 25 Oct 2024 04:19:05 +0300 Subject: [PATCH 6/7] Add proposals to the PR --- tests/e2e/specs/api/PhpDevFileAPI.spec.ts | 106 ++++++++++++---------- 1 file changed, 56 insertions(+), 50 deletions(-) diff --git a/tests/e2e/specs/api/PhpDevFileAPI.spec.ts b/tests/e2e/specs/api/PhpDevFileAPI.spec.ts index 32f6f96a3b1..47a6adfbb2f 100644 --- a/tests/e2e/specs/api/PhpDevFileAPI.spec.ts +++ b/tests/e2e/specs/api/PhpDevFileAPI.spec.ts @@ -10,61 +10,67 @@ import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS'; import { e2eContainer } from '../../configs/inversify.config'; import { CLASSES } from '../../configs/inversify.types'; -import {Logger} from "../../utils/Logger"; -import {DevfilesRegistryHelper} from "../../utils/DevfilesRegistryHelper"; -import {ContainerTerminal, KubernetesCommandLineToolsExecutor} from "../../utils/KubernetesCommandLineToolsExecutor"; -import {ShellExecutor} from "../../utils/ShellExecutor"; -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 {StringUtil} from "../../utils/StringUtil"; -import {string} from "yaml/dist/schema/common/string"; - +import { DevfilesRegistryHelper } from '../../utils/DevfilesRegistryHelper'; +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('PHP devfile API test', function (): void { - const devfilesRegistryHelper: DevfilesRegistryHelper = e2eContainer.get(CLASSES.DevfilesRegistryHelper); - const kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = e2eContainer.get(CLASSES.KubernetesCommandLineToolsExecutor); - let containerTerminal: ContainerTerminal = e2eContainer.get(CLASSES.ContainerTerminal); - let devWorkspaceConfigurationHelper: DevWorkspaceConfigurationHelper; - let devfileContext: DevfileContext; - let devfileContent: string =''; - - suiteSetup(`Prepare login ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, async function (): Promise { - kubernetesCommandLineToolsExecutor.loginToOcp(); - }); - - test('Create PHP DevSpace', async function (): Promise { - kubernetesCommandLineToolsExecutor.namespace = 'admin-devspaces'; - devfileContent = devfilesRegistryHelper.getDevfileContent('php'); - const editorDevfileContent: string = devfilesRegistryHelper.obtainCheDevFileEditorFromCheConfigMap('editors-definitions'); - kubernetesCommandLineToolsExecutor.workspaceName = YAML.parse(devfileContent).metadata.name; + const devfilesRegistryHelper: DevfilesRegistryHelper = e2eContainer.get(CLASSES.DevfilesRegistryHelper); + const kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = e2eContainer.get( + CLASSES.KubernetesCommandLineToolsExecutor + ); + const devfileID: string = 'php'; + const containerTerminal: ContainerTerminal = e2eContainer.get(CLASSES.ContainerTerminal); + let devWorkspaceConfigurationHelper: DevWorkspaceConfigurationHelper; + let devfileContext: DevfileContext; + let devfileContent: string = ''; - devWorkspaceConfigurationHelper = new DevWorkspaceConfigurationHelper({ - editorContent: editorDevfileContent, devfileContent: devfileContent - }); - devfileContext = await devWorkspaceConfigurationHelper.generateDevfileContext(); + suiteSetup(`Prepare login ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void { + kubernetesCommandLineToolsExecutor.loginToOcp(); + }); - const devWorkspaceConfigurationYamlString: string = - devWorkspaceConfigurationHelper.getDevWorkspaceConfigurationYamlAsString(devfileContext); - const output: ShellString = kubernetesCommandLineToolsExecutor.applyAndWaitDevWorkspace(devWorkspaceConfigurationYamlString); - expect(output.stdout).contains('condition met'); - }); + test(`Create ${devfileID} workspace`, async function (): Promise { + const randomPref: string = crypto.randomBytes(4).toString('hex'); + kubernetesCommandLineToolsExecutor.namespace = API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE || 'admin-devspaces'; + devfileContent = devfilesRegistryHelper.getDevfileContent(devfileID); + const editorDevfileContent: string = devfilesRegistryHelper.obtainCheDevFileEditorFromCheConfigMap('editors-definitions'); + const uniqName: string = YAML.parse(devfileContent).metadata.name + randomPref; + kubernetesCommandLineToolsExecutor.workspaceName = uniqName; - test('Check running application', async function (): Promise { - const workdir:string = YAML.parse(devfileContent).commands[0].exec.workingDir; - const commandLine:string = YAML.parse(devfileContent).commands[0].exec.commandLine; - const containerName:string = YAML.parse(devfileContent).commands[0].exec.component; - const runCommandInBash:string = `cd ${workdir} && ${commandLine}`; - const output: ShellString = containerTerminal.execInContainerCommand(runCommandInBash, containerName); - expect(output.code).eqls(0); - expect(output.stdout.trim()).contains('Hello, world!'); + devWorkspaceConfigurationHelper = new DevWorkspaceConfigurationHelper({ + editorContent: editorDevfileContent, + devfileContent: devfileContent + }); + devfileContext = await devWorkspaceConfigurationHelper.generateDevfileContext(); + if (devfileContext.devWorkspace.metadata) { + devfileContext.devWorkspace.metadata.name = uniqName; + } + const devWorkspaceConfigurationYamlString: string = + devWorkspaceConfigurationHelper.getDevWorkspaceConfigurationYamlAsString(devfileContext); + const output: ShellString = kubernetesCommandLineToolsExecutor.applyAndWaitDevWorkspace(devWorkspaceConfigurationYamlString); + expect(output.stdout).contains('condition met'); + }); - }); + test('Check running application', function (): void { + const workdir: string = YAML.parse(devfileContent).commands[0].exec.workingDir; + const commandLine: string = YAML.parse(devfileContent).commands[0].exec.commandLine; + const containerName: string = YAML.parse(devfileContent).commands[0].exec.component; + Logger.info(`workdir from exec section of DevWorkspace file: ${workdir}`); + Logger.info(`commandLine from exec section of DevWorkspace file: ${commandLine}`); + const runCommandInBash: string = `cd ${workdir} && ${commandLine}`; + const output: ShellString = containerTerminal.execInContainerCommand(runCommandInBash, containerName); + expect(output.code).eqls(0); + expect(output.stdout.trim()).contains('Hello, world!'); + }); - suiteTeardown('Delete workspace', function (): void { - kubernetesCommandLineToolsExecutor.deleteDevWorkspace(); - }); + suiteTeardown('Delete workspace', function (): void { + kubernetesCommandLineToolsExecutor.deleteDevWorkspace(); + }); }); From 162f46293427885aaef0ba9c89e60fa2ed258614 Mon Sep 17 00:00:00 2001 From: mmusiien Date: Fri, 25 Oct 2024 04:30:51 +0300 Subject: [PATCH 7/7] rename helper class --- tests/e2e/configs/inversify.config.ts | 4 +- tests/e2e/index.ts | 2 +- .../api/DevfileAcceptanceTestAPI.spec.ts | 4 +- ...InbuiltApplicationDevWorkspacesAPI.spec.ts | 4 +- tests/e2e/specs/api/PhpDevFileAPI.spec.ts | 4 +- .../utils/DevWorkspaceConfigurationHelper.ts | 2 +- ...lesRegistryHelper.ts => DevfilesHelper.ts} | 116 ++++++++++-------- 7 files changed, 75 insertions(+), 61 deletions(-) rename tests/e2e/utils/{DevfilesRegistryHelper.ts => DevfilesHelper.ts} (72%) diff --git a/tests/e2e/configs/inversify.config.ts b/tests/e2e/configs/inversify.config.ts index 0847de699ba..16b063be137 100644 --- a/tests/e2e/configs/inversify.config.ts +++ b/tests/e2e/configs/inversify.config.ts @@ -47,7 +47,7 @@ import { BASE_TEST_CONSTANTS, Platform } from '../constants/BASE_TEST_CONSTANTS' import { CheCodeLocatorLoader } from '../pageobjects/ide/CheCodeLocatorLoader'; import { LocatorLoader } from 'monaco-page-objects/out/locators/loader'; import { OauthPage } from '../pageobjects/git-providers/OauthPage'; -import { DevfilesRegistryHelper } from '../utils/DevfilesRegistryHelper'; +import { DevfilesHelper } from '../utils/DevfilesHelper'; import { Main as Generator } from '@eclipse-che/che-devworkspace-generator/lib/main'; import { ContainerTerminal, KubernetesCommandLineToolsExecutor } from '../utils/KubernetesCommandLineToolsExecutor'; import { ShellExecutor } from '../utils/ShellExecutor'; @@ -84,7 +84,7 @@ e2eContainer.bind(CLASSES.StringUtil).to(StringUtil); e2eContainer.bind(CLASSES.ApiUrlResolver).to(ApiUrlResolver); e2eContainer.bind(CLASSES.WorkspaceHandlingTests).to(WorkspaceHandlingTests); e2eContainer.bind(CLASSES.RedHatLoginPage).to(RedHatLoginPage); -e2eContainer.bind(CLASSES.DevfilesRegistryHelper).to(DevfilesRegistryHelper); +e2eContainer.bind(CLASSES.DevfilesRegistryHelper).to(DevfilesHelper); e2eContainer.bind(CLASSES.KubernetesCommandLineToolsExecutor).to(KubernetesCommandLineToolsExecutor); e2eContainer.bind(CLASSES.ShellExecutor).to(ShellExecutor); e2eContainer.bind(CLASSES.ContainerTerminal).to(ContainerTerminal); diff --git a/tests/e2e/index.ts b/tests/e2e/index.ts index 44027982124..d0cb8483b56 100644 --- a/tests/e2e/index.ts +++ b/tests/e2e/index.ts @@ -5,7 +5,7 @@ export * from './configs/mocharc'; export * from './driver/ChromeDriver'; export * from './driver/IDriver'; export * from './utils/BrowserTabsUtil'; -export * from './utils/DevfilesRegistryHelper'; +export * from './utils/DevfilesHelper'; export * from './utils/DevWorkspaceConfigurationHelper'; export * from './utils/DriverHelper'; export * from './utils/IContextParams'; diff --git a/tests/e2e/specs/api/DevfileAcceptanceTestAPI.spec.ts b/tests/e2e/specs/api/DevfileAcceptanceTestAPI.spec.ts index 996d8950757..b1bd1bffcd0 100644 --- a/tests/e2e/specs/api/DevfileAcceptanceTestAPI.spec.ts +++ b/tests/e2e/specs/api/DevfileAcceptanceTestAPI.spec.ts @@ -16,7 +16,7 @@ import { StringUtil } from '../../utils/StringUtil'; import { Logger } from '../../utils/Logger'; import { e2eContainer } from '../../configs/inversify.config'; import { CLASSES } from '../../configs/inversify.types'; -import { DevfilesRegistryHelper } from '../../utils/DevfilesRegistryHelper'; +import { DevfilesHelper } from '../../utils/DevfilesHelper'; import { MOCHA_CONSTANTS } from '../../constants/MOCHA_CONSTANTS'; import { API_TEST_CONSTANTS } from '../../constants/API_TEST_CONSTANTS'; import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS'; @@ -26,7 +26,7 @@ import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS'; * info: https://mochajs.org/#delayed-root-suite */ void (async function (): Promise { - const devfilesRegistryHelper: DevfilesRegistryHelper = e2eContainer.get(CLASSES.DevfilesRegistryHelper); + const devfilesRegistryHelper: DevfilesHelper = e2eContainer.get(CLASSES.DevfilesRegistryHelper); let devfileSamples: any = []; if ( diff --git a/tests/e2e/specs/api/InbuiltApplicationDevWorkspacesAPI.spec.ts b/tests/e2e/specs/api/InbuiltApplicationDevWorkspacesAPI.spec.ts index abb8342971c..77906dc1799 100644 --- a/tests/e2e/specs/api/InbuiltApplicationDevWorkspacesAPI.spec.ts +++ b/tests/e2e/specs/api/InbuiltApplicationDevWorkspacesAPI.spec.ts @@ -12,7 +12,7 @@ import { DevWorkspaceConfigurationHelper } from '../../utils/DevWorkspaceConfigu import { ShellString } from 'shelljs'; import { expect } from 'chai'; import { StringUtil } from '../../utils/StringUtil'; -import { DevfilesRegistryHelper } from '../../utils/DevfilesRegistryHelper'; +import { DevfilesHelper } from '../../utils/DevfilesHelper'; import { Logger } from '../../utils/Logger'; import { e2eContainer } from '../../configs/inversify.config'; import { CLASSES } from '../../configs/inversify.types'; @@ -27,7 +27,7 @@ import { MOCHA_CONSTANTS } from '../../constants/MOCHA_CONSTANTS'; */ void (async function (): Promise { - const devfilesRegistryHelper: DevfilesRegistryHelper = e2eContainer.get(CLASSES.DevfilesRegistryHelper); + const devfilesRegistryHelper: DevfilesHelper = e2eContainer.get(CLASSES.DevfilesRegistryHelper); let devfileSamples: any; if (MOCHA_CONSTANTS.MOCHA_DELAYED_SUITE) { devfileSamples = await devfilesRegistryHelper.collectPathsToDevfilesFromRegistry( diff --git a/tests/e2e/specs/api/PhpDevFileAPI.spec.ts b/tests/e2e/specs/api/PhpDevFileAPI.spec.ts index 47a6adfbb2f..ea398b7fb64 100644 --- a/tests/e2e/specs/api/PhpDevFileAPI.spec.ts +++ b/tests/e2e/specs/api/PhpDevFileAPI.spec.ts @@ -10,7 +10,7 @@ import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS'; import { e2eContainer } from '../../configs/inversify.config'; import { CLASSES } from '../../configs/inversify.types'; -import { DevfilesRegistryHelper } from '../../utils/DevfilesRegistryHelper'; +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'; @@ -22,7 +22,7 @@ import { Logger } from '../../utils/Logger'; import crypto from 'crypto'; suite('PHP devfile API test', function (): void { - const devfilesRegistryHelper: DevfilesRegistryHelper = e2eContainer.get(CLASSES.DevfilesRegistryHelper); + const devfilesRegistryHelper: DevfilesHelper = e2eContainer.get(CLASSES.DevfilesRegistryHelper); const kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = e2eContainer.get( CLASSES.KubernetesCommandLineToolsExecutor ); diff --git a/tests/e2e/utils/DevWorkspaceConfigurationHelper.ts b/tests/e2e/utils/DevWorkspaceConfigurationHelper.ts index 0bc746f7751..e75248bd784 100644 --- a/tests/e2e/utils/DevWorkspaceConfigurationHelper.ts +++ b/tests/e2e/utils/DevWorkspaceConfigurationHelper.ts @@ -20,7 +20,7 @@ import { IContextParams } from './IContextParams'; import { e2eContainer } from '../configs/inversify.config'; import { CLASSES, EXTERNAL_CLASSES } from '../configs/inversify.types'; import getDecorators from 'inversify-inject-decorators'; -import {DevfilesRegistryHelper} from "./DevfilesRegistryHelper"; +import {DevfilesHelper} from "./DevfilesHelper"; const { lazyInject } = getDecorators(e2eContainer); diff --git a/tests/e2e/utils/DevfilesRegistryHelper.ts b/tests/e2e/utils/DevfilesHelper.ts similarity index 72% rename from tests/e2e/utils/DevfilesRegistryHelper.ts rename to tests/e2e/utils/DevfilesHelper.ts index 9ba185fcce4..0edccaf2251 100644 --- a/tests/e2e/utils/DevfilesRegistryHelper.ts +++ b/tests/e2e/utils/DevfilesHelper.ts @@ -13,16 +13,72 @@ import YAML from 'yaml'; import { API_TEST_CONSTANTS, SUPPORTED_DEVFILE_REGISTRIES } from '../constants/API_TEST_CONSTANTS'; import { injectable } from 'inversify'; import { BASE_TEST_CONSTANTS, Platform } from '../constants/BASE_TEST_CONSTANTS'; -import {ShellExecutor} from "./ShellExecutor"; -import {e2eContainer} from "../configs/inversify.config"; -import {CLASSES} from "../configs/inversify.types"; +import { ShellExecutor } from './ShellExecutor'; +import { e2eContainer } from '../configs/inversify.config'; +import { CLASSES } from '../configs/inversify.types'; @injectable() -export class DevfilesRegistryHelper { +export class DevfilesHelper { + public getInternalClusterURLToDevFile(devFileName: string): string { + const devfileSampleURIPrefix: string = `/dashboard/api/airgap-sample/devfile/download?id=${devFileName}`; + let serviceClusterIp: string = ''; + let servicePort: string = ''; + serviceClusterIp = this.getShellExecutor().executeArbitraryShellScript( + `oc get svc devspaces-dashboard -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()} -o=jsonpath='{.spec.clusterIP}'` + ); + servicePort = this.getShellExecutor().executeArbitraryShellScript( + `oc get svc devspaces-dashboard -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()} -o=jsonpath='{.spec.ports[*].port}'` + ); + return `http://${serviceClusterIp}:${servicePort}${devfileSampleURIPrefix}`; + } - private getShellExecutor(): ShellExecutor { - return e2eContainer.get(CLASSES.ShellExecutor); + /** + * grab devfile content from the Dashboard pod (currently, in the image of dashboard builds with devfile content and we use it for getting devfile description) + * @param podName + * @param containerName + * @param devFileName + */ + public obtainDevFileContentUsingPod(podName: string, containerName: string, devFileName: string): string { + const clusterURL: string = this.getInternalClusterURLToDevFile(devFileName); + this.getShellExecutor().executeCommand( + `oc exec -i ${podName} -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()} -c ${containerName} -- sh -c 'curl -o /tmp/${devFileName}-devfile.yaml ${clusterURL}'` + ); + return this.getShellExecutor() + .executeArbitraryShellScript( + `oc exec -i ${podName} -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()} -c ${containerName} -- cat /tmp/${devFileName}-devfile.yaml` + ) + .toString(); + } + + /** + * grab devfile content from the Che config map + * @param configMapName + */ + public obtainCheDevFileEditorFromCheConfigMap(configMapName: string): string { + return this.getShellExecutor().executeCommand( + `oc get configmap ${configMapName} -o jsonpath="{.data.che-code\\.yaml}" -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()}` + ); } + + /** + * find the Dashboard pod and container name and grab devfile content from it + * @param devSample + */ + public getDevfileContent(devSample: string): string { + const command: string = `oc get pods -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()}`; + console.log(`command: ${command}`); + const podName: string = this.getShellExecutor() + .executeArbitraryShellScript( + `oc get pods -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()} | grep dashboard | awk \'{print $1}\'` + ) + .trim(); + const containerName: string = this.getShellExecutor().executeArbitraryShellScript( + `oc get pod -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()} ${podName} -o jsonpath=\'{.spec.containers[*].name}\'` + ); + const devfileContent: string = this.obtainDevFileContentUsingPod(podName, containerName, devSample); + return devfileContent; + } + /** * @deprecated applicable only for inbuilt devfiles * @param sampleNamePatterns @@ -103,7 +159,6 @@ export class DevfilesRegistryHelper { return devfileSamples; } - private filterSamples(sampleNamePatterns: string[] | undefined, content: any): Promise { if (sampleNamePatterns) { const commonSampleNamePattern: RegExp = new RegExp(sampleNamePatterns.join('|'), 'i'); @@ -111,7 +166,9 @@ export class DevfilesRegistryHelper { } return content; } - + private getShellExecutor(): ShellExecutor { + return e2eContainer.get(CLASSES.ShellExecutor); + } // eslint-disable-next-line @typescript-eslint/no-unused-vars private async getContent(url: string, headers?: object): Promise { Logger.trace(`${url}`); @@ -134,47 +191,4 @@ export class DevfilesRegistryHelper { } return response?.data; } - - public getInternalClusterURLToDevFile(devFileName:string): string { - let devfileSampleURIPrefix:string = `/dashboard/api/airgap-sample/devfile/download?id=${devFileName}`; - let serviceClusterIp:string = '' - let servicePort:string = '' - serviceClusterIp = this.getShellExecutor().executeArbitraryShellScript(`oc get svc devspaces-dashboard -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()} -o=jsonpath='{.spec.clusterIP}'`); - servicePort = this.getShellExecutor().executeArbitraryShellScript(`oc get svc devspaces-dashboard -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()} -o=jsonpath='{.spec.ports[*].port}'`); - return `http://${serviceClusterIp}:${servicePort}${devfileSampleURIPrefix}`; - } - - /** - * grab devfile content from the Dashboard pod (currently, in the image of dashboard builds with devfile content and we use it for getting devfile description) - * @param podName - * @param containerName - * @param devFileName - */ - public obtainDevFileContentUsingPod(podName:string, containerName:string, devFileName:string): string { - const clusterURL:string = this.getInternalClusterURLToDevFile(devFileName); - this.getShellExecutor().executeCommand(`oc exec -i ${podName} -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()} -c ${containerName} -- sh -c 'curl -o /tmp/${devFileName}-devfile.yaml ${clusterURL}'`); - return this.getShellExecutor().executeArbitraryShellScript(`oc exec -i ${podName} -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()} -c ${containerName} -- cat /tmp/${devFileName}-devfile.yaml`).toString(); - } - - /** - * use internal CHE config map for getting description of CHE editor - * @param configMapName - */ - public obtainCheDevFileEditorFromCheConfigMap(configMapName: string): string { - return this.getShellExecutor().executeCommand(`oc get configmap ${configMapName} -o jsonpath="{.data.che-code\\.yaml}" -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()}`); - } - - /** - * find the Dashboard pod and container name and grab devfile content from it - * @param devSample - */ - public getDevfileContent(devSample: string): string { - const command: string = `oc get pods -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()}`; - console.log(`command: ${command}`); - const podName: string = this.getShellExecutor().executeArbitraryShellScript(`oc get pods -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()} | grep dashboard | awk \'{print $1}\'`).trim() - const containerName: string = this.getShellExecutor().executeArbitraryShellScript(`oc get pod -n ${BASE_TEST_CONSTANTS.TS_PLATFORM}-${BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()} ${podName} -o jsonpath=\'{.spec.containers[*].name}\'`) - const devfileContent: string = this.obtainDevFileContentUsingPod(podName, containerName, devSample); - return devfileContent; - } - }