Skip to content

Commit 9e88500

Browse files
committed
Fixing OpenShift 4 PyTest.
Use conftest.py and VARS tuple from this. Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
1 parent 8d4f43f commit 9e88500

5 files changed

+32
-91
lines changed

test/test_ocp_mysql_imagestream.py

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +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-
if not check_variables():
11-
print("At least one variable from IMAGE_NAME, OS, VERSION is missing.")
12-
sys.exit(1)
13-
144

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

207

218
class TestMySQLImagestreamTemplate:
22-
239
def setup_method(self):
24-
self.oc_api = OpenShiftAPI(pod_name_prefix="mysql", version=VERSION, shared_cluster=True)
10+
self.oc_api = OpenShiftAPI(
11+
pod_name_prefix="mysql", version=VARS.VERSION, shared_cluster=True
12+
)
2513

2614
def teardown_method(self):
2715
self.oc_api.delete_project()
2816

2917
@pytest.mark.parametrize(
30-
"template",
31-
[
32-
"mysql-ephemeral-template.json",
33-
"mysql-persistent-template.json"
34-
]
18+
"template", ["mysql-ephemeral-template.json", "mysql-persistent-template.json"]
3519
)
3620
def test_imagestream_template(self, template):
37-
os_name = ''.join(i for i in OS if not i.isdigit())
21+
os_name = "".join(i for i in VARS.OS if not i.isdigit())
3822
assert self.oc_api.deploy_image_stream_template(
3923
imagestream_file=f"imagestreams/mysql-{os_name}.json",
4024
template_file=f"examples/{template}",
4125
app_name=self.oc_api.pod_name_prefix,
42-
openshift_args=[
43-
f"MYSQL_VERSION={VERSION}{TAG}"
44-
]
26+
openshift_args=[f"MYSQL_VERSION={VARS.VERSION}{VARS.TAG}"],
4527
)
4628
assert self.oc_api.is_pod_running(pod_name_prefix=self.oc_api.pod_name_prefix)
Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,27 @@
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-
if not check_variables():
11-
print("At least one variable from IMAGE_NAME, OS, VERSION is missing.")
12-
sys.exit(1)
13-
144

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

207

218
class TestMySQLImagestreamTemplate:
22-
239
def setup_method(self):
24-
self.oc_api = OpenShiftAPI(pod_name_prefix="mysql", version=VERSION, shared_cluster=True)
10+
self.oc_api = OpenShiftAPI(
11+
pod_name_prefix="mysql", version=VARS.VERSION, shared_cluster=True
12+
)
2513

2614
def teardown_method(self):
2715
self.oc_api.delete_project()
2816

2917
@pytest.mark.parametrize(
30-
"template",
31-
[
32-
"mysql-ephemeral-template.json",
33-
"mysql-persistent-template.json"
34-
]
18+
"template", ["mysql-ephemeral-template.json", "mysql-persistent-template.json"]
3519
)
3620
def test_imagestream_template(self, template):
37-
os_name = ''.join(i for i in OS if not i.isdigit())
21+
os_name = "".join(i for i in VARS.OS if not i.isdigit())
3822
assert self.oc_api.deploy_image_stream_template(
3923
imagestream_file=f"imagestreams/mysql-{os_name}.json",
4024
template_file=f"examples/{template}",
41-
app_name=self.oc_api.pod_name_prefix
25+
app_name=self.oc_api.pod_name_prefix,
4226
)
4327
assert self.oc_api.is_pod_running(pod_name_prefix=self.oc_api.pod_name_prefix)

test/test_ocp_mysql_latest_imagestreams.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
1-
import os
2-
import sys
3-
4-
from pathlib import Path
5-
61
from container_ci_suite.imagestreams import ImageStreamChecker
7-
from container_ci_suite.utils import check_variables
8-
9-
TEST_DIR = Path(os.path.abspath(os.path.dirname(__file__)))
102

11-
if not check_variables():
12-
print("At least one variable from IMAGE_NAME, OS, VERSION is missing.")
13-
sys.exit(1)
3+
from conftest import VARS
144

155

166
class TestLatestImagestreams:
177
def setup_method(self):
18-
self.isc = ImageStreamChecker(working_dir=TEST_DIR.parent)
8+
self.isc = ImageStreamChecker(working_dir=VARS.TEST_DIR.parent)
199

2010
def test_latest_imagestream(self):
2111
self.latest_version = self.isc.get_latest_version()

test/test_ocp_mysql_local_template.py

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,14 @@
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-
15-
16-
VERSION = os.getenv("VERSION")
17-
IMAGE_NAME = os.getenv("IMAGE_NAME")
18-
OS = os.getenv("TARGET")
19-
204

21-
TAG = TAGS.get(OS)
5+
from conftest import VARS
226

237

248
class TestMySQLDeployTemplate:
259
def setup_method(self):
2610
self.oc_api = OpenShiftAPI(
27-
pod_name_prefix="mysql-testing", version=VERSION, shared_cluster=True
11+
pod_name_prefix="mysql-testing", version=VARS.VERSION, shared_cluster=True
2812
)
2913
self.oc_api.import_is("imagestreams/mysql-rhel.json", "", skip_check=True)
3014

@@ -35,13 +19,13 @@ def teardown_method(self):
3519
"template", ["mysql-ephemeral-template.json", "mysql-persistent-template.json"]
3620
)
3721
def test_template_inside_cluster(self, template):
38-
short_version = VERSION.replace(".", "")
22+
short_version = VARS.VERSION.replace(".", "")
3923
assert self.oc_api.deploy_template_with_image(
40-
image_name=IMAGE_NAME,
24+
image_name=VARS.IMAGE_NAME,
4125
template=template,
4226
name_in_template="mysql",
4327
openshift_args=[
44-
f"MYSQL_VERSION={VERSION}{TAG}",
28+
f"MYSQL_VERSION={VARS.VERSION}{VARS.TAG}",
4529
f"DATABASE_SERVICE_NAME={self.oc_api.pod_name_prefix}",
4630
"MYSQL_USER=testu",
4731
"MYSQL_PASSWORD=testp",
@@ -51,7 +35,7 @@ def test_template_inside_cluster(self, template):
5135

5236
assert self.oc_api.is_pod_running(pod_name_prefix=self.oc_api.pod_name_prefix)
5337
assert self.oc_api.check_command_internal(
54-
image_name=f"registry.redhat.io/{OS}/mysql-{short_version}",
38+
image_name=f"registry.redhat.io/{VARS.OS}/mysql-{short_version}",
5539
service_name=self.oc_api.pod_name_prefix,
5640
cmd="echo 'SELECT 42 as testval\\g' | mysql --connect-timeout=15 -h <IP> testdb -utestu -ptestp",
5741
expected_output="42",

test/test_ocp_mysql_shared_helm_imagestreams.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
import os
2-
31
import pytest
4-
from pathlib import Path
52

63
from container_ci_suite.helm import HelmChartsAPI
74

8-
test_dir = Path(os.path.abspath(os.path.dirname(__file__)))
5+
from conftest import VARS
96

107

118
class TestHelmRHELMySQLImageStreams:
12-
139
def setup_method(self):
1410
package_name = "redhat-mysql-imagestreams"
15-
path = test_dir
16-
self.hc_api = HelmChartsAPI(path=path, package_name=package_name, tarball_dir=test_dir, shared_cluster=True)
11+
self.hc_api = HelmChartsAPI(
12+
path=VARS.TEST_DIR,
13+
package_name=package_name,
14+
tarball_dir=VARS.TEST_DIR,
15+
shared_cluster=True,
16+
)
1717
self.hc_api.clone_helm_chart_repo(
18-
repo_url="https://github.com/sclorg/helm-charts", repo_name="helm-charts",
19-
subdir="charts/redhat"
18+
repo_url="https://github.com/sclorg/helm-charts",
19+
repo_name="helm-charts",
20+
subdir="charts/redhat",
2021
)
2122

2223
def teardown_method(self):

0 commit comments

Comments
 (0)