Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 2.4-micro/test/run-pytest
1 change: 1 addition & 0 deletions 2.4-micro/test/test_container_httpd.py
1 change: 1 addition & 0 deletions 2.4-micro/test/test_container_httpd_s2i.py
1 change: 1 addition & 0 deletions 2.4-micro/test/test_container_ssl.py
1 change: 0 additions & 1 deletion 2.4-micro/test/test_httpd_ex_template.py

This file was deleted.

1 change: 0 additions & 1 deletion 2.4-micro/test/test_httpd_imagestream_s2i.py

This file was deleted.

1 change: 0 additions & 1 deletion 2.4-micro/test/test_httpd_imagestreams.py

This file was deleted.

1 change: 0 additions & 1 deletion 2.4-micro/test/test_httpd_integration.py

This file was deleted.

1 change: 0 additions & 1 deletion 2.4-micro/test/test_httpd_shared_helm_imagestreams.py

This file was deleted.

1 change: 0 additions & 1 deletion 2.4-micro/test/test_httpd_shared_helm_template.py

This file was deleted.

1 change: 1 addition & 0 deletions 2.4-micro/test/test_ocp_ex_template.py
1 change: 1 addition & 0 deletions 2.4-micro/test/test_ocp_imagestream_s2i.py
1 change: 1 addition & 0 deletions 2.4-micro/test/test_ocp_imagestreams.py
1 change: 1 addition & 0 deletions 2.4-micro/test/test_ocp_integration.py
1 change: 1 addition & 0 deletions 2.4-micro/test/test_ocp_shared_helm_imagestreams.py
1 change: 1 addition & 0 deletions 2.4-micro/test/test_ocp_shared_helm_template.py
1 change: 1 addition & 0 deletions 2.4/test/run-pytest
1 change: 1 addition & 0 deletions 2.4/test/test_container_httpd.py
1 change: 1 addition & 0 deletions 2.4/test/test_container_httpd_s2i.py
1 change: 1 addition & 0 deletions 2.4/test/test_container_ssl.py
1 change: 0 additions & 1 deletion 2.4/test/test_httpd_ex_template.py

This file was deleted.

1 change: 0 additions & 1 deletion 2.4/test/test_httpd_imagestream_s2i.py

This file was deleted.

1 change: 0 additions & 1 deletion 2.4/test/test_httpd_imagestreams.py

This file was deleted.

1 change: 0 additions & 1 deletion 2.4/test/test_httpd_integration.py

This file was deleted.

1 change: 0 additions & 1 deletion 2.4/test/test_httpd_shared_helm_imagestreams.py

This file was deleted.

1 change: 0 additions & 1 deletion 2.4/test/test_httpd_shared_helm_template.py

This file was deleted.

1 change: 1 addition & 0 deletions 2.4/test/test_ocp_ex_template.py
1 change: 1 addition & 0 deletions 2.4/test/test_ocp_imagestream_s2i.py
1 change: 1 addition & 0 deletions 2.4/test/test_ocp_imagestreams.py
1 change: 1 addition & 0 deletions 2.4/test/test_ocp_integration.py
1 change: 1 addition & 0 deletions 2.4/test/test_ocp_shared_helm_imagestreams.py
1 change: 1 addition & 0 deletions 2.4/test/test_ocp_shared_helm_template.py
6 changes: 6 additions & 0 deletions test/constants.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)
15 changes: 15 additions & 0 deletions test/run-pytest
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
# 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
146 changes: 146 additions & 0 deletions test/test_container_httpd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
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, ContainerTestLibUtils


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__)))
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.")
sys.exit(1)
print(f"Test dir is: {TEST_DIR}")


@pytest.fixture(scope="module")
def app(request):
app = ContainerTestLib(image_name=IMAGE_NAME, s2i_image=True)
yield app
app.clean_containers()
app.clean_app_images()


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":
response = "HTTP Server Test Page"
else:
# The RHEL and Fedora OS gets this response
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_as_root(self, app):
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}'")
assert output != ""

@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",
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)
# 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=".*" )
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
)
def test_log_to_data_volume(self, app):
data_dir = ContainerTestLibUtils.create_local_temp_dir(
dir_name="/tmp/httpd-test_log_dir"
)
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")
84 changes: 84 additions & 0 deletions test/test_container_httpd_s2i.py
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__)))
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)

image_tag_wo_tag = IMAGE_NAME.split(":")[0]
image_tag = IMAGE_NAME.split(":")[1]
pre_init_test_app = os.path.join(TEST_DIR, "pre-init-test-app")
sample_test_app = os.path.join(TEST_DIR, "sample-test-app")


@pytest.fixture(scope="module", params=[pre_init_test_app])
def s2i_app_pre_init(request):
container_lib = ContainerTestLib(IMAGE_NAME)
app_name = return_app_name(request)
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):
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be removed, as the fixture takes care of the cleanup.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow, where it is specified, that fixture takes care of the cleanup?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed here, but I don't know if it right approach d53f360

Copy link
Member

@befeleme befeleme Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must have commented on the wrong line, sorry. So: s2i_app_pre_init fixture, which is defined on line 34 has a yield statement, which will give the initiated app for the disposal of the test case. Once the tests in this module (fixture says: scope="module") are all performed, the code after yield statement will continue. So the line 44 with the cleanup will be always called afterwards.
As I understand it, the statement in test_run_pre_init_test was doing the same action, and removing the cleanup part from it, as in d53f360 is a correct approach.



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."
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
)

Loading