-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add suite for testing mariadb-container in OpenSHift4 (#246)
* Add GitHub Action for Pytest * Add suite for testing mariadb-container in OpenSHift4 by pytest * Add more outputs to PyTest module * Add tags into template * Import mariadb imagestreams for mariadb template Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
- Loading branch information
Showing
5 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
# | ||
# IMAGE_NAME specifies a name of the candidate image used for testing. | ||
# The image has to be available before this script is executed. | ||
# VERSION specifies the major version of the MariaDB in format of X.Y | ||
# OS specifies RHEL version (e.g. OS=rhel7) | ||
# | ||
|
||
THISDIR=$(dirname ${BASH_SOURCE[0]}) | ||
|
||
git show -s | ||
|
||
cd "${THISDIR}" && python3 -m pytest -s -rxfapP --showlocals -vv test_mariadb_*.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import os | ||
import sys | ||
|
||
import pytest | ||
|
||
from container_ci_suite.openshift import OpenShiftAPI | ||
from container_ci_suite.utils import check_variables | ||
|
||
if not check_variables(): | ||
print("At least one variable from IMAGE_NAME, OS, SINGLE_VERSION is missing.") | ||
sys.exit(1) | ||
|
||
|
||
VERSION = os.getenv("SINGLE_VERSION") | ||
IMAGE_NAME = os.getenv("IMAGE_NAME") | ||
OS = os.getenv("TARGET") | ||
TAGS = { | ||
"rhel8": "-el8", | ||
"rhel9": "-el9" | ||
} | ||
TAG = TAGS.get(OS, None) | ||
|
||
|
||
class TestMariaDBImagestreamTemplate: | ||
|
||
def setup_method(self): | ||
self.oc_api = OpenShiftAPI(pod_name_prefix="mariadb", version=VERSION) | ||
|
||
def teardown_method(self): | ||
self.oc_api.delete_project() | ||
|
||
@pytest.mark.parametrize( | ||
"template", | ||
[ | ||
"mariadb-ephemeral-template.json", | ||
"mariadb-persistent-template.json" | ||
] | ||
) | ||
def test_mariadb_imagestream_template(self, template): | ||
os_name = ''.join(i for i in OS if not i.isdigit()) | ||
print(os.getcwd()) | ||
assert self.oc_api.deploy_image_stream_template( | ||
imagestream_file=f"imagestreams/mariadb-{os_name}.json", | ||
template_file=f"examples/{template}", | ||
app_name=self.oc_api.pod_name_prefix, | ||
openshift_args=[ | ||
f"MARIADB_VERSION={VERSION}{TAG}" | ||
] | ||
) | ||
assert self.oc_api.is_pod_running(pod_name_prefix=self.oc_api.pod_name_prefix) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import os | ||
import sys | ||
|
||
import pytest | ||
|
||
from container_ci_suite.openshift import OpenShiftAPI | ||
from container_ci_suite.utils import check_variables | ||
|
||
if not check_variables(): | ||
print("At least one variable from IMAGE_NAME, OS, SINGLE_VERSION is missing.") | ||
sys.exit(1) | ||
|
||
|
||
VERSION = os.getenv("SINGLE_VERSION") | ||
IMAGE_NAME = os.getenv("IMAGE_NAME") | ||
OS = os.getenv("TARGET") | ||
TAGS = { | ||
"rhel8": "-el8", | ||
"rhel9": "-el9" | ||
} | ||
TAG = TAGS.get(OS, None) | ||
|
||
|
||
class TestMariaDBImagestreamTemplate: | ||
|
||
def setup_method(self): | ||
self.oc_api = OpenShiftAPI(pod_name_prefix="mariadb", version=VERSION) | ||
|
||
def teardown_method(self): | ||
self.oc_api.delete_project() | ||
|
||
@pytest.mark.parametrize( | ||
"template", | ||
[ | ||
"mariadb-ephemeral-template.json", | ||
"mariadb-persistent-template.json" | ||
] | ||
) | ||
def test_mariadb_imagestream_template(self, template): | ||
os_name = ''.join(i for i in OS if not i.isdigit()) | ||
assert self.oc_api.deploy_image_stream_template( | ||
imagestream_file=f"imagestreams/mariadb-{os_name}.json", | ||
template_file=f"examples/{template}", | ||
app_name=self.oc_api.pod_name_prefix | ||
) | ||
assert self.oc_api.is_pod_running(pod_name_prefix=self.oc_api.pod_name_prefix) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
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, SINGLE_VERSION is missing.") | ||
sys.exit(1) | ||
|
||
|
||
class TestLatestImagestreams: | ||
|
||
def setup_method(self): | ||
self.isc = ImageStreamChecker(working_dir=TEST_DIR.parent) | ||
|
||
def test_latest_imagestream(self): | ||
self.latest_version = self.isc.get_latest_version() | ||
assert self.latest_version != "" | ||
self.isc.check_imagestreams(self.latest_version) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import os | ||
import sys | ||
|
||
import pytest | ||
|
||
from container_ci_suite.openshift import OpenShiftAPI | ||
from container_ci_suite.utils import check_variables | ||
|
||
if not check_variables(): | ||
print("At least one variable from IMAGE_NAME, OS, SINGLE_VERSION is missing.") | ||
sys.exit(1) | ||
|
||
|
||
VERSION = os.getenv("SINGLE_VERSION") | ||
IMAGE_NAME = os.getenv("IMAGE_NAME") | ||
OS = os.getenv("TARGET") | ||
|
||
TAGS = { | ||
"rhel8": "-el8", | ||
"rhel9": "-el9" | ||
} | ||
TAG = TAGS.get(OS, None) | ||
|
||
|
||
class TestMariaDBDeployTemplate: | ||
|
||
def setup_method(self): | ||
self.oc_api = OpenShiftAPI(pod_name_prefix="mariadb-testing", version=VERSION) | ||
self.oc_api.import_is("imagestreams/mariadb-rhel.json", "", skip_check=True) | ||
|
||
def teardown_method(self): | ||
self.oc_api.delete_project() | ||
|
||
@pytest.mark.parametrize( | ||
"template", | ||
[ | ||
"mariadb-ephemeral-template.json", | ||
"mariadb-persistent-template.json" | ||
] | ||
) | ||
def test_python_template_inside_cluster(self, template): | ||
short_version = VERSION.replace(".", "") | ||
assert self.oc_api.deploy_template_with_image( | ||
image_name=IMAGE_NAME, | ||
template=template, | ||
name_in_template="mariadb", | ||
openshift_args=[ | ||
f"MARIADB_VERSION={VERSION}{TAG}", | ||
f"DATABASE_SERVICE_NAME={self.oc_api.pod_name_prefix}", | ||
f"MYSQL_USER=testu", | ||
f"MYSQL_PASSWORD=testp", | ||
f"MYSQL_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}/mariadb-{short_version}", | ||
service_name=self.oc_api.pod_name_prefix, | ||
cmd="echo 'SELECT 42 as testval\\g' | mysql --connect-timeout=15 -h <IP> testdb -utestu -ptestp", | ||
expected_output="42" | ||
) |