Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
73 changes: 73 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -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]
5 changes: 0 additions & 5 deletions test/constants.py

This file was deleted.

34 changes: 7 additions & 27 deletions test/test_ocp_psql_imagestream.py
Original file line number Diff line number Diff line change
@@ -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)
31 changes: 7 additions & 24 deletions test/test_ocp_psql_imagestream_template.py
Original file line number Diff line number Diff line change
@@ -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)
19 changes: 3 additions & 16 deletions test/test_ocp_psql_latest_imagestreams.py
Original file line number Diff line number Diff line change
@@ -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)
47 changes: 16 additions & 31 deletions test/test_ocp_psql_template.py
Original file line number Diff line number Diff line change
@@ -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 <IP> -U testu -d testdb",
expected_output="accepting connections"
expected_output="accepting connections",
)
30 changes: 14 additions & 16 deletions test/test_ocp_shared_helm_psql_imagestreams.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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
)
Loading
Loading