Skip to content

Commit 88cdbf2

Browse files
committed
Rename constanst.py to conftest.py
Update also OpenShift part Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
1 parent 4a217f9 commit 88cdbf2

8 files changed

Lines changed: 135 additions & 149 deletions

test/conftest.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import os
2+
import sys
3+
4+
from pathlib import Path
5+
from collections import namedtuple
6+
7+
from container_ci_suite.utils import check_variables
8+
9+
if not check_variables():
10+
sys.exit(1)
11+
12+
TEST_DIR = Path(__file__).parent.absolute()
13+
Vars = namedtuple(
14+
"Vars",
15+
[
16+
"OS",
17+
"VERSION",
18+
"IMAGE_NAME",
19+
"TEST_DIR",
20+
"TAG",
21+
"TEST_APP",
22+
"VERY_LONG_IDENTIFIER",
23+
],
24+
)
25+
VERSION = os.getenv("VERSION")
26+
OS = os.getenv("TARGET").lower()
27+
TEST_APP = TEST_DIR / "test-app"
28+
VERY_LONG_IDENTIFIER = "very_long_identifier_" + "x" * 40
29+
VARS = Vars(
30+
OS=OS,
31+
VERSION=VERSION,
32+
IMAGE_NAME=os.getenv("IMAGE_NAME"),
33+
TEST_DIR=TEST_DIR,
34+
TAG=OS.replace("rh", "-", 1),
35+
TEST_APP=TEST_APP,
36+
VERY_LONG_IDENTIFIER=VERY_LONG_IDENTIFIER,
37+
)
38+
39+
40+
def get_previous_major_version():
41+
version_dict = {
42+
"13": "12",
43+
"15": "13",
44+
"16": "15",
45+
}
46+
return version_dict.get(VARS.VERSION)
47+
48+
49+
def get_upgrade_path():
50+
upgrade_path = {
51+
"rhel8": "none 12 13 15 16 none",
52+
"rhel9": "none 13 15 16 none",
53+
"rhel10": "none 13 15 16 none",
54+
"fedora": "none 12 13 14 15 16 none",
55+
}
56+
for version in upgrade_path.keys():
57+
if version == VARS.VERSION:
58+
break
59+
prev = version
60+
if prev == "none":
61+
return None
62+
return prev
63+
64+
65+
def get_image_id(version):
66+
ns = {
67+
"rhel8": f"registry.redhat.io/rhel8/postgresql-{version}",
68+
"rhel9": f"registry.redhat.io/rhel9/postgresql-{version}",
69+
"rhel10": f"registry.redhat.io/rhel10/postgresql-{version}",
70+
"c9s": f"quay.io/sclorg/postgresql-{version}-c9s",
71+
"c10s": f"quay.io/sclorg/postgresql-{version}-c10s",
72+
}
73+
return ns[VARS.OS]

test/constants.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/test_ocp_psql_imagestream.py

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,29 @@
1-
import os
2-
import sys
3-
41
import pytest
52

63
from container_ci_suite.openshift import OpenShiftAPI
7-
from container_ci_suite.utils import check_variables
8-
9-
from constants import TAGS
10-
11-
if not check_variables():
12-
print("At least one variable from IMAGE_NAME, OS, VERSION is missing.")
13-
sys.exit(1)
14-
154

16-
VERSION = os.getenv("VERSION")
17-
IMAGE_NAME = os.getenv("IMAGE_NAME")
18-
OS = os.getenv("TARGET")
19-
20-
TAG = TAGS.get(OS)
5+
from conftest import VARS
216

227

238
class TestPostgreSQLImagestreamTemplate:
24-
259
def setup_method(self):
26-
self.oc_api = OpenShiftAPI(pod_name_prefix="postgresql", version=VERSION, shared_cluster=True)
10+
self.oc_api = OpenShiftAPI(
11+
pod_name_prefix="postgresql", version=VARS.VERSION, shared_cluster=True
12+
)
2713

2814
def teardown_method(self):
2915
self.oc_api.delete_project()
3016

3117
@pytest.mark.parametrize(
3218
"template",
33-
[
34-
"postgresql-ephemeral-template.json",
35-
"postgresql-persistent-template.json"
36-
]
19+
["postgresql-ephemeral-template.json", "postgresql-persistent-template.json"],
3720
)
3821
def test_psql_imagestream_template(self, template):
39-
os_name = ''.join(i for i in OS if not i.isdigit())
40-
print(os.getcwd())
22+
os_name = "".join(i for i in VARS.OS if not i.isdigit())
4123
assert self.oc_api.deploy_image_stream_template(
4224
imagestream_file=f"imagestreams/postgresql-{os_name}.json",
4325
template_file=f"examples/{template}",
4426
app_name=self.oc_api.pod_name_prefix,
45-
openshift_args=[
46-
f"POSTGRESQL_VERSION={VERSION}{TAG}"
47-
]
27+
openshift_args=[f"POSTGRESQL_VERSION={VARS.VERSION}{VARS.TAG}"],
4828
)
4929
assert self.oc_api.is_pod_running(pod_name_prefix=self.oc_api.pod_name_prefix)
Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,28 @@
1-
import os
2-
import sys
3-
41
import pytest
52

63
from container_ci_suite.openshift import OpenShiftAPI
7-
from container_ci_suite.utils import check_variables
8-
9-
from constants import TAGS
10-
11-
if not check_variables():
12-
print("At least one variable from IMAGE_NAME, OS, VERSION is missing.")
13-
sys.exit(1)
14-
154

16-
VERSION = os.getenv("VERSION")
17-
IMAGE_NAME = os.getenv("IMAGE_NAME")
18-
OS = os.getenv("TARGET")
19-
20-
TAG = TAGS.get(OS)
5+
from conftest import VARS
216

227

238
class TestPostgreSQLImagestreamTemplate:
24-
259
def setup_method(self):
26-
self.oc_api = OpenShiftAPI(pod_name_prefix="postgresql", version=VERSION, shared_cluster=True)
10+
self.oc_api = OpenShiftAPI(
11+
pod_name_prefix="postgresql", version=VARS.VERSION, shared_cluster=True
12+
)
2713

2814
def teardown_method(self):
2915
self.oc_api.delete_project()
3016

3117
@pytest.mark.parametrize(
3218
"template",
33-
[
34-
"postgresql-ephemeral-template.json",
35-
"postgresql-persistent-template.json"
36-
]
19+
["postgresql-ephemeral-template.json", "postgresql-persistent-template.json"],
3720
)
3821
def test_psql_imagestream_template(self, template):
39-
os_name = ''.join(i for i in OS if not i.isdigit())
22+
os_name = "".join(i for i in VARS.OS if not i.isdigit())
4023
assert self.oc_api.deploy_image_stream_template(
4124
imagestream_file=f"imagestreams/postgresql-{os_name}.json",
4225
template_file=f"examples/{template}",
43-
app_name=self.oc_api.pod_name_prefix
26+
app_name=self.oc_api.pod_name_prefix,
4427
)
4528
assert self.oc_api.is_pod_running(pod_name_prefix=self.oc_api.pod_name_prefix)
Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
1-
import os
2-
import sys
3-
4-
import pytest
5-
6-
from pathlib import Path
7-
81
from container_ci_suite.imagestreams import ImageStreamChecker
9-
from container_ci_suite.utils import check_variables
102

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, VERSION is missing.")
15-
sys.exit(1)
3+
from conftest import VARS
164

175

186
class TestLatestImagestreams:
19-
207
def setup_method(self):
21-
self.isc = ImageStreamChecker(working_dir=TEST_DIR.parent)
8+
self.isc = ImageStreamChecker(working_dir=VARS.TEST_DIR.parent)
229

2310
def test_latest_imagestream(self):
2411
self.latest_version = self.isc.get_latest_version()
25-
assert self.latest_version != ""
12+
assert self.latest_version
2613
self.isc.check_imagestreams(self.latest_version)

test/test_ocp_psql_template.py

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,44 @@
1-
import os
2-
import sys
3-
41
import pytest
52

63
from container_ci_suite.openshift import OpenShiftAPI
7-
from container_ci_suite.utils import check_variables
8-
9-
from constants import TAGS
10-
11-
if not check_variables():
12-
print("At least one variable from IMAGE_NAME, OS, VERSION is missing.")
13-
sys.exit(1)
14-
154

16-
VERSION = os.getenv("VERSION")
17-
IMAGE_NAME = os.getenv("IMAGE_NAME")
18-
OS = os.getenv("TARGET")
19-
20-
TAG = TAGS.get(OS)
5+
from conftest import VARS
216

227

238
class TestPostgreSQLDeployTemplate:
24-
259
def setup_method(self):
26-
self.oc_api = OpenShiftAPI(pod_name_prefix="postgresql-testing", version=VERSION, shared_cluster=True)
10+
self.oc_api = OpenShiftAPI(
11+
pod_name_prefix="postgresql-testing",
12+
version=VARS.VERSION,
13+
shared_cluster=True,
14+
)
2715

2816
def teardown_method(self):
2917
self.oc_api.delete_project()
3018

3119
@pytest.mark.parametrize(
3220
"template",
33-
[
34-
"postgresql-ephemeral-template.json",
35-
"postgresql-persistent-template.json"
36-
]
21+
["postgresql-ephemeral-template.json", "postgresql-persistent-template.json"],
3722
)
3823
def test_psql_template_inside_cluster(self, template):
39-
short_version = VERSION.replace(".", "")
24+
short_version = VARS.VERSION.replace(".", "")
4025
assert self.oc_api.deploy_template_with_image(
41-
image_name=IMAGE_NAME,
26+
image_name=VARS.IMAGE_NAME,
4227
template=f"examples/{template}",
4328
name_in_template="postgresql",
4429
openshift_args=[
45-
f"POSTGRESQL_VERSION={VERSION}",
30+
f"POSTGRESQL_VERSION={VARS.VERSION}",
4631
f"DATABASE_SERVICE_NAME={self.oc_api.pod_name_prefix}",
47-
f"POSTGRESQL_USER=testu",
48-
f"POSTGRESQL_PASSWORD=testp",
49-
f"POSTGRESQL_DATABASE=testdb"
50-
]
32+
"POSTGRESQL_USER=testu",
33+
"POSTGRESQL_PASSWORD=testp",
34+
"POSTGRESQL_DATABASE=testdb",
35+
],
5136
)
5237

5338
assert self.oc_api.is_pod_running(pod_name_prefix=self.oc_api.pod_name_prefix)
5439
assert self.oc_api.check_command_internal(
55-
image_name=f"registry.redhat.io/{OS}/postgresql-{short_version}",
40+
image_name=f"registry.redhat.io/{VARS.OS}/postgresql-{short_version}",
5641
service_name=self.oc_api.pod_name_prefix,
5742
cmd="PGPASSWORD=testp pg_isready -t 15 -h <IP> -U testu -d testdb",
58-
expected_output="accepting connections"
43+
expected_output="accepting connections",
5944
)
Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
1-
import os
2-
import sys
3-
41
import pytest
52

6-
from pathlib import Path
73

84
from container_ci_suite.helm import HelmChartsAPI
9-
from container_ci_suite.utils import check_variables
10-
11-
if not check_variables():
12-
print("At least one variable from IMAGE_NAME, OS, VERSION is missing.")
13-
sys.exit(1)
145

15-
test_dir = Path(os.path.abspath(os.path.dirname(__file__)))
6+
from conftest import VARS
167

178

189
class TestHelmRHELPostgresqlImageStreams:
19-
2010
def setup_method(self):
2111
package_name = "redhat-postgresql-imagestreams"
22-
path = test_dir
23-
self.hc_api = HelmChartsAPI(path=path, package_name=package_name, tarball_dir=test_dir, shared_cluster=True)
12+
self.hc_api = HelmChartsAPI(
13+
path=VARS.TEST_DIR,
14+
package_name=package_name,
15+
tarball_dir=VARS.TEST_DIR,
16+
shared_cluster=True,
17+
)
2418
self.hc_api.clone_helm_chart_repo(
25-
repo_url="https://github.com/sclorg/helm-charts", repo_name="helm-charts",
26-
subdir="charts/redhat"
19+
repo_url="https://github.com/sclorg/helm-charts",
20+
repo_name="helm-charts",
21+
subdir="charts/redhat",
2722
)
2823

2924
def teardown_method(self):
@@ -45,4 +40,7 @@ def teardown_method(self):
4540
def test_package_imagestream(self, version, registry, expected):
4641
assert self.hc_api.helm_package()
4742
assert self.hc_api.helm_installation()
48-
assert self.hc_api.check_imagestreams(version=version, registry=registry) == expected
43+
assert (
44+
self.hc_api.check_imagestreams(version=version, registry=registry)
45+
== expected
46+
)

0 commit comments

Comments
 (0)