Skip to content

Commit af6a373

Browse files
authored
Add tests written in Pytest for testing in OpenShift 4 environment (#575)
* Add tests written in Pytest for testing in OpenShift 4 environment Add test written in PyTest for testing postgresql-container in OpenShift 4 environment * Add the latest container-common-scripts --------- Signed-off-by: Petr "Stone" Hracek <[email protected]>
1 parent 9c52e6c commit af6a373

File tree

5 files changed

+196
-0
lines changed

5 files changed

+196
-0
lines changed

test/run-openshift-pytest

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
#
3+
# IMAGE_NAME specifies a name of the candidate image used for testing.
4+
# The image has to be available before this script is executed.
5+
# VERSION specifies the major version of the MariaDB in format of X.Y
6+
# OS specifies RHEL version (e.g. OS=rhel7)
7+
#
8+
9+
THISDIR=$(dirname ${BASH_SOURCE[0]})
10+
11+
git show -s
12+
13+
cd "${THISDIR}" && python3 -m pytest -s -rA --showlocals -vv test_postgresql_*.py
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import os
2+
import sys
3+
4+
import pytest
5+
6+
from container_ci_suite.openshift import OpenShiftAPI
7+
from container_ci_suite.utils import check_variables
8+
9+
if not check_variables():
10+
print("At least one variable from IMAGE_NAME, OS, SINGLE_VERSION is missing.")
11+
sys.exit(1)
12+
13+
14+
VERSION = os.getenv("SINGLE_VERSION")
15+
IMAGE_NAME = os.getenv("IMAGE_NAME")
16+
OS = os.getenv("TARGET")
17+
TAGS = {
18+
"rhel8": "-el8",
19+
"rhel9": "-el9"
20+
}
21+
TAG = TAGS.get(OS, None)
22+
23+
24+
class TestPostgreSQLImagestreamTemplate:
25+
26+
def setup_method(self):
27+
self.oc_api = OpenShiftAPI(pod_name_prefix="postgresql", version=VERSION)
28+
29+
def teardown_method(self):
30+
self.oc_api.delete_project()
31+
32+
@pytest.mark.parametrize(
33+
"template",
34+
[
35+
"postgresql-ephemeral-template.json",
36+
"postgresql-persistent-template.json"
37+
]
38+
)
39+
def test_psql_imagestream_template(self, template):
40+
os_name = ''.join(i for i in OS if not i.isdigit())
41+
print(os.getcwd())
42+
assert self.oc_api.deploy_image_stream_template(
43+
imagestream_file=f"imagestreams/postgresql-{os_name}.json",
44+
template_file=f"examples/{template}",
45+
app_name=self.oc_api.pod_name_prefix,
46+
openshift_args=[
47+
f"POSTGRESQL_VERSION={VERSION}{TAG}"
48+
]
49+
)
50+
assert self.oc_api.is_pod_running(pod_name_prefix=self.oc_api.pod_name_prefix)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import os
2+
import sys
3+
4+
import pytest
5+
6+
from container_ci_suite.openshift import OpenShiftAPI
7+
from container_ci_suite.utils import check_variables
8+
9+
if not check_variables():
10+
print("At least one variable from IMAGE_NAME, OS, SINGLE_VERSION is missing.")
11+
sys.exit(1)
12+
13+
14+
VERSION = os.getenv("SINGLE_VERSION")
15+
IMAGE_NAME = os.getenv("IMAGE_NAME")
16+
OS = os.getenv("TARGET")
17+
TAGS = {
18+
"rhel8": "-el8",
19+
"rhel9": "-el9"
20+
}
21+
TAG = TAGS.get(OS, None)
22+
23+
24+
class TestPostgreSQLImagestreamTemplate:
25+
26+
def setup_method(self):
27+
self.oc_api = OpenShiftAPI(pod_name_prefix="postgresql", version=VERSION)
28+
29+
def teardown_method(self):
30+
self.oc_api.delete_project()
31+
32+
@pytest.mark.parametrize(
33+
"template",
34+
[
35+
"postgresql-ephemeral-template.json",
36+
"postgresql-persistent-template.json"
37+
]
38+
)
39+
def test_psql_imagestream_template(self, template):
40+
os_name = ''.join(i for i in OS if not i.isdigit())
41+
assert self.oc_api.deploy_image_stream_template(
42+
imagestream_file=f"imagestreams/postgresql-{os_name}.json",
43+
template_file=f"examples/{template}",
44+
app_name=self.oc_api.pod_name_prefix
45+
)
46+
assert self.oc_api.is_pod_running(pod_name_prefix=self.oc_api.pod_name_prefix)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import os
2+
import sys
3+
4+
import pytest
5+
6+
from pathlib import Path
7+
8+
from container_ci_suite.imagestreams import ImageStreamChecker
9+
from container_ci_suite.utils import check_variables
10+
11+
TEST_DIR = Path(os.path.abspath(os.path.dirname(__file__)))
12+
13+
if not check_variables():
14+
print("At least one variable from IMAGE_NAME, OS, SINGLE_VERSION is missing.")
15+
sys.exit(1)
16+
17+
18+
class TestLatestImagestreams:
19+
20+
def setup_method(self):
21+
self.isc = ImageStreamChecker(working_dir=TEST_DIR.parent)
22+
23+
def test_latest_imagestream(self):
24+
self.latest_version = self.isc.get_latest_version()
25+
assert self.latest_version != ""
26+
self.isc.check_imagestreams(self.latest_version)

test/test_postgresql_template.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import os
2+
import sys
3+
4+
import pytest
5+
6+
from container_ci_suite.openshift import OpenShiftAPI
7+
from container_ci_suite.utils import check_variables
8+
9+
if not check_variables():
10+
print("At least one variable from IMAGE_NAME, OS, SINGLE_VERSION is missing.")
11+
sys.exit(1)
12+
13+
14+
VERSION = os.getenv("SINGLE_VERSION")
15+
IMAGE_NAME = os.getenv("IMAGE_NAME")
16+
OS = os.getenv("TARGET")
17+
18+
TAGS = {
19+
"rhel8": "-el8",
20+
"rhel9": "-el9"
21+
}
22+
TAG = TAGS.get(OS, None)
23+
24+
25+
class TestPostgreSQLDeployTemplate:
26+
27+
def setup_method(self):
28+
self.oc_api = OpenShiftAPI(pod_name_prefix="postgresql-testing", version=VERSION)
29+
30+
def teardown_method(self):
31+
self.oc_api.delete_project()
32+
33+
@pytest.mark.parametrize(
34+
"template",
35+
[
36+
"postgresql-ephemeral-template.json",
37+
"postgresql-persistent-template.json"
38+
]
39+
)
40+
def test_psql_template_inside_cluster(self, template):
41+
short_version = VERSION.replace(".", "")
42+
assert self.oc_api.deploy_template_with_image(
43+
image_name=IMAGE_NAME,
44+
template=f"examples/{template}",
45+
name_in_template="postgresql",
46+
openshift_args=[
47+
f"POSTGRESQL_VERSION={VERSION}",
48+
f"DATABASE_SERVICE_NAME={self.oc_api.pod_name_prefix}",
49+
f"POSTGRESQL_USER=testu",
50+
f"POSTGRESQL_PASSWORD=testp",
51+
f"POSTGRESQL_DATABASE=testdb"
52+
]
53+
)
54+
55+
assert self.oc_api.is_pod_running(pod_name_prefix=self.oc_api.pod_name_prefix)
56+
assert self.oc_api.check_command_internal(
57+
image_name=f"registry.redhat.io/{OS}/postgresql-{short_version}",
58+
service_name=self.oc_api.pod_name_prefix,
59+
cmd="PGPASSWORD=testp pg_isready -t 15 -h <IP> -U testu -d testdb",
60+
expected_output="accepting connections"
61+
)

0 commit comments

Comments
 (0)