From f63ce707ec2161808b89b504defe9a812eba4de0 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Thu, 19 Mar 2026 13:45:10 +0100 Subject: [PATCH] Rename constanst.py to conftest.py Update also OpenShift part Signed-off-by: Petr "Stone" Hracek --- test/conftest.py | 73 +++++++++++++++++++ test/constants.py | 5 -- test/test_ocp_psql_imagestream.py | 34 ++------- test/test_ocp_psql_imagestream_template.py | 31 ++------ test/test_ocp_psql_latest_imagestreams.py | 19 +---- test/test_ocp_psql_template.py | 47 ++++-------- .../test_ocp_shared_helm_psql_imagestreams.py | 30 ++++---- test/test_ocp_shared_helm_psql_template.py | 45 ++++-------- 8 files changed, 135 insertions(+), 149 deletions(-) create mode 100644 test/conftest.py delete mode 100644 test/constants.py diff --git a/test/conftest.py b/test/conftest.py new file mode 100644 index 00000000..e4f969de --- /dev/null +++ b/test/conftest.py @@ -0,0 +1,73 @@ +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) + +TEST_DIR = Path(__file__).parent.absolute() +Vars = namedtuple( + "Vars", + [ + "OS", + "VERSION", + "IMAGE_NAME", + "TEST_DIR", + "TAG", + "TEST_APP", + "VERY_LONG_IDENTIFIER", + ], +) +VERSION = os.getenv("VERSION") +OS = os.getenv("TARGET").lower() +TEST_APP = TEST_DIR / "test-app" +VERY_LONG_IDENTIFIER = "very_long_identifier_" + "x" * 40 +VARS = Vars( + OS=OS, + VERSION=VERSION, + IMAGE_NAME=os.getenv("IMAGE_NAME"), + TEST_DIR=TEST_DIR, + TAG=OS.replace("rh", "-", 1), + TEST_APP=TEST_APP, + VERY_LONG_IDENTIFIER=VERY_LONG_IDENTIFIER, +) + + +def get_previous_major_version(): + version_dict = { + "13": "12", + "15": "13", + "16": "15", + } + return version_dict.get(VARS.VERSION) + + +def get_upgrade_path(): + upgrade_path = { + "rhel8": "none 12 13 15 16 none", + "rhel9": "none 13 15 16 none", + "rhel10": "none 13 15 16 none", + "fedora": "none 12 13 14 15 16 none", + } + for version in upgrade_path.keys(): + if version == VARS.VERSION: + break + prev = version + if prev == "none": + return None + return prev + + +def get_image_id(version): + ns = { + "rhel8": f"registry.redhat.io/rhel8/postgresql-{version}", + "rhel9": f"registry.redhat.io/rhel9/postgresql-{version}", + "rhel10": f"registry.redhat.io/rhel10/postgresql-{version}", + "c9s": f"quay.io/sclorg/postgresql-{version}-c9s", + "c10s": f"quay.io/sclorg/postgresql-{version}-c10s", + } + return ns[VARS.OS] diff --git a/test/constants.py b/test/constants.py deleted file mode 100644 index 26eb71ae..00000000 --- a/test/constants.py +++ /dev/null @@ -1,5 +0,0 @@ -TAGS = { - "rhel8": "-el8", - "rhel9": "-el9", - "rhel10": "-el10", -} diff --git a/test/test_ocp_psql_imagestream.py b/test/test_ocp_psql_imagestream.py index 1252f405..bda37267 100644 --- a/test/test_ocp_psql_imagestream.py +++ b/test/test_ocp_psql_imagestream.py @@ -1,49 +1,29 @@ -import os -import sys - import pytest from container_ci_suite.openshift import OpenShiftAPI -from container_ci_suite.utils import check_variables - -from constants import TAGS - -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") - -TAG = TAGS.get(OS) +from conftest import VARS class TestPostgreSQLImagestreamTemplate: - def setup_method(self): - self.oc_api = OpenShiftAPI(pod_name_prefix="postgresql", version=VERSION, shared_cluster=True) + self.oc_api = OpenShiftAPI( + pod_name_prefix="postgresql", version=VARS.VERSION, shared_cluster=True + ) def teardown_method(self): self.oc_api.delete_project() @pytest.mark.parametrize( "template", - [ - "postgresql-ephemeral-template.json", - "postgresql-persistent-template.json" - ] + ["postgresql-ephemeral-template.json", "postgresql-persistent-template.json"], ) def test_psql_imagestream_template(self, template): - os_name = ''.join(i for i in OS if not i.isdigit()) - print(os.getcwd()) + os_name = "".join(i for i in VARS.OS if not i.isdigit()) assert self.oc_api.deploy_image_stream_template( imagestream_file=f"imagestreams/postgresql-{os_name}.json", template_file=f"examples/{template}", app_name=self.oc_api.pod_name_prefix, - openshift_args=[ - f"POSTGRESQL_VERSION={VERSION}{TAG}" - ] + openshift_args=[f"POSTGRESQL_VERSION={VARS.VERSION}{VARS.TAG}"], ) assert self.oc_api.is_pod_running(pod_name_prefix=self.oc_api.pod_name_prefix) diff --git a/test/test_ocp_psql_imagestream_template.py b/test/test_ocp_psql_imagestream_template.py index b45d1e00..988278b9 100644 --- a/test/test_ocp_psql_imagestream_template.py +++ b/test/test_ocp_psql_imagestream_template.py @@ -1,45 +1,28 @@ -import os -import sys - import pytest from container_ci_suite.openshift import OpenShiftAPI -from container_ci_suite.utils import check_variables - -from constants import TAGS - -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") - -TAG = TAGS.get(OS) +from conftest import VARS class TestPostgreSQLImagestreamTemplate: - def setup_method(self): - self.oc_api = OpenShiftAPI(pod_name_prefix="postgresql", version=VERSION, shared_cluster=True) + self.oc_api = OpenShiftAPI( + pod_name_prefix="postgresql", version=VARS.VERSION, shared_cluster=True + ) def teardown_method(self): self.oc_api.delete_project() @pytest.mark.parametrize( "template", - [ - "postgresql-ephemeral-template.json", - "postgresql-persistent-template.json" - ] + ["postgresql-ephemeral-template.json", "postgresql-persistent-template.json"], ) def test_psql_imagestream_template(self, template): - 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_image_stream_template( imagestream_file=f"imagestreams/postgresql-{os_name}.json", template_file=f"examples/{template}", - app_name=self.oc_api.pod_name_prefix + app_name=self.oc_api.pod_name_prefix, ) assert self.oc_api.is_pod_running(pod_name_prefix=self.oc_api.pod_name_prefix) diff --git a/test/test_ocp_psql_latest_imagestreams.py b/test/test_ocp_psql_latest_imagestreams.py index f01d442e..b357060f 100644 --- a/test/test_ocp_psql_latest_imagestreams.py +++ b/test/test_ocp_psql_latest_imagestreams.py @@ -1,26 +1,13 @@ -import os -import sys - -import pytest - -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, VERSION is missing.") - sys.exit(1) +from conftest import VARS class TestLatestImagestreams: - def setup_method(self): - self.isc = ImageStreamChecker(working_dir=TEST_DIR.parent) + self.isc = ImageStreamChecker(working_dir=VARS.TEST_DIR.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_psql_template.py b/test/test_ocp_psql_template.py index dc18cf76..5bcf73c7 100644 --- a/test/test_ocp_psql_template.py +++ b/test/test_ocp_psql_template.py @@ -1,59 +1,44 @@ -import os -import sys - import pytest from container_ci_suite.openshift import OpenShiftAPI -from container_ci_suite.utils import check_variables - -from constants import TAGS - -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") - -TAG = TAGS.get(OS) +from conftest import VARS class TestPostgreSQLDeployTemplate: - def setup_method(self): - self.oc_api = OpenShiftAPI(pod_name_prefix="postgresql-testing", version=VERSION, shared_cluster=True) + self.oc_api = OpenShiftAPI( + pod_name_prefix="postgresql-testing", + version=VARS.VERSION, + shared_cluster=True, + ) def teardown_method(self): self.oc_api.delete_project() @pytest.mark.parametrize( "template", - [ - "postgresql-ephemeral-template.json", - "postgresql-persistent-template.json" - ] + ["postgresql-ephemeral-template.json", "postgresql-persistent-template.json"], ) def test_psql_template_inside_cluster(self, template): - short_version = VERSION.replace(".", "") + short_version = VARS.VERSION.replace(".", "") assert self.oc_api.deploy_template_with_image( - image_name=IMAGE_NAME, + image_name=VARS.IMAGE_NAME, template=f"examples/{template}", name_in_template="postgresql", openshift_args=[ - f"POSTGRESQL_VERSION={VERSION}", + f"POSTGRESQL_VERSION={VARS.VERSION}", f"DATABASE_SERVICE_NAME={self.oc_api.pod_name_prefix}", - f"POSTGRESQL_USER=testu", - f"POSTGRESQL_PASSWORD=testp", - f"POSTGRESQL_DATABASE=testdb" - ] + "POSTGRESQL_USER=testu", + "POSTGRESQL_PASSWORD=testp", + "POSTGRESQL_DATABASE=testdb", + ], ) assert self.oc_api.is_pod_running(pod_name_prefix=self.oc_api.pod_name_prefix) assert self.oc_api.check_command_internal( - image_name=f"registry.redhat.io/{OS}/postgresql-{short_version}", + image_name=f"registry.redhat.io/{VARS.OS}/postgresql-{short_version}", service_name=self.oc_api.pod_name_prefix, cmd="PGPASSWORD=testp pg_isready -t 15 -h -U testu -d testdb", - expected_output="accepting connections" + expected_output="accepting connections", ) diff --git a/test/test_ocp_shared_helm_psql_imagestreams.py b/test/test_ocp_shared_helm_psql_imagestreams.py index 19d108f4..cb1b1578 100644 --- a/test/test_ocp_shared_helm_psql_imagestreams.py +++ b/test/test_ocp_shared_helm_psql_imagestreams.py @@ -1,29 +1,24 @@ -import os -import sys - import pytest -from pathlib import Path from container_ci_suite.helm import HelmChartsAPI -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) -test_dir = Path(os.path.abspath(os.path.dirname(__file__))) +from conftest import VARS class TestHelmRHELPostgresqlImageStreams: - def setup_method(self): package_name = "redhat-postgresql-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", - subdir="charts/redhat" + repo_url="https://github.com/sclorg/helm-charts", + repo_name="helm-charts", + subdir="charts/redhat", ) def teardown_method(self): @@ -45,4 +40,7 @@ def teardown_method(self): def test_package_imagestream(self, version, registry, expected): assert self.hc_api.helm_package() assert self.hc_api.helm_installation() - assert self.hc_api.check_imagestreams(version=version, registry=registry) == expected + assert ( + self.hc_api.check_imagestreams(version=version, registry=registry) + == expected + ) diff --git a/test/test_ocp_shared_helm_psql_template.py b/test/test_ocp_shared_helm_psql_template.py index 1e86cacd..1c94b834 100644 --- a/test/test_ocp_shared_helm_psql_template.py +++ b/test/test_ocp_shared_helm_psql_template.py @@ -1,38 +1,21 @@ -import os -import sys - -import pytest - -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 IMAGE_NAME, 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("TARGET") - -TAG = TAGS.get(OS) +from conftest import VARS class TestHelmPostgresqlPersistent: - def setup_method(self): package_name = "redhat-postgresql-persistent" - path = test_dir - self.hc_api = HelmChartsAPI(path=path, package_name=package_name, tarball_dir=test_dir) + 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", - subdir="charts/redhat" + repo_url="https://github.com/sclorg/helm-charts", + repo_name="helm-charts", + subdir="charts/redhat", ) def teardown_method(self): @@ -46,9 +29,11 @@ def test_package_persistent(self): assert self.hc_api.helm_package() assert self.hc_api.helm_installation( values={ - ".image.tag": f"{VERSION}{TAG}", - ".namespace": self.hc_api.namespace, + ".image.tag": f"{VARS.VERSION}{VARS.TAG}", + "namespace": self.hc_api.namespace, } ) - assert self.hc_api.is_pod_running(pod_name_prefix="redhat-postgresql-persistent") + assert self.hc_api.is_pod_running( + pod_name_prefix="redhat-postgresql-persistent" + ) assert self.hc_api.test_helm_chart(expected_str=["accepting connection"])