From 438f2be41745abeec85ae27bce3b75d80d1779b8 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Wed, 27 Nov 2024 13:02:16 +0100 Subject: [PATCH 1/3] First PoC for testing httpd-2.4 container by PyTest Signed-off-by: Petr "Stone" Hracek --- 2.4/test/container/test_httpd.py | 1 + 2.4/test/container/test_httpd_s2i.py | 1 + test/container/test_httpd.py | 55 +++++++++++++++++++ test/container/test_httpd_s2i.py | 53 ++++++++++++++++++ .../{ => openshift}/test_httpd_ex_template.py | 0 .../test_httpd_imagestream_s2i.py | 0 .../test_httpd_imagestreams.py | 0 .../{ => openshift}/test_httpd_integration.py | 0 .../test_httpd_shared_helm_imagestreams.py | 0 .../test_httpd_shared_helm_template.py | 0 10 files changed, 110 insertions(+) create mode 120000 2.4/test/container/test_httpd.py create mode 120000 2.4/test/container/test_httpd_s2i.py create mode 100644 test/container/test_httpd.py create mode 100644 test/container/test_httpd_s2i.py rename test/{ => openshift}/test_httpd_ex_template.py (100%) rename test/{ => openshift}/test_httpd_imagestream_s2i.py (100%) rename test/{ => openshift}/test_httpd_imagestreams.py (100%) rename test/{ => openshift}/test_httpd_integration.py (100%) rename test/{ => openshift}/test_httpd_shared_helm_imagestreams.py (100%) rename test/{ => openshift}/test_httpd_shared_helm_template.py (100%) diff --git a/2.4/test/container/test_httpd.py b/2.4/test/container/test_httpd.py new file mode 120000 index 00000000..feb1dd5f --- /dev/null +++ b/2.4/test/container/test_httpd.py @@ -0,0 +1 @@ +../../../test/container/test_httpd.py \ No newline at end of file diff --git a/2.4/test/container/test_httpd_s2i.py b/2.4/test/container/test_httpd_s2i.py new file mode 120000 index 00000000..4a108e73 --- /dev/null +++ b/2.4/test/container/test_httpd_s2i.py @@ -0,0 +1 @@ +../../../test/container/test_httpd_s2i.py \ No newline at end of file diff --git a/test/container/test_httpd.py b/test/container/test_httpd.py new file mode 100644 index 00000000..ec7acf25 --- /dev/null +++ b/test/container/test_httpd.py @@ -0,0 +1,55 @@ +import os +import sys +import pytest + +from container_ci_suite.engines.container import ContainerImage +from container_ci_suite.utils import check_variables + +if not check_variables(): + print("At least one variable from IMAGE_NAME, OS, VERSION is missing.") + sys.exit(1) + +VERSION = os.getenv("VERSION") +IMAGE_NAME = os.getenv("IMAGE_NAME") +OS = os.getenv("TARGET") + +image_name = os.environ.get("IMAGE_NAME").split(":")[0] +image_tag = os.environ.get("IMAGE_NAME").split(":")[1] +test_dir = os.path.abspath(os.path.dirname(__file__)) +print(f"Test dir is: {test_dir}") + + +@pytest.fixture(scope="module") +def app(request): + app = ContainerImage(image_name) + print(request) + # app_name = os.path.basename(request.param) + yield app + pass + #app.rmi() + + +class TestHttpdAppContainer: + + def test_default_path(self, app): + assert app.create_container(cid_file="test_default_page") + cip = app.get_cip() + 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_tests=3) + + def test_run_as_root(self, app): + assert app.create_container(cid_file="test_default_page", container_args="--user 0") + cip = app.get_cip() + 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_tests=3) + + def test_run_s2i_usage(self, app): + assert app.s2i_usage() != "" diff --git a/test/container/test_httpd_s2i.py b/test/container/test_httpd_s2i.py new file mode 100644 index 00000000..ce4bb674 --- /dev/null +++ b/test/container/test_httpd_s2i.py @@ -0,0 +1,53 @@ +import os +import sys +import pytest + +from container_ci_suite.engines.s2i_container import S2IContainerImage +from container_ci_suite.utils import check_variables + +if not check_variables(): + print("At least one variable from IMAGE_NAME, OS, VERSION is missing.") + sys.exit(1) + +VERSION = os.getenv("VERSION") +IMAGE_NAME = os.getenv("IMAGE_NAME") +OS = os.getenv("TARGET") + +full_image_name = os.environ.get("IMAGE_NAME") +image_tag_wo_tag = os.environ.get("IMAGE_NAME").split(":")[0] +image_tag = os.environ.get("IMAGE_NAME").split(":")[1] +test_dir = os.path.abspath(os.path.dirname(__file__)) +pre_init_test_app = os.path.join(test_dir, "..", "pre-init-test-app") + +app_paths = [ + pre_init_test_app +] + + +@pytest.fixture(scope="module", params=app_paths) +def s2i_app(request): + ci = S2IContainerImage(full_image_name) + app_name = os.path.basename(request.param) + s2i_app = ci.s2i_build_as_df( + app_path=request.param, + s2i_args="--pull-policy=never", + src_image=full_image_name, + dst_image=f"{full_image_name}-{app_name}" + ) + yield s2i_app + pass + if s2i_app: + s2i_app.cleanup_container() + + +class TestHttpdS2IContainer: + + def test_run_pre_init_test(self, s2i_app): + print("run_pre_init_test") + assert s2i_app + assert s2i_app.create_container(cid_file="testing-app-pre-init", container_args="--user 1000") + cip = s2i_app.get_cip() + assert cip + response = "This content was replaced by pre-init script." + assert s2i_app.test_response(url=f"{cip}", expected_code=200, expected_output=response) + diff --git a/test/test_httpd_ex_template.py b/test/openshift/test_httpd_ex_template.py similarity index 100% rename from test/test_httpd_ex_template.py rename to test/openshift/test_httpd_ex_template.py diff --git a/test/test_httpd_imagestream_s2i.py b/test/openshift/test_httpd_imagestream_s2i.py similarity index 100% rename from test/test_httpd_imagestream_s2i.py rename to test/openshift/test_httpd_imagestream_s2i.py diff --git a/test/test_httpd_imagestreams.py b/test/openshift/test_httpd_imagestreams.py similarity index 100% rename from test/test_httpd_imagestreams.py rename to test/openshift/test_httpd_imagestreams.py diff --git a/test/test_httpd_integration.py b/test/openshift/test_httpd_integration.py similarity index 100% rename from test/test_httpd_integration.py rename to test/openshift/test_httpd_integration.py diff --git a/test/test_httpd_shared_helm_imagestreams.py b/test/openshift/test_httpd_shared_helm_imagestreams.py similarity index 100% rename from test/test_httpd_shared_helm_imagestreams.py rename to test/openshift/test_httpd_shared_helm_imagestreams.py diff --git a/test/test_httpd_shared_helm_template.py b/test/openshift/test_httpd_shared_helm_template.py similarity index 100% rename from test/test_httpd_shared_helm_template.py rename to test/openshift/test_httpd_shared_helm_template.py From 89890511e29b8050d2cdbf7ea2d8b045c0f8292e Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Thu, 28 Nov 2024 11:32:58 +0100 Subject: [PATCH 2/3] Add support for s2i builds in httpd container Signed-off-by: Petr "Stone" Hracek --- test/container/test_httpd.py | 24 +++++++++++++-- test/container/test_httpd_s2i.py | 52 +++++++++++++++++++++++++------- 2 files changed, 62 insertions(+), 14 deletions(-) diff --git a/test/container/test_httpd.py b/test/container/test_httpd.py index ec7acf25..cec09aec 100644 --- a/test/container/test_httpd.py +++ b/test/container/test_httpd.py @@ -11,7 +11,7 @@ VERSION = os.getenv("VERSION") IMAGE_NAME = os.getenv("IMAGE_NAME") -OS = os.getenv("TARGET") +OS = os.getenv("OS") image_name = os.environ.get("IMAGE_NAME").split(":")[0] image_tag = os.environ.get("IMAGE_NAME").split(":")[1] @@ -26,11 +26,10 @@ def app(request): # app_name = os.path.basename(request.param) yield app pass - #app.rmi() + app.cleanup_container() class TestHttpdAppContainer: - def test_default_path(self, app): assert app.create_container(cid_file="test_default_page") cip = app.get_cip() @@ -53,3 +52,22 @@ def test_run_as_root(self, app): def test_run_s2i_usage(self, app): assert app.s2i_usage() != "" + + @pytest.mark.parametrize( + "dockerfile", + [ + "Dockerfile", + "Dockerfile.s2i" + ] + ) + def test_dockerfiles(self, app, dockerfile): + assert app.build_test_container( + dockerfile=f"test/examples/{dockerfile}", app_url="https://github.com/sclorg/httpd-ex.git", + app_dir="app-src" + ) + assert app.test_run_app_dockerfile() + cip = app.get_app_cip() + assert cip + assert app.test_response(url=f"{cip}", expected_code=200, expected_output="Welcome to your static httpd application on OpenShift") + app.rmi_app() + diff --git a/test/container/test_httpd_s2i.py b/test/container/test_httpd_s2i.py index ce4bb674..d5a8ca2b 100644 --- a/test/container/test_httpd_s2i.py +++ b/test/container/test_httpd_s2i.py @@ -18,14 +18,15 @@ image_tag = os.environ.get("IMAGE_NAME").split(":")[1] test_dir = os.path.abspath(os.path.dirname(__file__)) pre_init_test_app = os.path.join(test_dir, "..", "pre-init-test-app") +self_cert_test = os.path.join(test_dir, "..", "self-signed-ssl") +sample_test_app = os.path.join(test_dir, "..", "sample-test-app") -app_paths = [ - pre_init_test_app -] +app_params_pre = [pre_init_test_app] +app_params_sample = [sample_test_app] -@pytest.fixture(scope="module", params=app_paths) -def s2i_app(request): +@pytest.fixture(scope="module", params=app_params_pre) +def s2i_app_pre_init(request): ci = S2IContainerImage(full_image_name) app_name = os.path.basename(request.param) s2i_app = ci.s2i_build_as_df( @@ -40,14 +41,43 @@ def s2i_app(request): s2i_app.cleanup_container() -class TestHttpdS2IContainer: +@pytest.fixture(scope="module", params=app_params_sample) +def s2i_sample_app(request): + ci = S2IContainerImage(full_image_name) + app_name = os.path.basename(request.param) + s2i_app = ci.s2i_build_as_df( + app_path=request.param, + s2i_args="--pull-policy=never", + src_image=full_image_name, + dst_image=f"{full_image_name}-{app_name}" + ) + yield s2i_app + pass + if s2i_app: + s2i_app.cleanup_container() + + +@pytest.mark.usefixtures("s2i_app_pre_init") +class TestHttpdS2IPreInitContainer: - def test_run_pre_init_test(self, s2i_app): + def test_run_pre_init_test(self, s2i_app_pre_init): print("run_pre_init_test") - assert s2i_app - assert s2i_app.create_container(cid_file="testing-app-pre-init", container_args="--user 1000") - cip = s2i_app.get_cip() + assert s2i_app_pre_init + assert s2i_app_pre_init.create_container(cid_file="testing-app-pre-init", container_args="--user 1000", image_name=s2i_app_pre_init.image_name) + cip = s2i_app_pre_init.get_cip() assert cip response = "This content was replaced by pre-init script." - assert s2i_app.test_response(url=f"{cip}", expected_code=200, expected_output=response) + assert s2i_app_pre_init.test_response(url=f"{cip}", expected_code=200, expected_output=response) + +@pytest.mark.usefixtures("s2i_sample_app") +class TestHttpdS2ISampleAppContainer: + + def test_self_cert_test(self, s2i_sample_app): + print("run_pre_init_test") + assert s2i_sample_app + assert s2i_sample_app.create_container(cid_file="testing-sample=app", container_args="--user 1000", image_name=s2i_sample_app.image_name) + cip = s2i_sample_app.get_cip() + 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) From c011dbf9c919d8cbeccba698b71cdc2b845fcf19 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Tue, 3 Dec 2024 15:01:45 +0100 Subject: [PATCH 3/3] Reorganize tests in httpd-container repository Signed-off-by: Petr "Stone" Hracek --- 2.4/test/container | 1 + 2.4/test/container/test_httpd.py | 1 - 2.4/test/container/test_httpd_s2i.py | 1 - 2.4/test/openshift | 1 + 2.4/test/test_httpd_ex_template.py | 1 - 2.4/test/test_httpd_imagestream_s2i.py | 1 - 2.4/test/test_httpd_imagestreams.py | 1 - 2.4/test/test_httpd_integration.py | 1 - 2.4/test/test_httpd_shared_helm_imagestreams.py | 1 - 2.4/test/test_httpd_shared_helm_template.py | 1 - 10 files changed, 2 insertions(+), 8 deletions(-) create mode 120000 2.4/test/container delete mode 120000 2.4/test/container/test_httpd.py delete mode 120000 2.4/test/container/test_httpd_s2i.py create mode 120000 2.4/test/openshift delete mode 120000 2.4/test/test_httpd_ex_template.py delete mode 120000 2.4/test/test_httpd_imagestream_s2i.py delete mode 120000 2.4/test/test_httpd_imagestreams.py delete mode 120000 2.4/test/test_httpd_integration.py delete mode 120000 2.4/test/test_httpd_shared_helm_imagestreams.py delete mode 120000 2.4/test/test_httpd_shared_helm_template.py diff --git a/2.4/test/container b/2.4/test/container new file mode 120000 index 00000000..bf5e5a70 --- /dev/null +++ b/2.4/test/container @@ -0,0 +1 @@ +../../test/container \ No newline at end of file diff --git a/2.4/test/container/test_httpd.py b/2.4/test/container/test_httpd.py deleted file mode 120000 index feb1dd5f..00000000 --- a/2.4/test/container/test_httpd.py +++ /dev/null @@ -1 +0,0 @@ -../../../test/container/test_httpd.py \ No newline at end of file diff --git a/2.4/test/container/test_httpd_s2i.py b/2.4/test/container/test_httpd_s2i.py deleted file mode 120000 index 4a108e73..00000000 --- a/2.4/test/container/test_httpd_s2i.py +++ /dev/null @@ -1 +0,0 @@ -../../../test/container/test_httpd_s2i.py \ No newline at end of file diff --git a/2.4/test/openshift b/2.4/test/openshift new file mode 120000 index 00000000..6f7addda --- /dev/null +++ b/2.4/test/openshift @@ -0,0 +1 @@ +../../test/openshift \ No newline at end of file diff --git a/2.4/test/test_httpd_ex_template.py b/2.4/test/test_httpd_ex_template.py deleted file mode 120000 index 922da056..00000000 --- a/2.4/test/test_httpd_ex_template.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_httpd_ex_template.py \ No newline at end of file diff --git a/2.4/test/test_httpd_imagestream_s2i.py b/2.4/test/test_httpd_imagestream_s2i.py deleted file mode 120000 index b24e3bab..00000000 --- a/2.4/test/test_httpd_imagestream_s2i.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_httpd_imagestream_s2i.py \ No newline at end of file diff --git a/2.4/test/test_httpd_imagestreams.py b/2.4/test/test_httpd_imagestreams.py deleted file mode 120000 index c356f03a..00000000 --- a/2.4/test/test_httpd_imagestreams.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_httpd_imagestreams.py \ No newline at end of file diff --git a/2.4/test/test_httpd_integration.py b/2.4/test/test_httpd_integration.py deleted file mode 120000 index 6634e2d6..00000000 --- a/2.4/test/test_httpd_integration.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_httpd_integration.py \ No newline at end of file diff --git a/2.4/test/test_httpd_shared_helm_imagestreams.py b/2.4/test/test_httpd_shared_helm_imagestreams.py deleted file mode 120000 index 94930d9a..00000000 --- a/2.4/test/test_httpd_shared_helm_imagestreams.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_httpd_shared_helm_imagestreams.py \ No newline at end of file diff --git a/2.4/test/test_httpd_shared_helm_template.py b/2.4/test/test_httpd_shared_helm_template.py deleted file mode 120000 index eec4d0a4..00000000 --- a/2.4/test/test_httpd_shared_helm_template.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_httpd_shared_helm_template.py \ No newline at end of file