diff --git a/test/run-openshift-pytest b/test/run-openshift-pytest new file mode 100755 index 00000000..bd49496e --- /dev/null +++ b/test/run-openshift-pytest @@ -0,0 +1,13 @@ +#!/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. +# VERSION specifies the major version of the MariaDB in format of X.Y +# OS specifies RHEL version (e.g. OS=rhel7) +# + +THISDIR=$(dirname ${BASH_SOURCE[0]}) + +git show -s + +cd "${THISDIR}" && python3 -m pytest -s -rA --showlocals -vv test_postgresql_*.py diff --git a/test/test_postgresql_imagestream.py b/test/test_postgresql_imagestream.py new file mode 100644 index 00000000..b81c4d28 --- /dev/null +++ b/test/test_postgresql_imagestream.py @@ -0,0 +1,50 @@ +import os +import sys + +import pytest + +from container_ci_suite.openshift import OpenShiftAPI +from container_ci_suite.utils import check_variables + +if not check_variables(): + print("At least one variable from IMAGE_NAME, OS, SINGLE_VERSION is missing.") + sys.exit(1) + + +VERSION = os.getenv("SINGLE_VERSION") +IMAGE_NAME = os.getenv("IMAGE_NAME") +OS = os.getenv("TARGET") +TAGS = { + "rhel8": "-el8", + "rhel9": "-el9" +} +TAG = TAGS.get(OS, None) + + +class TestPostgreSQLImagestreamTemplate: + + def setup_method(self): + self.oc_api = OpenShiftAPI(pod_name_prefix="postgresql", version=VERSION) + + def teardown_method(self): + self.oc_api.delete_project() + + @pytest.mark.parametrize( + "template", + [ + "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()) + 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}" + ] + ) + assert self.oc_api.is_pod_running(pod_name_prefix=self.oc_api.pod_name_prefix) diff --git a/test/test_postgresql_imagestream_template.py b/test/test_postgresql_imagestream_template.py new file mode 100644 index 00000000..65323c6b --- /dev/null +++ b/test/test_postgresql_imagestream_template.py @@ -0,0 +1,46 @@ +import os +import sys + +import pytest + +from container_ci_suite.openshift import OpenShiftAPI +from container_ci_suite.utils import check_variables + +if not check_variables(): + print("At least one variable from IMAGE_NAME, OS, SINGLE_VERSION is missing.") + sys.exit(1) + + +VERSION = os.getenv("SINGLE_VERSION") +IMAGE_NAME = os.getenv("IMAGE_NAME") +OS = os.getenv("TARGET") +TAGS = { + "rhel8": "-el8", + "rhel9": "-el9" +} +TAG = TAGS.get(OS, None) + + +class TestPostgreSQLImagestreamTemplate: + + def setup_method(self): + self.oc_api = OpenShiftAPI(pod_name_prefix="postgresql", version=VERSION) + + def teardown_method(self): + self.oc_api.delete_project() + + @pytest.mark.parametrize( + "template", + [ + "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()) + 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 + ) + assert self.oc_api.is_pod_running(pod_name_prefix=self.oc_api.pod_name_prefix) diff --git a/test/test_postgresql_latest_imagestreams.py b/test/test_postgresql_latest_imagestreams.py new file mode 100644 index 00000000..a8140cf3 --- /dev/null +++ b/test/test_postgresql_latest_imagestreams.py @@ -0,0 +1,26 @@ +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, SINGLE_VERSION is missing.") + sys.exit(1) + + +class TestLatestImagestreams: + + def setup_method(self): + self.isc = ImageStreamChecker(working_dir=TEST_DIR.parent) + + def test_latest_imagestream(self): + self.latest_version = self.isc.get_latest_version() + assert self.latest_version != "" + self.isc.check_imagestreams(self.latest_version) diff --git a/test/test_postgresql_template.py b/test/test_postgresql_template.py new file mode 100644 index 00000000..516e5d00 --- /dev/null +++ b/test/test_postgresql_template.py @@ -0,0 +1,61 @@ +import os +import sys + +import pytest + +from container_ci_suite.openshift import OpenShiftAPI +from container_ci_suite.utils import check_variables + +if not check_variables(): + print("At least one variable from IMAGE_NAME, OS, SINGLE_VERSION is missing.") + sys.exit(1) + + +VERSION = os.getenv("SINGLE_VERSION") +IMAGE_NAME = os.getenv("IMAGE_NAME") +OS = os.getenv("TARGET") + +TAGS = { + "rhel8": "-el8", + "rhel9": "-el9" +} +TAG = TAGS.get(OS, None) + + +class TestPostgreSQLDeployTemplate: + + def setup_method(self): + self.oc_api = OpenShiftAPI(pod_name_prefix="postgresql-testing", version=VERSION) + + def teardown_method(self): + self.oc_api.delete_project() + + @pytest.mark.parametrize( + "template", + [ + "postgresql-ephemeral-template.json", + "postgresql-persistent-template.json" + ] + ) + def test_psql_template_inside_cluster(self, template): + short_version = VERSION.replace(".", "") + assert self.oc_api.deploy_template_with_image( + image_name=IMAGE_NAME, + template=f"examples/{template}", + name_in_template="postgresql", + openshift_args=[ + f"POSTGRESQL_VERSION={VERSION}", + f"DATABASE_SERVICE_NAME={self.oc_api.pod_name_prefix}", + f"POSTGRESQL_USER=testu", + f"POSTGRESQL_PASSWORD=testp", + f"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}", + service_name=self.oc_api.pod_name_prefix, + cmd="PGPASSWORD=testp pg_isready -t 15 -h -U testu -d testdb", + expected_output="accepting connections" + )