Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests written in PyTest for testing in Openshift 4 #304

Merged
merged 3 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 1.20/test/run-openshift-pytest
1 change: 1 addition & 0 deletions 1.20/test/test_nginx_imagestream_s2i.py
1 change: 1 addition & 0 deletions 1.20/test/test_nginx_imagestreams.py
1 change: 1 addition & 0 deletions 1.20/test/test_nginx_local_example.py
1 change: 1 addition & 0 deletions 1.20/test/test_nginx_remote_example.py
1 change: 1 addition & 0 deletions 1.22/test/run-openshift-pytest
1 change: 1 addition & 0 deletions 1.22/test/test_nginx_imagestream_s2i.py
1 change: 1 addition & 0 deletions 1.22/test/test_nginx_imagestreams.py
1 change: 1 addition & 0 deletions 1.22/test/test_nginx_local_example.py
1 change: 1 addition & 0 deletions 1.22/test/test_nginx_remote_example.py
1 change: 1 addition & 0 deletions 1.24/test/run-openshift-pytest
1 change: 1 addition & 0 deletions 1.24/test/test_nginx_imagestream_s2i.py
1 change: 1 addition & 0 deletions 1.24/test/test_nginx_imagestreams.py
1 change: 1 addition & 0 deletions 1.24/test/test_nginx_local_example.py
1 change: 1 addition & 0 deletions 1.24/test/test_nginx_remote_example.py
1 change: 1 addition & 0 deletions 1.24/test/test_nginx_template_example_app.py
13 changes: 13 additions & 0 deletions test/run-openshift-pytest
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_nginx_*.py
42 changes: 42 additions & 0 deletions test/test_nginx_imagestream_s2i.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os
import sys
import pytest

from container_ci_suite.openshift import OpenShiftAPI
from container_ci_suite.utils import get_service_image, check_variables

if not check_variables():
print("At least one variable from IMAGE_NAME, OS, SINGLE_VERSION is missing.")
sys.exit(1)

BRANCH_TO_TEST = "master"
IMAGE_NAME = os.getenv("IMAGE_NAME")
OS = os.getenv("OS")
VERSION = os.getenv("SINGLE_VERSION")


# bash test=test_nginx_imagestream
class TestNginxImagestreamS2I:

def setup_method(self):
self.template_name = get_service_image(IMAGE_NAME)
self.oc_api = OpenShiftAPI(pod_name_prefix=self.template_name, version=VERSION)

def teardown_method(self):
self.oc_api.delete_project()

def test_inside_cluster(self):
os_name = ''.join(i for i in OS if not i.isdigit())
new_version = VERSION
if "-minimal" in VERSION:
new_version = VERSION.replace("-minimal", "")
assert self.oc_api.deploy_imagestream_s2i(
imagestream_file=f"imagestreams/nginx-{os_name}.json",
image_name=IMAGE_NAME,
app="https://github.com/sclorg/nginx-container.git",
context=f"examples/{new_version}/test-app"
)
assert self.oc_api.template_deployed(name_in_template=self.template_name)
assert self.oc_api.check_response_inside_cluster(
name_in_template=self.template_name, expected_output="Test NGINX passed"
)
25 changes: 25 additions & 0 deletions test/test_nginx_imagestreams.py
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 / ".." / "..")

def test_latest_imagestream(self):
self.latest_version = self.isc.get_latest_version()
assert self.latest_version != ""
self.isc.check_imagestreams(self.latest_version)
36 changes: 36 additions & 0 deletions test/test_nginx_local_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
import sys
import pytest

from container_ci_suite.openshift import OpenShiftAPI
from container_ci_suite.utils import get_service_image, 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")


# Replacement with 'test_python_s2i_app_ex_standalone'
class TestNginxLocalEx:

def setup_method(self):
self.template_name = get_service_image(IMAGE_NAME)
self.oc_api = OpenShiftAPI(pod_name_prefix=self.template_name, version=VERSION)

def teardown_method(self):
self.oc_api.delete_project()

def test_python_ex_template_inside_cluster(self):
assert self.oc_api.deploy_s2i_app(
image_name=IMAGE_NAME, app="test-app",
context=".",
service_name=self.template_name
)
assert self.oc_api.template_deployed(name_in_template=self.template_name)
assert self.oc_api.check_response_inside_cluster(
name_in_template=self.template_name, expected_output="Test NGINX passed"
)
37 changes: 37 additions & 0 deletions test/test_nginx_remote_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import sys
import pytest

from container_ci_suite.openshift import OpenShiftAPI
from container_ci_suite.utils import get_service_image, 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")


# Replacement with
# test_nginx_remote_example
class TestNginxLocalEx:

def setup_method(self):
self.template_name = get_service_image(IMAGE_NAME)
self.oc_api = OpenShiftAPI(pod_name_prefix=self.template_name, version=VERSION)

def teardown_method(self):
self.oc_api.delete_project()

def test_python_ex_template_inside_cluster(self):
assert self.oc_api.deploy_s2i_app(
image_name=IMAGE_NAME, app=f"https://github.com/sclorg/nginx-ex.git",
context=".",
service_name=self.template_name
)
assert self.oc_api.template_deployed(name_in_template=self.template_name)
assert self.oc_api.check_response_inside_cluster(
name_in_template=self.template_name, expected_output="Welcome to your static nginx application on OpenShift"
)
48 changes: 48 additions & 0 deletions test/test_nginx_template_example_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
import sys
import pytest

from pathlib import Path

from container_ci_suite.openshift import OpenShiftAPI
from container_ci_suite.utils import get_service_image, 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")


# bash test_nginx_template_from_example_app
# Replacement with 'test_python_s2i_templates'
class TestNginxDeployTemplate:

def setup_method(self):
self.oc_api = OpenShiftAPI(pod_name_prefix="nginx-testing", version=VERSION)

def teardown_method(self):
self.oc_api.delete_project()

def test_python_template_inside_cluster(self):
service_name = "nginx-testing"
template_url = self.oc_api.get_raw_url_for_json(
container="nginx-ex", dir="openshift/templates", filename="nginx.json", branch="master"
)
assert self.oc_api.deploy_template_with_image(
image_name=IMAGE_NAME,
template=template_url,
name_in_template="nginx",
openshift_args=[
f"SOURCE_REPOSITORY_REF=master",
f"NGINX_VERSION={VERSION}",
f"NAME={service_name}"
]
)
assert self.oc_api.template_deployed(name_in_template=service_name)
assert self.oc_api.check_response_inside_cluster(
name_in_template=service_name, expected_output="Welcome to your static nginx application on OpenShift"
)