Skip to content

Commit 5f440ef

Browse files
committed
Introduce PyTest suite migrated from test/run bash suite.
Migration matrix is: `build_s2i_app` is fixture that takes `Path` test-app from `conftest.py` file. test_container_application.py tests all test-app directories. test_container_basics.py tests only basics w/o application. It also tests test_dockerfile and test_minimal_dockerfile Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
1 parent 1ef68a0 commit 5f440ef

File tree

7 files changed

+378
-38
lines changed

7 files changed

+378
-38
lines changed

manifest-minimal.yml

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ DISTGEN_RULES:
2020
dest: test/run
2121
mode: "0755"
2222

23+
- src: test/run-pytest
24+
dest: test/run-pytest
25+
mode: "0755"
26+
2327
- src: src/test/pipenv-test-app/Pipfile
2428
dest: test/pipenv-test-app/Pipfile
2529

@@ -184,26 +188,32 @@ SYMLINK_RULES:
184188
- src: ../../test/run-openshift-pytest
185189
dest: test/run-openshift-pytest
186190

187-
- src: ../../test/test_deploy_templates.py
188-
dest: test/test_deploy_templates.py
191+
- src: ../../test/test_container_application.py
192+
dest: test/test_container_application.py
193+
194+
- src: ../../test/test_container_basics.py
195+
dest: test/test_container_basics.py
196+
197+
- src: ../../test/test_ocp_deploy_templates.py
198+
dest: test/test_ocp_deploy_templates.py
189199

190-
- src: ../../test/test_imagestreams_quickstart.py
191-
dest: test/test_imagestreams_quickstart.py
200+
- src: ../../test/test_ocp_imagestreams_quickstart.py
201+
dest: test/test_ocp_imagestreams_quickstart.py
192202

193-
- src: ../../test/test_python_ex_standalone.py
194-
dest: test/test_python_ex_standalone.py
203+
- src: ../../test/test_ocp_python_ex_standalone.py
204+
dest: test/test_ocp_python_ex_standalone.py
195205

196-
- src: ../../test/test_python_ex_template.py
197-
dest: test/test_python_ex_template.py
206+
- src: ../../test/test_ocp_python_ex_template.py
207+
dest: test/test_ocp_python_ex_template.py
198208

199-
- src: ../../test/test_helm_python_django_app.py
200-
dest: test/test_helm_python_django_app.py
209+
- src: ../../test/test_ocp_helm_python_django_app.py
210+
dest: test/test_ocp_helm_python_django_app.py
201211

202-
- src: ../../test/test_helm_python_django_psql_persistent.py
203-
dest: test/test_helm_python_django_psql_persistent.py
212+
- src: ../../test/test_ocp_helm_python_django_psql_persistent.py
213+
dest: test/test_ocp_helm_python_django_psql_persistent.py
204214

205-
- src: ../../test/test_helm_python_imagestreams.py
206-
dest: test/test_helm_python_imagestreams.py
215+
- src: ../../test/test_ocp_helm_python_imagestreams.py
216+
dest: test/test_ocp_helm_python_imagestreams.py
207217

208218
- src: ../../test/conftest.py
209219
dest: test/conftest.py

manifest.yml

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ DISTGEN_RULES:
2020
dest: test/run
2121
mode: "0755"
2222

23+
- src: test/run-pytest
24+
dest: test/run-pytest
25+
mode: "0755"
26+
2327
- src: src/test/pipenv-test-app/Pipfile
2428
dest: test/pipenv-test-app/Pipfile
2529

@@ -183,26 +187,32 @@ SYMLINK_RULES:
183187
- src: ../../test/run-openshift-pytest
184188
dest: test/run-openshift-pytest
185189

186-
- src: ../../test/test_deploy_templates.py
187-
dest: test/test_deploy_templates.py
190+
- src: ../../test/test_container_application.py
191+
dest: test/test_container_application.py
192+
193+
- src: ../../test/test_container_basics.py
194+
dest: test/test_container_basics.py
195+
196+
- src: ../../test/test_ocp_deploy_templates.py
197+
dest: test/test_ocp_deploy_templates.py
188198

189-
- src: ../../test/test_imagestreams_quickstart.py
190-
dest: test/test_imagestreams_quickstart.py
199+
- src: ../../test/test_ocp_imagestreams_quickstart.py
200+
dest: test/test_ocp_imagestreams_quickstart.py
191201

192-
- src: ../../test/test_python_ex_standalone.py
193-
dest: test/test_python_ex_standalone.py
202+
- src: ../../test/test_ocp_python_ex_standalone.py
203+
dest: test/test_ocp_python_ex_standalone.py
194204

195-
- src: ../../test/test_python_ex_template.py
196-
dest: test/test_python_ex_template.py
205+
- src: ../../test/test_ocp_python_ex_template.py
206+
dest: test/test_ocp_python_ex_template.py
197207

198-
- src: ../../test/test_helm_python_django_app.py
199-
dest: test/test_helm_python_django_app.py
208+
- src: ../../test/test_ocp_helm_python_django_app.py
209+
dest: test/test_ocp_helm_python_django_app.py
200210

201-
- src: ../../test/test_helm_python_django_psql_persistent.py
202-
dest: test/test_helm_python_django_psql_persistent.py
211+
- src: ../../test/test_ocp_helm_python_django_psql_persistent.py
212+
dest: test/test_ocp_helm_python_django_psql_persistent.py
203213

204-
- src: ../../test/test_helm_python_imagestreams.py
205-
dest: test/test_helm_python_imagestreams.py
214+
- src: ../../test/test_ocp_helm_python_imagestreams.py
215+
dest: test/test_ocp_helm_python_imagestreams.py
206216

207217
- src: ../../test/conftest.py
208218
dest: test/conftest.py

test/conftest.py

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from collections import namedtuple
21
import os
3-
from pathlib import Path
42
import sys
3+
from pathlib import Path
4+
from collections import namedtuple
55

66
from container_ci_suite.utils import check_variables
77
from pytest import skip
@@ -15,12 +15,81 @@
1515
"rhel10": "-ubi10",
1616
}
1717

18-
Vars = namedtuple("Vars", [
19-
"OS", "VERSION", "IMAGE_NAME", "IS_MINIMAL", "VERSION_NO_MINIMAL",
20-
"SHORT_VERSION", "TAG", "TEST_DIR"
21-
])
18+
19+
Vars = namedtuple(
20+
"Vars",
21+
[
22+
"OS",
23+
"VERSION",
24+
"IMAGE_NAME",
25+
"IS_MINIMAL",
26+
"VERSION_NO_MINIMAL",
27+
"SHORT_VERSION",
28+
"TAG",
29+
"TEST_DIR",
30+
"WEB_APPS",
31+
"SHOULD_FAIL_WEB_APPS",
32+
"BRANCH_TO_TEST",
33+
"DEPLOYED_PSQL_IMAGE",
34+
"IMAGE_TAG",
35+
"PSQL_VERSION",
36+
],
37+
)
2238
VERSION = os.getenv("VERSION")
2339
OS = os.getenv("TARGET").lower()
40+
TEST_DIR = Path(__file__).parent.absolute()
41+
BRANCH_TO_TEST = "2.2.x"
42+
DEPLOYED_PSQL_IMAGE = "quay.io/sclorg/postgresql-10-c8s:c8s"
43+
IMAGE_TAG = "postgresql:10"
44+
PSQL_VERSION = "10"
45+
if VERSION in ("3.11", "3.12", "3.12-minimal"):
46+
BRANCH_TO_TEST = "4.2.x"
47+
DEPLOYED_PSQL_IMAGE = "quay.io/sclorg/postgresql-12-c8s"
48+
IMAGE_TAG = "postgresql:12"
49+
PSQL_VERSION = "12"
50+
51+
COMMON_WEB_APPS = [
52+
TEST_DIR / f"{x}-test-app"
53+
for x in [
54+
"gunicorn-config-different-port",
55+
"gunicorn-different-port",
56+
"django-different-port",
57+
"standalone",
58+
"setup",
59+
"setup-requirements",
60+
"django",
61+
"numpy",
62+
"app-home",
63+
"locale",
64+
"pipenv",
65+
"app-module",
66+
"pyuwsgi-pipenv",
67+
"micropipenv",
68+
"standalone-custom-pypi-index",
69+
"gunicorn-python-configfile-different-port",
70+
]
71+
]
72+
FULL_WEB_APPS = [
73+
TEST_DIR / f"{x}-test-app"
74+
for x in [
75+
"setup-cfg",
76+
"npm-virtualenv-uwsgi",
77+
"mod-wsgi",
78+
"pin-pipenv-version",
79+
"micropipenv-requirements",
80+
"poetry-src-layout",
81+
]
82+
]
83+
SHOULD_FAIL_WEB_APPS = [
84+
TEST_DIR / "pipenv-and-micropipenv-should-fail-test-app",
85+
]
86+
87+
MINIMAL_WEB_APPS: list[Path] = []
88+
if "minimal" in VERSION:
89+
WEB_APPS = COMMON_WEB_APPS
90+
else:
91+
WEB_APPS = COMMON_WEB_APPS + FULL_WEB_APPS
92+
2493
VARS = Vars(
2594
OS=OS,
2695
VERSION=VERSION,
@@ -29,11 +98,18 @@
2998
VERSION_NO_MINIMAL=VERSION.replace("-minimal", ""),
3099
SHORT_VERSION=VERSION.replace("-minimal", "").replace(".", ""),
31100
TAG=TAGS.get(OS),
32-
TEST_DIR=Path(__file__).parent.absolute()
101+
TEST_DIR=TEST_DIR,
102+
WEB_APPS=WEB_APPS,
103+
SHOULD_FAIL_WEB_APPS=SHOULD_FAIL_WEB_APPS,
104+
BRANCH_TO_TEST=BRANCH_TO_TEST,
105+
DEPLOYED_PSQL_IMAGE=DEPLOYED_PSQL_IMAGE,
106+
IMAGE_TAG=IMAGE_TAG,
107+
PSQL_VERSION=PSQL_VERSION,
33108
)
34109

35110

36111
def skip_helm_charts_tests():
37-
if VARS.VERSION in ("3.9-minimal", "3.11-minimal") or \
38-
(VARS.VERSION == "3.12-minimal" and VARS.OS == "rhel8"):
112+
if VARS.VERSION in ("3.9-minimal", "3.11-minimal") or (
113+
VARS.VERSION == "3.12-minimal" and VARS.OS == "rhel8"
114+
):
39115
skip(f"Skipping Helm Charts tests for {VARS.VERSION} on {VARS.OS}.")

test/run-openshift-pytest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
THISDIR=$(dirname ${BASH_SOURCE[0]})
1010

11-
cd "${THISDIR}" && python3.12 -m pytest -s -rA --showlocals -vv test_*.py
11+
cd "${THISDIR}" && python3.12 -m pytest -s -rA --showlocals -vv test_ocp_*.py

test/run-pytest

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
#
3+
# IMAGE_NAME specifies a name of the candidate image used for testing.
4+
# The image has to be available before this script is executed.
5+
# SINGLE_VERSION specifies the major version of the MariaDB in format of X.Y
6+
# OS specifies RHEL version (e.g. OS=rhel8)
7+
#
8+
9+
THISDIR=$(dirname ${BASH_SOURCE[0]})
10+
11+
PYTHON_VERSION="3.12"
12+
if [[ ! -f "/usr/bin/python$PYTHON_VERSION" ]]; then
13+
PYTHON_VERSION="3.13"
14+
fi
15+
cd "${THISDIR}" && "python${PYTHON_VERSION}" -m pytest -s -rA --showlocals -vv test_container_b*.py

test/test_container_application.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import pytest
2+
3+
from container_ci_suite.container_lib import ContainerImage, ContainerTestLib
4+
from container_ci_suite.engines.podman_wrapper import PodmanCLIWrapper
5+
6+
from conftest import VARS
7+
8+
9+
@pytest.fixture(params=VARS.WEB_APPS, ids=[app.name for app in VARS.WEB_APPS])
10+
def build_s2i_app(request) -> ContainerTestLib:
11+
"""
12+
Build a S2I application.
13+
"""
14+
container_lib = ContainerTestLib(VARS.IMAGE_NAME)
15+
app_name = request.param.name
16+
s2i_app = container_lib.build_as_df(
17+
app_path=request.param,
18+
s2i_args="--pull-policy=never",
19+
src_image=VARS.IMAGE_NAME,
20+
dst_image=f"{VARS.IMAGE_NAME}-{app_name}",
21+
)
22+
yield s2i_app
23+
s2i_app.cleanup()
24+
25+
26+
@pytest.mark.usefixtures("build_s2i_app")
27+
@pytest.mark.parametrize(
28+
"container_args",
29+
[
30+
"--user 100001",
31+
"--user 12345",
32+
"-e ENABLE_INIT_WRAPPER=true",
33+
],
34+
)
35+
def test_application(build_s2i_app, container_args):
36+
"""
37+
Test if container works
38+
Python version is properly set
39+
Application response on specific port and specific URL.
40+
41+
"""
42+
s2i_app = build_s2i_app
43+
cid_file_name = s2i_app.app_name
44+
assert s2i_app.create_container(
45+
cid_file_name=cid_file_name,
46+
container_args=container_args,
47+
)
48+
assert ContainerImage.wait_for_cid(cid_file_name=cid_file_name)
49+
python_version = PodmanCLIWrapper.podman_run_command_and_remove(
50+
cid_file_name=VARS.IMAGE_NAME, cmd="echo \\$PYTHON_VERSION"
51+
).strip()
52+
python_version_output = PodmanCLIWrapper.podman_run_command_and_remove(
53+
cid_file_name=VARS.IMAGE_NAME, cmd="python --version"
54+
)
55+
assert f"Python {python_version}." in python_version_output
56+
cip = s2i_app.get_cip(cid_file_name=cid_file_name)
57+
assert cip
58+
port = 8080
59+
if "different-port" in s2i_app.app_name:
60+
port = 8085
61+
assert s2i_app.test_response(url=f"http://{cip}", port=port)
62+
63+
64+
@pytest.mark.parametrize(
65+
"should_fail_app",
66+
VARS.SHOULD_FAIL_WEB_APPS,
67+
)
68+
def test_application_should_fail(should_fail_app):
69+
"""
70+
Test if build fails for should fail apps
71+
72+
"""
73+
container_lib = ContainerTestLib(VARS.IMAGE_NAME)
74+
app_name = should_fail_app.name
75+
s2i_app_should_fail = container_lib.build_as_df(
76+
app_path=should_fail_app,
77+
s2i_args="--pull-policy=never",
78+
src_image=VARS.IMAGE_NAME,
79+
dst_image=f"{VARS.IMAGE_NAME}-{app_name}",
80+
)
81+
assert not s2i_app_should_fail

0 commit comments

Comments
 (0)