Skip to content

Commit e68a3cc

Browse files
committed
Fix OpenShift 4 PyTest and add missing docstring.
Do not run FIPS tests on RHEL8 Signed-off-by: Petr "Stone" Hracek <[email protected]>
1 parent 21776e9 commit e68a3cc

10 files changed

+207
-222
lines changed

test/conftest.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
from container_ci_suite.utils import check_variables
1010

11-
11+
PSQL_TAGS = {
12+
"rhel8": "-el8",
13+
"rhel9": "-el9",
14+
"rhel10": "-el10",
15+
}
1216
if not check_variables():
1317
sys.exit(1)
1418

@@ -17,7 +21,6 @@
1721
"rhel9": "-ubi9",
1822
"rhel10": "-ubi10",
1923
}
20-
BRANCH_TO_TEST = "master"
2124
Vars = namedtuple(
2225
"Vars",
2326
[
@@ -28,10 +31,16 @@
2831
"SHORT_VERSION",
2932
"TEST_DIR",
3033
"BRANCH_TO_TEST",
34+
"PSQL_TAG",
35+
"PSQL_IMAGE_SHORT",
36+
"PSQL_IMAGE_TAG",
3137
],
3238
)
3339
OS = os.getenv("TARGET").lower()
3440
VERSION = os.getenv("VERSION")
41+
PSQL_TAG = PSQL_TAGS.get(OS)
42+
PSQL_IMAGE_SHORT = f"postgresql:12{PSQL_TAG}"
43+
PSQL_IMAGE_TAG = f"12{PSQL_TAG}"
3544
BRANCH_TO_TEST = "master"
3645
if VERSION == "3.1" or VERSION == "3.3":
3746
BRANCH_TO_TEST = "3.3"
@@ -44,6 +53,9 @@
4453
SHORT_VERSION=VERSION.replace(".", ""),
4554
TEST_DIR=Path(__file__).parent.absolute(),
4655
BRANCH_TO_TEST=BRANCH_TO_TEST,
56+
PSQL_TAG=PSQL_TAGS.get(OS),
57+
PSQL_IMAGE_SHORT=PSQL_IMAGE_SHORT,
58+
PSQL_IMAGE_TAG=PSQL_IMAGE_TAG,
4759
)
4860

4961

test/test_container_fips.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def test_fips_mode(self):
4545
Test if container works under specific user
4646
and not only with user --user 10001
4747
"""
48+
skip_fips_tests_rhel8()
4849
print(f"Is FIPS enabled? {fips_enabled()}")
4950
if fips_enabled():
5051
output = PodmanCLIWrapper.podman_run_command_and_remove(
Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,24 @@
1-
import os
2-
import sys
3-
41
import pytest
52

6-
from pathlib import Path
7-
83
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)
14-
15-
16-
test_dir = Path(os.path.abspath(os.path.dirname(__file__)))
174

18-
19-
VERSION = os.getenv("VERSION")
20-
IMAGE_NAME = os.getenv("IMAGE_NAME")
21-
OS = os.getenv("TARGET")
5+
from conftest import VARS
226

237

248
class TestHelmRHELRubyImageStreams:
25-
269
def setup_method(self):
2710
package_name = "redhat-ruby-imagestreams"
28-
path = test_dir
29-
self.hc_api = HelmChartsAPI(path=path, package_name=package_name, tarball_dir=test_dir, shared_cluster=True)
11+
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+
)
3018
self.hc_api.clone_helm_chart_repo(
31-
repo_url="https://github.com/sclorg/helm-charts", repo_name="helm-charts",
32-
subdir="charts/redhat"
19+
repo_url="https://github.com/sclorg/helm-charts",
20+
repo_name="helm-charts",
21+
subdir="charts/redhat",
3322
)
3423

3524
def teardown_method(self):
@@ -49,6 +38,12 @@ def teardown_method(self):
4938
],
5039
)
5140
def test_package_imagestream(self, version, registry, expected):
41+
"""
42+
Test checks if Helm imagestreams are present
43+
"""
5244
assert self.hc_api.helm_package()
5345
assert self.hc_api.helm_installation()
54-
assert self.hc_api.check_imagestreams(version=version, registry=registry) == expected
46+
assert (
47+
self.hc_api.check_imagestreams(version=version, registry=registry)
48+
== expected
49+
)
Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,55 @@
1-
import os
2-
import sys
3-
4-
import pytest
5-
6-
from pathlib import Path
7-
81
from container_ci_suite.helm import HelmChartsAPI
9-
from container_ci_suite.utils import check_variables
10-
11-
from constants import TAGS
12-
13-
if not check_variables():
14-
print("At least one variable from IMAGE_NAME, OS, VERSION is missing.")
15-
sys.exit(1)
16-
172

18-
test_dir = Path(os.path.abspath(os.path.dirname(__file__)))
19-
20-
21-
VERSION = os.getenv("VERSION")
22-
IMAGE_NAME = os.getenv("IMAGE_NAME")
23-
OS = os.getenv("TARGET")
24-
25-
26-
TAG = TAGS.get(OS)
3+
from conftest import VARS
274

285

296
class TestHelmCakePHPTemplate:
7+
"""
8+
Test checks if Helm imagestream and Helm ruby rails application
9+
works properly and response is as expected.
10+
"""
3011

3112
def setup_method(self):
13+
"""
14+
Setup the test environment.
15+
"""
3216
package_name = "redhat-ruby-rails-application"
33-
path = test_dir
34-
self.hc_api = HelmChartsAPI(path=path, package_name=package_name, tarball_dir=test_dir, shared_cluster=True)
17+
self.hc_api = HelmChartsAPI(
18+
path=VARS.TEST_DIR,
19+
package_name=package_name,
20+
tarball_dir=VARS.TEST_DIR,
21+
shared_cluster=True,
22+
)
3523
self.hc_api.clone_helm_chart_repo(
36-
repo_url="https://github.com/sclorg/helm-charts", repo_name="helm-charts",
37-
subdir="charts/redhat"
24+
repo_url="https://github.com/sclorg/helm-charts",
25+
repo_name="helm-charts",
26+
subdir="charts/redhat",
3827
)
3928

4029
def teardown_method(self):
30+
"""
31+
Teardown the test environment.
32+
"""
4133
self.hc_api.delete_project()
4234

4335
def test_by_helm_test(self):
44-
rails_ex_branch = "master"
45-
if VERSION == "3.3":
46-
rails_ex_branch = VERSION
36+
"""
37+
Test checks if Helm imagestream and Helm ruby rails application
38+
works properly and response is as expected.
39+
"""
4740
self.hc_api.package_name = "redhat-ruby-imagestreams"
4841
assert self.hc_api.helm_package()
4942
assert self.hc_api.helm_installation()
5043
self.hc_api.package_name = "redhat-ruby-rails-application"
5144
assert self.hc_api.helm_package()
5245
assert self.hc_api.helm_installation(
5346
values={
54-
"ruby_version": f"{VERSION}{TAG}",
47+
"ruby_version": f"{VARS.VERSION}{VARS.TAG}",
5548
"namespace": self.hc_api.namespace,
56-
"source_repository_ref": rails_ex_branch,
49+
"source_repository_ref": VARS.BRANCH_TO_TEST,
5750
}
5851
)
5952
assert self.hc_api.is_s2i_pod_running(pod_name_prefix="rails-example")
60-
assert self.hc_api.test_helm_chart(expected_str=["Welcome to your Rails application"])
53+
assert self.hc_api.test_helm_chart(
54+
expected_str=["Welcome to your Rails application"]
55+
)
Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,40 @@
1-
import os
2-
import sys
3-
4-
import pytest
5-
6-
from container_ci_suite.utils import check_variables
71
from container_ci_suite.openshift import OpenShiftAPI
82

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

14-
VERSION = os.getenv("VERSION")
15-
IMAGE_NAME = os.getenv("IMAGE_NAME")
16-
OS = os.getenv("TARGET")
175

18-
SHORT_VERSION = "".join(VERSION.split("."))
19-
20-
# Replacement with 'test_python_s2i_app_ex'
216
class TestS2IRailsExTemplate:
7+
"""
8+
Test checks if Ruby ex standalone template works properly and response is as expected.
9+
"""
2210

2311
def setup_method(self):
24-
self.oc_api = OpenShiftAPI(pod_name_prefix=f"ruby-{SHORT_VERSION}-testing", version=VERSION)
12+
"""
13+
Setup the test environment.
14+
"""
15+
self.oc_api = OpenShiftAPI(
16+
pod_name_prefix=f"ruby-{VARS.SHORT_VERSION}-testing", version=VARS.VERSION
17+
)
2518

2619
def teardown_method(self):
20+
"""
21+
Teardown the test environment.
22+
"""
2723
self.oc_api.delete_project()
2824

2925
def test_dancer_ex_template_inside_cluster(self):
30-
service_name = f"ruby-{SHORT_VERSION}-testing"
31-
rails_ex_branch = "master"
32-
if VERSION == "3.3":
33-
rails_ex_branch = VERSION
26+
"""
27+
Test checks if Ruby ex standalone template works properly and response is as expected.
28+
"""
29+
service_name = f"ruby-{VARS.SHORT_VERSION}-testing"
3430
assert self.oc_api.deploy_s2i_app(
35-
image_name=IMAGE_NAME, app=f"https://github.com/sclorg/rails-ex#{rails_ex_branch}",
31+
image_name=VARS.IMAGE_NAME,
32+
app=f"https://github.com/sclorg/rails-ex#{VARS.BRANCH_TO_TEST}",
3633
context=".",
37-
service_name=service_name
34+
service_name=service_name,
3835
)
3936
assert self.oc_api.is_template_deployed(name_in_template=service_name)
4037
assert self.oc_api.check_response_inside_cluster(
41-
name_in_template=service_name, expected_output="Welcome to your Rails application"
38+
name_in_template=service_name,
39+
expected_output="Welcome to your Rails application",
4240
)
Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
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__)))
10-
11-
if not check_variables():
12-
print("At least one variable from IMAGE_NAME, OS, VERSION is missing.")
13-
sys.exit(1)
142

15-
VERSION = os.getenv("VERSION")
3+
from conftest import VARS
164

175

18-
# Replacement with 'test_latest_imagestreams'
196
class TestLatestImagestreams:
7+
"""
8+
Test checks if local imagestreams are the latest one
9+
"""
2010

2111
def setup_method(self):
22-
self.isc = ImageStreamChecker(working_dir=TEST_DIR.parent.parent)
12+
"""
13+
Setup the test environment.
14+
"""
15+
self.isc = ImageStreamChecker(working_dir=VARS.TEST_DIR.parent.parent)
2316

2417
def test_latest_imagestream(self):
18+
"""
19+
Test checks if local imagestreams are the latest one
20+
"""
2521
self.latest_version = self.isc.get_latest_version()
26-
assert self.latest_version != ""
22+
assert self.latest_version
2723
self.isc.check_imagestreams(self.latest_version)

test/test_ocp_s2i_imagestreams.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
1-
import os
2-
import sys
3-
4-
import pytest
5-
61
from container_ci_suite.openshift import OpenShiftAPI
7-
from container_ci_suite.utils import check_variables
8-
9-
10-
if not check_variables():
11-
print("At least one variable from IMAGE_NAME, OS, VERSION is missing.")
12-
sys.exit(1)
132

14-
15-
VERSION = os.getenv("VERSION")
16-
IMAGE_NAME = os.getenv("IMAGE_NAME")
17-
OS = os.getenv("OS")
18-
19-
SHORT_VERSION = "".join(VERSION.split("."))
3+
from conftest import VARS
204

215

226
class TestRubyImagestreams:
7+
"""
8+
Test checks if Ruby imagestreams work properly
9+
"""
2310

2411
def setup_method(self):
25-
self.oc_api = OpenShiftAPI(pod_name_prefix=f"ruby-{SHORT_VERSION}-testing", version=VERSION, shared_cluster=True)
12+
"""
13+
Setup the test environment.
14+
"""
15+
self.oc_api = OpenShiftAPI(
16+
pod_name_prefix=f"ruby-{VARS.SHORT_VERSION}-testing",
17+
version=VARS.VERSION,
18+
shared_cluster=True,
19+
)
2620

2721
def teardown_method(self):
22+
"""
23+
Teardown the test environment.
24+
"""
2825
self.oc_api.delete_project()
2926

3027
def ruby_deploy_imagestream(self):
31-
service_name = f"ruby-{SHORT_VERSION}-testing"
28+
"""
29+
Test checks if Ruby imagestreams work properly
30+
"""
31+
service_name = f"ruby-{VARS.SHORT_VERSION}-testing"
3232
assert self.oc_api.deploy_imagestream_s2i(
33-
imagestream_file=f"{VERSION}/imagestreams/ruby-rhel.json",
34-
image_name=IMAGE_NAME,
33+
imagestream_file=f"{VARS.VERSION}/imagestreams/ruby-rhel.json",
34+
image_name=VARS.IMAGE_NAME,
3535
app="https://github.com/sclorg/s2i-ruby-container.git",
36-
context=f"{VERSION}/test/puma-test-app"
36+
context=f"{VARS.VERSION}/test/puma-test-app",
37+
service_name=service_name,
3738
)
3839
assert self.oc_api.is_template_deployed(name_in_template=service_name)
3940
assert self.oc_api.check_response_inside_cluster(

0 commit comments

Comments
 (0)