From 435643f8179f673ed5d8088ba38b35ac67ddd391 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Wed, 13 May 2026 12:26:38 +0200 Subject: [PATCH 1/3] Let' use shared_cluster based on share_cluster.json variable Signed-off-by: Petr "Stone" Hracek --- test/test_ocp_ex_template.py | 4 +++- test/test_ocp_imagestream_s2i.py | 4 +++- test/test_ocp_integration.py | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/test/test_ocp_ex_template.py b/test/test_ocp_ex_template.py index 22f542e6..23b38b13 100644 --- a/test/test_ocp_ex_template.py +++ b/test/test_ocp_ex_template.py @@ -19,7 +19,9 @@ class TestHTTPDExExampleRepo: def setup_method(self): self.template_name = get_service_image(IMAGE_NAME) - self.oc_api = OpenShiftAPI(pod_name_prefix=self.template_name, version=VERSION) + self.oc_api = OpenShiftAPI( + pod_name_prefix=self.template_name, version=VERSION, shared_cluster=True + ) def teardown_method(self): self.oc_api.delete_project() diff --git a/test/test_ocp_imagestream_s2i.py b/test/test_ocp_imagestream_s2i.py index b4396187..5e3e563d 100644 --- a/test/test_ocp_imagestream_s2i.py +++ b/test/test_ocp_imagestream_s2i.py @@ -17,7 +17,9 @@ class TestHTTPDImagestreamS2I: def setup_method(self): self.template_name = get_service_image(IMAGE_NAME) - self.oc_api = OpenShiftAPI(pod_name_prefix=self.template_name, version=VERSION) + self.oc_api = OpenShiftAPI( + pod_name_prefix=self.template_name, version=VERSION, shared_cluster=True + ) def teardown_method(self): self.oc_api.delete_project() diff --git a/test/test_ocp_integration.py b/test/test_ocp_integration.py index 402088fb..1288d0fc 100644 --- a/test/test_ocp_integration.py +++ b/test/test_ocp_integration.py @@ -17,7 +17,9 @@ class TestHTTPDIntegrationTemplate: def setup_method(self): self.template_name = get_service_image(IMAGE_NAME) - self.oc_api = OpenShiftAPI(pod_name_prefix=self.template_name, version=VERSION) + self.oc_api = OpenShiftAPI( + pod_name_prefix=self.template_name, version=VERSION, shared_cluster=True + ) def teardown_method(self): self.oc_api.delete_project() From d9ed2b7dc48c731afcec09a84e5c3beee81704ef Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Thu, 14 May 2026 13:40:11 +0200 Subject: [PATCH 2/3] Let's make test more readable like we do in the rest containers. Inspiration is taken from mariadb-container and mysql-container. Let's use conftest.py instead of a lot of duplication in alone PyTest files Signed-off-by: Petr "Stone" Hracek --- 2.4-micro/test/conftest.py | 1 + 2.4-micro/test/constants.py | 1 - 2.4/test/conftest.py | 1 + 2.4/test/constants.py | 1 - test/conftest.py | 40 +++++++++++++++++++++ test/constants.py | 5 --- test/test_ocp_ex_template.py | 22 +++--------- test/test_ocp_imagestream_s2i.py | 24 +++++-------- test/test_ocp_imagestreams.py | 16 ++------- test/test_ocp_integration.py | 20 +++-------- test/test_ocp_shared_helm_imagestreams.py | 16 +++++---- test/test_ocp_shared_helm_template.py | 43 ++++++++--------------- 12 files changed, 87 insertions(+), 103 deletions(-) create mode 120000 2.4-micro/test/conftest.py delete mode 120000 2.4-micro/test/constants.py create mode 120000 2.4/test/conftest.py delete mode 120000 2.4/test/constants.py create mode 100644 test/conftest.py delete mode 100644 test/constants.py diff --git a/2.4-micro/test/conftest.py b/2.4-micro/test/conftest.py new file mode 120000 index 00000000..3f2d7840 --- /dev/null +++ b/2.4-micro/test/conftest.py @@ -0,0 +1 @@ +../../test/conftest.py \ No newline at end of file diff --git a/2.4-micro/test/constants.py b/2.4-micro/test/constants.py deleted file mode 120000 index 360f725b..00000000 --- a/2.4-micro/test/constants.py +++ /dev/null @@ -1 +0,0 @@ -../../test/constants.py \ No newline at end of file diff --git a/2.4/test/conftest.py b/2.4/test/conftest.py new file mode 120000 index 00000000..3f2d7840 --- /dev/null +++ b/2.4/test/conftest.py @@ -0,0 +1 @@ +../../test/conftest.py \ No newline at end of file diff --git a/2.4/test/constants.py b/2.4/test/constants.py deleted file mode 120000 index 360f725b..00000000 --- a/2.4/test/constants.py +++ /dev/null @@ -1 +0,0 @@ -../../test/constants.py \ No newline at end of file diff --git a/test/conftest.py b/test/conftest.py new file mode 100644 index 00000000..70121825 --- /dev/null +++ b/test/conftest.py @@ -0,0 +1,40 @@ +import os +import sys + +from pathlib import Path +from collections import namedtuple + +from container_ci_suite.utils import check_variables + +if not check_variables(): + sys.exit(1) + +TAGS = { + "rhel8": "-ubi8", + "rhel9": "-ubi9", + "rhel10": "-ubi10", +} + +TEST_DIR = Path(__file__).parent.absolute() +Vars = namedtuple( + "Vars", + [ + "OS", + "TAG", + "VERSION", + "IMAGE_NAME", + "SHORT_VERSION", + "TEST_DIR", + ], +) +OS = os.getenv("TARGET").lower() +VERSION = os.getenv("VERSION") + +VARS = Vars( + OS=OS, + TAG=TAGS.get(OS), + VERSION=VERSION, + IMAGE_NAME=os.getenv("IMAGE_NAME"), + SHORT_VERSION=VERSION.replace(".", ""), + TEST_DIR=TEST_DIR, +) diff --git a/test/constants.py b/test/constants.py deleted file mode 100644 index e0402ba6..00000000 --- a/test/constants.py +++ /dev/null @@ -1,5 +0,0 @@ -TAGS = { - "rhel8": "-ubi8", - "rhel9": "-ubi9", - "rhel10": "-ubi10", -} diff --git a/test/test_ocp_ex_template.py b/test/test_ocp_ex_template.py index 23b38b13..8f56d764 100644 --- a/test/test_ocp_ex_template.py +++ b/test/test_ocp_ex_template.py @@ -1,26 +1,14 @@ -import os -import sys - -from pathlib import Path - from container_ci_suite.openshift import OpenShiftAPI -from container_ci_suite.utils import get_service_image, check_variables - -if not check_variables(): - print("At least one variable from IMAGE_NAME, OS, VERSION is missing.") - sys.exit(1) - +from container_ci_suite.utils import get_service_image -TEST_DIR = Path(os.path.abspath(os.path.dirname(__file__))) -VERSION = os.getenv("VERSION") -IMAGE_NAME = os.getenv("IMAGE_NAME") +from conftest import VARS class TestHTTPDExExampleRepo: def setup_method(self): - self.template_name = get_service_image(IMAGE_NAME) + self.template_name = get_service_image(VARS.IMAGE_NAME) self.oc_api = OpenShiftAPI( - pod_name_prefix=self.template_name, version=VERSION, shared_cluster=True + pod_name_prefix=self.template_name, version=VARS.VERSION, shared_cluster=True ) def teardown_method(self): @@ -28,7 +16,7 @@ def teardown_method(self): def test_httpd_ex_template_inside_cluster(self): assert self.oc_api.deploy_s2i_app( - image_name=IMAGE_NAME, + image_name=VARS.IMAGE_NAME, app="https://github.com/sclorg/httpd-ex#master", context=".", ) diff --git a/test/test_ocp_imagestream_s2i.py b/test/test_ocp_imagestream_s2i.py index 5e3e563d..d4ab6589 100644 --- a/test/test_ocp_imagestream_s2i.py +++ b/test/test_ocp_imagestream_s2i.py @@ -1,34 +1,26 @@ -import os -import sys - from container_ci_suite.openshift import OpenShiftAPI -from container_ci_suite.utils import get_service_image, check_variables - - -if not check_variables(): - print("At least one variable from IMAGE_NAME, OS, SINGLE_VERSION is missing.") - sys.exit(1) +from container_ci_suite.utils import get_service_image -IMAGE_NAME = os.getenv("IMAGE_NAME") -OS = os.getenv("OS") -VERSION = os.getenv("VERSION") +from conftest import VARS class TestHTTPDImagestreamS2I: def setup_method(self): - self.template_name = get_service_image(IMAGE_NAME) + self.template_name = get_service_image(VARS.IMAGE_NAME) self.oc_api = OpenShiftAPI( - pod_name_prefix=self.template_name, version=VERSION, shared_cluster=True + pod_name_prefix=self.template_name, + version=VARS.VERSION, + shared_cluster=True ) def teardown_method(self): self.oc_api.delete_project() def test_inside_cluster(self): - os_name = "".join(i for i in OS if not i.isdigit()) + os_name = "".join(i for i in VARS.OS if not i.isdigit()) assert self.oc_api.deploy_imagestream_s2i( imagestream_file=f"imagestreams/httpd-{os_name}.json", - image_name=IMAGE_NAME, + image_name=VARS.IMAGE_NAME, app="https://github.com/sclorg/httpd-container.git", context="examples/sample-test-app", service_name=self.template_name, diff --git a/test/test_ocp_imagestreams.py b/test/test_ocp_imagestreams.py index ae8f88a2..66484266 100644 --- a/test/test_ocp_imagestreams.py +++ b/test/test_ocp_imagestreams.py @@ -1,24 +1,14 @@ -import os -import sys - -from pathlib import Path - from container_ci_suite.imagestreams import ImageStreamChecker -from container_ci_suite.utils import check_variables - -TEST_DIR = Path(os.path.abspath(os.path.dirname(__file__))) -if not check_variables(): - print("At least one variable from IMAGE_NAME, OS, SINGLE_VERSION is missing.") - sys.exit(1) +from conftest import VARS class TestLatestImagestreams: def setup_method(self): - self.isc = ImageStreamChecker(working_dir=TEST_DIR.parent.parent) + self.isc = ImageStreamChecker(working_dir=VARS.TEST_DIR.parent.parent) def test_latest_imagestream(self): self.latest_version = self.isc.get_latest_version() - assert self.latest_version != "" + assert self.latest_version self.isc.check_imagestreams(self.latest_version) diff --git a/test/test_ocp_integration.py b/test/test_ocp_integration.py index 1288d0fc..de79cfb4 100644 --- a/test/test_ocp_integration.py +++ b/test/test_ocp_integration.py @@ -1,24 +1,14 @@ -import os -import sys - from container_ci_suite.openshift import OpenShiftAPI -from container_ci_suite.utils import get_service_image, check_variables - - -if not check_variables(): - print("At least one variable from IMAGE_NAME, OS, VERSION is missing.") - sys.exit(1) - +from container_ci_suite.utils import get_service_image -VERSION = os.getenv("VERSION") -IMAGE_NAME = os.getenv("IMAGE_NAME") +from conftest import VARS class TestHTTPDIntegrationTemplate: def setup_method(self): - self.template_name = get_service_image(IMAGE_NAME) + self.template_name = get_service_image(VARS.IMAGE_NAME) self.oc_api = OpenShiftAPI( - pod_name_prefix=self.template_name, version=VERSION, shared_cluster=True + pod_name_prefix=self.template_name, version=VARS.VERSION, shared_cluster=True ) def teardown_method(self): @@ -26,7 +16,7 @@ def teardown_method(self): def test_httpd_ex_template_inside_cluster(self): assert self.oc_api.deploy_s2i_app( - image_name=IMAGE_NAME, + image_name=VARS.IMAGE_NAME, app="https://github.com/sclorg/httpd-container.git", context="examples/sample-test-app", ) diff --git a/test/test_ocp_shared_helm_imagestreams.py b/test/test_ocp_shared_helm_imagestreams.py index d910964b..3ee0faec 100644 --- a/test/test_ocp_shared_helm_imagestreams.py +++ b/test/test_ocp_shared_helm_imagestreams.py @@ -1,21 +1,23 @@ -import os - import pytest -from pathlib import Path from container_ci_suite.helm import HelmChartsAPI -test_dir = Path(os.path.abspath(os.path.dirname(__file__))) +from conftest import VARS class TestHelmRHELHttpdImageStreams: def setup_method(self): package_name = "redhat-httpd-imagestreams" - path = test_dir - self.hc_api = HelmChartsAPI(path=path, package_name=package_name, tarball_dir=test_dir, shared_cluster=True) + self.hc_api = HelmChartsAPI( + path=VARS.TEST_DIR, + package_name=package_name, + tarball_dir=VARS.TEST_DIR, + shared_cluster=True + ) self.hc_api.clone_helm_chart_repo( - repo_url="https://github.com/sclorg/helm-charts", repo_name="helm-charts", + repo_url="https://github.com/sclorg/helm-charts", + repo_name="helm-charts", subdir="charts/redhat" ) diff --git a/test/test_ocp_shared_helm_template.py b/test/test_ocp_shared_helm_template.py index 8d7bda8f..3466e1e1 100644 --- a/test/test_ocp_shared_helm_template.py +++ b/test/test_ocp_shared_helm_template.py @@ -1,35 +1,20 @@ -import os -import sys - -from pathlib import Path - from container_ci_suite.helm import HelmChartsAPI -from container_ci_suite.utils import check_variables - -from constants import TAGS - - -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") -IMAGE_NAME = os.getenv("IMAGE_NAME") -OS = os.getenv("OS") - -TAG = TAGS.get(OS) +from conftest import VARS class TestHelmHTTPDTemplate: def setup_method(self): package_name = "redhat-httpd-template" - path = test_dir - self.hc_api = HelmChartsAPI(path=path, package_name=package_name, tarball_dir=test_dir, shared_cluster=True) + self.hc_api = HelmChartsAPI( + path=VARS.TEST_DIR, package_name=package_name, + tarball_dir=VARS.TEST_DIR, + shared_cluster=True + ) self.hc_api.clone_helm_chart_repo( - repo_url="https://github.com/sclorg/helm-charts", repo_name="helm-charts", + repo_url="https://github.com/sclorg/helm-charts", + repo_name="helm-charts", subdir="charts/redhat" ) @@ -37,9 +22,9 @@ def teardown_method(self): self.hc_api.delete_project() def test_package_persistent_by_helm_chart_test(self): - new_version = VERSION - if "micro" in VERSION: - new_version = VERSION.replace("-micro", "") + new_version = VARS.VERSION + if "micro" in VARS.VERSION: + new_version = VARS.VERSION.replace("-micro", "") self.hc_api.package_name = "redhat-httpd-imagestreams" self.hc_api.helm_package() assert self.hc_api.helm_installation() @@ -47,9 +32,11 @@ def test_package_persistent_by_helm_chart_test(self): self.hc_api.helm_package() assert self.hc_api.helm_installation( values={ - "httpd_version": f"{new_version}{TAG}", + "httpd_version": f"{new_version}{VARS.TAG}", "namespace": self.hc_api.namespace } ) assert self.hc_api.is_s2i_pod_running(pod_name_prefix="httpd-example") - assert self.hc_api.test_helm_chart(expected_str=["Welcome to your static httpd application on OpenShift"]) + assert self.hc_api.test_helm_chart( + expected_str=["Welcome to your static httpd application on OpenShift"] + ) From 8755cb1f0f11c7b26e3b25e7cc3ab205ca5b9a94 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Fri, 15 May 2026 09:28:02 +0200 Subject: [PATCH 3/3] remove SHORT_VERSION that is not needed at all Signed-off-by: Petr "Stone" Hracek --- test/conftest.py | 2 -- test/test_ocp_ex_template.py | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index 70121825..4e073aa0 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -23,7 +23,6 @@ "TAG", "VERSION", "IMAGE_NAME", - "SHORT_VERSION", "TEST_DIR", ], ) @@ -35,6 +34,5 @@ TAG=TAGS.get(OS), VERSION=VERSION, IMAGE_NAME=os.getenv("IMAGE_NAME"), - SHORT_VERSION=VERSION.replace(".", ""), TEST_DIR=TEST_DIR, ) diff --git a/test/test_ocp_ex_template.py b/test/test_ocp_ex_template.py index 8f56d764..cb172ae9 100644 --- a/test/test_ocp_ex_template.py +++ b/test/test_ocp_ex_template.py @@ -8,7 +8,9 @@ class TestHTTPDExExampleRepo: def setup_method(self): self.template_name = get_service_image(VARS.IMAGE_NAME) self.oc_api = OpenShiftAPI( - pod_name_prefix=self.template_name, version=VARS.VERSION, shared_cluster=True + pod_name_prefix=self.template_name, + version=VARS.VERSION, + shared_cluster=True, ) def teardown_method(self):