Skip to content

Commit 5531154

Browse files
authored
Verify image build functionality using kubedock and podman when spec.devEnvironments.persistUserHome.enabled is set to true (#23786)
1 parent 231dd16 commit 5531154

1 file changed

Lines changed: 154 additions & 0 deletions

File tree

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/** *******************************************************************
2+
* copyright (c) 2020-2026 Red Hat, Inc.
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
**********************************************************************/
10+
11+
import { ViewSection } from 'monaco-page-objects';
12+
import { ProjectAndFileTests } from '../../tests-library/ProjectAndFileTests';
13+
import { CLASSES, TYPES } from '../../configs/inversify.types';
14+
import { e2eContainer } from '../../configs/inversify.config';
15+
import { WorkspaceHandlingTests } from '../../tests-library/WorkspaceHandlingTests';
16+
import { registerRunningWorkspace } from '../MochaHooks';
17+
import { LoginTests } from '../../tests-library/LoginTests';
18+
import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil';
19+
import { expect } from 'chai';
20+
import { KubernetesCommandLineToolsExecutor } from '../../utils/KubernetesCommandLineToolsExecutor';
21+
import { ShellString } from 'shelljs';
22+
import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS';
23+
import { ITestWorkspaceUtil } from '../../utils/workspace/ITestWorkspaceUtil';
24+
import { Dashboard } from '../../pageobjects/dashboard/Dashboard';
25+
import { FACTORY_TEST_CONSTANTS } from '../../constants/FACTORY_TEST_CONSTANTS';
26+
import { ShellExecutor } from '../../utils/ShellExecutor';
27+
28+
suite(`Test image build with persistUserHome enabled (kubedock and podman) ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void {
29+
const projectAndFileTests: ProjectAndFileTests = e2eContainer.get(CLASSES.ProjectAndFileTests);
30+
const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests);
31+
const loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests);
32+
const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil);
33+
const testWorkspaceUtil: ITestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil);
34+
const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard);
35+
const shellExecutor: ShellExecutor = e2eContainer.get(CLASSES.ShellExecutor);
36+
const kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = e2eContainer.get(
37+
CLASSES.KubernetesCommandLineToolsExecutor
38+
);
39+
40+
let workspaceName: string = '';
41+
let defaultPersistentHomeValue: boolean = false;
42+
const cheClusterName: string = 'devspaces';
43+
44+
const testScript: string =
45+
'# Enable Kubedock\n' +
46+
'export KUBEDOCK_ENABLED=true\n' +
47+
'echo KUBEDOCK_ENABLED\n' +
48+
'/entrypoint.sh\n' +
49+
'cd $PROJECT_SOURCE\n' +
50+
'export ARCH=$(uname -m)\n' +
51+
'export DATE=$(date +"%m%d%y")\n' +
52+
'export USER=$(oc whoami)\n' +
53+
'export TKN=$(oc whoami -t)\n' +
54+
'export REG="image-registry.openshift-image-registry.svc:5000"\n' +
55+
'export PROJECT=$(oc project -q)\n' +
56+
'export IMG="${REG}/${PROJECT}/hello:${DATE}"\n' +
57+
'podman login --tls-verify=false --username ${USER} --password ${TKN} ${REG}\n' +
58+
'podman build -t ${IMG} -f Dockerfile.${ARCH}\n' +
59+
'podman push --tls-verify=false ${IMG}\n';
60+
61+
const runTestScript: string =
62+
'# Enable Kubedock\n' +
63+
'export KUBEDOCK_ENABLED=true\n' +
64+
'echo KUBEDOCK_ENABLED\n' +
65+
'/entrypoint.sh\n' +
66+
'export DATE=$(date +"%m%d%y")\n' +
67+
'export USER=$(oc whoami)\n' +
68+
'export TKN=$(oc whoami -t)\n' +
69+
'export REG="image-registry.openshift-image-registry.svc:5000"\n' +
70+
'export PROJECT=$(oc project -q)\n' +
71+
'export IMG="${REG}/${PROJECT}/hello:${DATE}"\n' +
72+
'podman login --tls-verify=false --username ${USER} --password ${TKN} ${REG}\n' +
73+
'podman run --rm ${IMG}';
74+
75+
const factoryUrl: string = BASE_TEST_CONSTANTS.IS_CLUSTER_DISCONNECTED()
76+
? FACTORY_TEST_CONSTANTS.TS_SELENIUM_AIRGAP_FACTORY_GIT_REPO_URL ||
77+
'https://gh.crw-qe.com/test-automation-only/dockerfile-hello-world'
78+
: FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_GIT_REPO_URL || 'https://github.com/crw-qe/dockerfile-hello-world';
79+
80+
suiteSetup(function (): void {
81+
kubernetesCommandLineToolsExecutor.loginToOcp();
82+
shellExecutor.executeCommand('oc project openshift-devspaces');
83+
84+
// get current value of spec.devEnvironments.persistUserHome.enabled
85+
const currentValue: string = shellExecutor
86+
.executeCommand(`oc get checluster/${cheClusterName} -o "jsonpath={.spec.devEnvironments.persistUserHome.enabled}"`)
87+
.stdout.trim();
88+
defaultPersistentHomeValue = currentValue === 'true';
89+
90+
// set spec.devEnvironments.persistUserHome.enabled to true
91+
const patchResult: ShellString = shellExecutor.executeCommand(
92+
`oc patch checluster ${cheClusterName} --type=merge ` +
93+
'-p \'{"spec":{"devEnvironments":{"persistUserHome":{"enabled": true}}}}\''
94+
);
95+
expect(patchResult.code).to.equal(0, 'Failed to patch CheCluster to enable persistUserHome');
96+
});
97+
98+
suiteSetup('Login', async function (): Promise<void> {
99+
await loginTests.loginIntoChe();
100+
});
101+
102+
test(`Create and open new workspace from factory:${factoryUrl}`, async function (): Promise<void> {
103+
await workspaceHandlingTests.createAndOpenWorkspaceFromGitRepository(factoryUrl);
104+
});
105+
106+
test('Obtain workspace name from workspace loader page', async function (): Promise<void> {
107+
await workspaceHandlingTests.obtainWorkspaceNameFromStartingPage();
108+
workspaceName = WorkspaceHandlingTests.getWorkspaceName();
109+
expect(workspaceName, 'Workspace name was not fetched from the loading page').not.undefined;
110+
});
111+
112+
test('Register running workspace', function (): void {
113+
registerRunningWorkspace(workspaceName);
114+
});
115+
116+
test('Wait workspace readiness', async function (): Promise<void> {
117+
await projectAndFileTests.waitWorkspaceReadinessForCheCodeEditor();
118+
});
119+
120+
test('Check the project files were imported', async function (): Promise<void> {
121+
const projectSection: ViewSection = await projectAndFileTests.getProjectViewSession();
122+
expect(await projectAndFileTests.getProjectTreeItem(projectSection, 'Dockerfile.ppc64le'), 'Files not imported').not.undefined;
123+
});
124+
125+
test('Create and check container runs using kubedock and podman with persistUserHome', function (): void {
126+
kubernetesCommandLineToolsExecutor.workspaceName = workspaceName;
127+
kubernetesCommandLineToolsExecutor.loginToOcp();
128+
kubernetesCommandLineToolsExecutor.getPodAndContainerNames();
129+
const output: ShellString = kubernetesCommandLineToolsExecutor.execInContainerCommand(testScript);
130+
expect(output, 'Podman test script failed').contains('Successfully tagged');
131+
const runOutput: ShellString = kubernetesCommandLineToolsExecutor.execInContainerCommand(runTestScript);
132+
expect(runOutput, 'Podman test script failed').contains('Hello from Kubedock!');
133+
});
134+
135+
suiteTeardown(function (): void {
136+
// restore spec.devEnvironments.persistUserHome.enabled to original value
137+
const restoreResult: ShellString = shellExecutor.executeCommand(
138+
`oc patch checluster ${cheClusterName} --type=merge ` +
139+
`-p '{"spec":{"devEnvironments":{"persistUserHome":{"enabled": ${defaultPersistentHomeValue}}}}}'`
140+
);
141+
142+
expect(restoreResult.code).to.equal(0, 'Failed to restore CheCluster persistUserHome setting');
143+
});
144+
145+
suiteTeardown('Stop and delete the workspace by API', async function (): Promise<void> {
146+
await dashboard.openDashboard();
147+
await browserTabsUtil.closeAllTabsExceptCurrent();
148+
await testWorkspaceUtil.stopAndDeleteWorkspaceByName(WorkspaceHandlingTests.getWorkspaceName());
149+
});
150+
151+
suiteTeardown('Unregister running workspace', function (): void {
152+
registerRunningWorkspace('');
153+
});
154+
});

0 commit comments

Comments
 (0)