-
Notifications
You must be signed in to change notification settings - Fork 125
Testing httpd-2.4 container by PyTest #234
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
Changes from 6 commits
6737b7f
6d5f823
884569a
00573a2
ee7ccfd
ea65bf9
b1e158e
3ea9aed
1b6e27d
db4b466
0ad18a8
83e280e
8862757
ff56ad5
8760afb
2cd3c34
c30c0fa
652a4b8
6afdb15
f292ca0
5b8ad70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/run-pytest |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_container_httpd.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_container_httpd_s2i.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_container_ssl.py |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_ex_template.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_imagestream_s2i.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_imagestreams.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_integration.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_shared_helm_imagestreams.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_shared_helm_template.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/run-pytest |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_container_httpd.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_container_httpd_s2i.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_container_ssl.py |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_ex_template.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_imagestream_s2i.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_imagestreams.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_integration.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_shared_helm_imagestreams.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_shared_helm_template.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| import os | ||
|
|
||
|
|
||
| TAGS = { | ||
| "rhel8": "-ubi8", | ||
| "rhel9": "-ubi9", | ||
| "rhel10": "-ubi10", | ||
| } | ||
|
|
||
| def return_app_name(request): | ||
| return os.path.basename(request.param) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #!/bin/bash | ||
| # | ||
| # IMAGE_NAME specifies a name of the candidate image used for testing. | ||
| # The image has to be available before this script is executed. | ||
| # SINGLE_VERSION specifies the major version of the MariaDB in format of X.Y | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # OS specifies RHEL version (e.g. OS=rhel8) | ||
| # | ||
|
|
||
| THISDIR=$(dirname ${BASH_SOURCE[0]}) | ||
|
|
||
| PYTHON_VERSION="3.12" | ||
| if [[ ! -f "/usr/bin/python$PYTHON_VERSION" ]]; then | ||
| PYTHON_VERSION="3.13" | ||
| fi | ||
| cd "${THISDIR}" && "python${PYTHON_VERSION}" -m pytest -s -rA --showlocals -vv test_container_*.py | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| import os | ||
| import sys | ||
|
|
||
| import pytest | ||
phracek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| from pathlib import Path | ||
|
|
||
| from container_ci_suite.container_lib import ContainerTestLib | ||
| from container_ci_suite.utils import check_variables, ContainerTestLibUtils | ||
|
|
||
|
|
||
| if not check_variables(): | ||
| print("At least one variable from OS, VERSION is missing.") | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| sys.exit(1) | ||
|
|
||
|
|
||
| TEST_DIR = Path(os.path.abspath(os.path.dirname(__file__))) | ||
| VERSION = os.getenv("VERSION") | ||
| OS = os.getenv("OS") | ||
| IMAGE_NAME = os.getenv("IMAGE_NAME") | ||
| if not IMAGE_NAME: | ||
| print(f"Built container for version {VERSION} on OS {OS} does not exist.") | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| sys.exit(1) | ||
| print(f"Test dir is: {TEST_DIR}") | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def app(request): | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| app = ContainerTestLib(image_name=IMAGE_NAME, s2i_image=True) | ||
| yield app | ||
| app.clean_containers() | ||
| app.clean_app_images() | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| class TestHttpdAppContainer: | ||
|
|
||
| def test_default_page(self, app): | ||
| assert app.create_container(cid_file_name="test_default_page") | ||
| cip = app.get_cip("test_default_page") | ||
| assert cip | ||
| if OS == "c9s" or OS == "c10s": | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| response = "HTTP Server Test Page" | ||
| else: | ||
| # The RHEL and Fedora OS gets this response | ||
| response = "Test Page for the HTTP Server on" | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assert app.test_response(url=f"{cip}", expected_code=403, expected_output=response, max_attempts=3) | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def test_run_as_root(self, app): | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assert app.create_container(cid_file_name="test_default_page", container_args="--user 0") | ||
| cip = app.get_cip("test_default_page") | ||
| assert cip | ||
| if OS == "c9s" or OS == "c10s": | ||
| response = "HTTP Server Test Page" | ||
| else: | ||
| response = "Test Page for the HTTP Server on" | ||
| assert app.test_response(url=f"{cip}", expected_code=403, expected_output=response, max_attempts=3) | ||
|
|
||
| def test_run_s2i_usage(self, app): | ||
| output = app.s2i_usage() | ||
| print(f"S2i_USAGE output: '{output}'") | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assert output != "" | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "dockerfile", | ||
| [ | ||
| "Dockerfile", | ||
| "Dockerfile.s2i" | ||
| ] | ||
| ) | ||
| def test_dockerfiles(self, app, dockerfile): | ||
| assert app.build_test_container( | ||
| dockerfile=f"{TEST_DIR}/examples/{dockerfile}", app_url="https://github.com/sclorg/httpd-ex.git", | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| app_dir="app-src" | ||
| ) | ||
| assert app.test_app_dockerfile() | ||
| cip = app.get_cip() | ||
| assert cip | ||
| assert app.test_response(url=f"{cip}", expected_code=200, expected_output="Welcome to your static httpd application on OpenShift") | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "mpm_config", | ||
| [ | ||
| "worker", | ||
| "event", | ||
| "prefork", | ||
| ] | ||
| ) | ||
| def test_mpm_config(self, app, mpm_config): | ||
| cid_name = f"test_mpm_{mpm_config}" | ||
| assert app.create_container(cid_file_name=cid_name, container_args=f"-e HTTPD_MPM={mpm_config} --user 1001") | ||
| cip = app.get_cip(cid_file_name=cid_name) | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # Let's check that server really response HTTP-403 | ||
| # See function here: in test/run `_run_mpm_config_test` | ||
| # https://github.com/sclorg/httpd-container/blob/master/test/run#L97 | ||
| assert app.test_response(url=f"{cip}", port=8080, expected_code=403, expected_output=".*" ) | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| logs = app.get_logs(cid_file_name=cid_name) | ||
| assert ContainerTestLibUtils.check_regexp_output( | ||
| regexp_to_check=f"mpm_{mpm_config}:notice.*resuming normal operations", | ||
| logs_to_check=logs | ||
| ) | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| def test_log_to_data_volume(self, app): | ||
| data_dir = ContainerTestLibUtils.create_local_temp_dir( | ||
| dir_name="/tmp/httpd-test_log_dir" | ||
| ) | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ContainerTestLibUtils.commands_to_run( | ||
| commands_to_run = [ | ||
| f"mkdir -p {data_dir}", | ||
| f"chown -R 1001:1001 {data_dir}", | ||
| f"chcon -Rvt svirt_sandbox_file_t {data_dir}/" | ||
| ] | ||
| ) | ||
| assert app.create_container( | ||
| cid_file_name="test_log_dir", | ||
| container_args=f"-e HTTPD_LOG_TO_VOLUME=1 --user 0 -v {data_dir}:/var/log/httpd" | ||
| ) | ||
| cip = app.get_cip(cid_file_name="test_log_dir") | ||
| assert app.test_response(url=f"{cip}", port=8080, expected_code=403, expected_output=".*") | ||
| assert ContainerTestLibUtils.check_files_are_present( | ||
| dir_name=data_dir, file_name_to_check=[ | ||
| "access_log", | ||
| "error_log", | ||
| "ssl_access_log", | ||
| "ssl_error_log", | ||
| "ssl_request_log", | ||
| ] | ||
| ) | ||
|
|
||
| def test_data_volume(self, app): | ||
| data_dir = ContainerTestLibUtils.create_local_temp_dir( | ||
| dir_name="/tmp/httpd-test-volume" | ||
| ) | ||
| ContainerTestLibUtils.commands_to_run( | ||
| commands_to_run = [ | ||
| f"mkdir -p {data_dir}/html", | ||
| f"echo hello > {data_dir}/html/index.html", | ||
| f"chown -R 1001:1001 {data_dir}", | ||
| f"chcon -Rvt svirt_sandbox_file_t {data_dir}/" | ||
| ] | ||
| ) | ||
| assert app.create_container( | ||
| cid_file_name="doc_root", | ||
| container_args=f"-v {data_dir}:/var/www" | ||
| ) | ||
| cip = app.get_cip(cid_file_name="doc_root") | ||
| assert cip | ||
| assert app.test_response(url=f"{cip}", port=8080, expected_code=200, expected_output="hello") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import os | ||
| import sys | ||
| import pytest | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| from container_ci_suite.container_lib import ContainerTestLib | ||
| from container_ci_suite.utils import check_variables | ||
|
|
||
|
|
||
| from constants import return_app_name | ||
|
|
||
|
|
||
| if not check_variables(): | ||
| print("At least one variable from OS, VERSION is missing.") | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| TEST_DIR = Path(os.path.abspath(os.path.dirname(__file__))) | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| VERSION = os.getenv("VERSION") | ||
| OS = os.getenv("TARGET") | ||
| IMAGE_NAME = os.getenv("IMAGE_NAME") | ||
| if not IMAGE_NAME: | ||
| print(f"Built container for version {VERSION} on OS {OS} does not exist.") | ||
| sys.exit(1) | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| image_tag_wo_tag = IMAGE_NAME.split(":")[0] | ||
| image_tag = IMAGE_NAME.split(":")[1] | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| pre_init_test_app = os.path.join(TEST_DIR, "pre-init-test-app") | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| sample_test_app = os.path.join(TEST_DIR, "sample-test-app") | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module", params=[pre_init_test_app]) | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| def s2i_app_pre_init(request): | ||
| container_lib = ContainerTestLib(IMAGE_NAME) | ||
| app_name = return_app_name(request) | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| s2i_app = container_lib.build_as_df( | ||
| app_path=request.param, | ||
| s2i_args="--pull-policy=never", | ||
| src_image=IMAGE_NAME, | ||
| dst_image=f"{IMAGE_NAME}-{app_name}" | ||
| ) | ||
| yield s2i_app | ||
| s2i_app.clean_containers() | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module", params=[sample_test_app]) | ||
| def s2i_sample_app(request): | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ci = ContainerTestLib(IMAGE_NAME) | ||
| app_name = return_app_name(request) | ||
| s2i_app = ci.build_as_df( | ||
| app_path=request.param, | ||
| s2i_args="--pull-policy=never", | ||
| src_image=IMAGE_NAME, | ||
| dst_image=f"{IMAGE_NAME}-{app_name}" | ||
| ) | ||
| yield s2i_app | ||
| s2i_app.clean_containers() | ||
|
||
|
|
||
|
|
||
| class TestHttpdS2IPreInitContainer: | ||
|
|
||
| def test_run_pre_init_test(self, s2i_app_pre_init): | ||
| assert s2i_app_pre_init.create_container(cid_file_name=s2i_app_pre_init.app_name, container_args="--user 1000") | ||
| cip = s2i_app_pre_init.get_cip(cid_file_name=s2i_app_pre_init.app_name) | ||
| assert cip | ||
| response = f"This content was replaced by pre-init script." | ||
phracek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assert s2i_app_pre_init.test_response(url=f"{cip}", expected_code=200, expected_output=response) | ||
|
|
||
|
|
||
| class TestHttpdS2ISampleAppContainer: | ||
|
|
||
| def test_sample_app(self, s2i_sample_app): | ||
| assert s2i_sample_app.create_container(cid_file_name=s2i_sample_app.app_name, container_args="--user 1000") | ||
| cip = s2i_sample_app.get_cip(cid_file_name=s2i_sample_app.app_name) | ||
| assert cip | ||
| response = "This is a sample s2i application with static content." | ||
| assert s2i_sample_app.test_response(url=f"{cip}", expected_code=200, expected_output=response) | ||
| assert s2i_sample_app.test_response( | ||
| url=f"https://{cip}", | ||
| port=8443, | ||
| expected_output=response | ||
| ) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.