From eded5b50e429c50354501b9286fb5578a94ec259 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Tue, 24 Sep 2024 12:54:39 +0200 Subject: [PATCH] Add Makefile and test suite Signed-off-by: Petr "Stone" Hracek --- .github/workflows/openshift-tests.yml | 30 +++++++++++ Makefile | 3 ++ tests/test_rails.py | 58 +++++++++++++++++++++ tests/test_rails_postgresql.py | 72 +++++++++++++++++++++++++++ 4 files changed, 163 insertions(+) create mode 100644 .github/workflows/openshift-tests.yml create mode 100644 Makefile create mode 100644 tests/test_rails.py create mode 100644 tests/test_rails_postgresql.py diff --git a/.github/workflows/openshift-tests.yml b/.github/workflows/openshift-tests.yml new file mode 100644 index 00000000..6e47e950 --- /dev/null +++ b/.github/workflows/openshift-tests.yml @@ -0,0 +1,30 @@ +on: + issue_comment: + types: + - created +jobs: + openshift-tests: + # This job only runs for '[test] pull request comments by owner, member + name: "RHEL9 tests: imagestream ${{ matrix.version }}" + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + version: [ "2.5-ubi8", "3.1-ubi8", "3.0-ubi9", "3.1-ubi9", "3.3-ubi8", "3.3-ubi9" ] + + if: | + github.event.issue.pull_request + && contains(github.event.comment.body, '[test]') + && contains(fromJson('["OWNER", "MEMBER"]'), github.event.comment.author_association) + steps: + - uses: sclorg/testing-farm-as-github-action@main + with: + api_key: ${{ secrets.TF_INTERNAL_API_KEY }} + compose: "RHEL-9.4.0-Nightly" + git_url: "https://gitlab.cee.redhat.com/platform-eng-core-services/sclorg-tmt-plans" + git_ref: "master" + tf_scope: "private" + tmt_plan_regex: "rhel9-openshift-pytest" + update_pull_request_status: true + pull_request_status_name: "RHEL9-OpenShift-4 - imagestream test ${{ matrix.version }}" + variables: "REPO_URL=${{ github.server_url }}/${{ github.repository }};REPO_NAME=${{ github.repository }};PR_NUMBER=${{ github.event.issue.number }};OS=rhel9;SINGLE_VERSION=${{ matrix.version }};TEST_NAME=test-openshift-pytest" \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..d7bdebcb --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +.PHONY: test-openshift-pytest +test-openshift-pytest: + cd tests && PYTHONPATH=$(CURDIR) python3.12 -m pytest -s -rA --showlocals -vv test_*.py diff --git a/tests/test_rails.py b/tests/test_rails.py new file mode 100644 index 00000000..00bb37f3 --- /dev/null +++ b/tests/test_rails.py @@ -0,0 +1,58 @@ +import os + +import pytest + +from pathlib import Path + +from container_ci_suite.openshift import OpenShiftAPI + +test_dir = Path(os.path.abspath(os.path.dirname(__file__))) + +VERSION = os.getenv("SINGLE_VERSION") +if not VERSION: + VERSION = "3.1-ubi8" + + +class TestRailsAppExTemplate: + + def setup_method(self): + self.oc_api = OpenShiftAPI(pod_name_prefix="rails-example") + json_raw_file = self.oc_api.get_raw_url_for_json( + container="s2i-ruby-container", dir="imagestreams", filename="ruby-rhel.json" + ) + self.oc_api.import_is(path=json_raw_file, name="ruby") + + def teardown_method(self): + self.oc_api.delete_project() + + def test_template_inside_cluster(self): + if VERSION.startswith("3.3"): + branch_to_test = "3.3" + else: + branch_to_test = "master" + expected_output = "Welcome to your Rails application" + template_json = test_dir / "../openshift/templates" / "rails.json" + assert self.oc_api.deploy_template( + template=str(template_json), name_in_template="rails-example", expected_output=expected_output, + openshift_args=[f"SOURCE_REPOSITORY_REF={branch_to_test}", f"RUBY_VERSION={VERSION}", "NAME=rails-example"] + ) + assert self.oc_api.template_deployed(name_in_template="rails-example") + assert self.oc_api.check_response_inside_cluster( + name_in_template="rails-example", expected_output=expected_output + ) + + def test_template_by_request(self): + if VERSION.startswith("3.3"): + branch_to_test = "3.3" + else: + branch_to_test = "master" + expected_output = "Welcome to your Rails application" + template_json = test_dir / "../openshift/templates" / "rails.json" + assert self.oc_api.deploy_template( + template=str(template_json), name_in_template="rails-example", expected_output=expected_output, + openshift_args=[f"SOURCE_REPOSITORY_REF={branch_to_test}", f"RUBY_VERSION={VERSION}", "NAME=rails-example"] + ) + assert self.oc_api.template_deployed(name_in_template="rails-example") + assert self.oc_api.check_response_outside_cluster( + name_in_template="rails-example", expected_output=expected_output + ) diff --git a/tests/test_rails_postgresql.py b/tests/test_rails_postgresql.py new file mode 100644 index 00000000..895cbbea --- /dev/null +++ b/tests/test_rails_postgresql.py @@ -0,0 +1,72 @@ +import os + +import pytest + +from pathlib import Path + +from container_ci_suite.openshift import OpenShiftAPI + +test_dir = Path(os.path.abspath(os.path.dirname(__file__))) + +VERSION = os.getenv("SINGLE_VERSION") +if not VERSION: + VERSION = "3.1-ubi8" + + +class TestRailsAppWithPostgreSQLExTemplate: + + def setup_method(self): + self.oc_api = OpenShiftAPI(pod_name_prefix="rails-example") + json_raw_file = self.oc_api.get_raw_url_for_json( + container="s2i-ruby-container", dir="imagestreams", filename="ruby-rhel.json" + ) + self.oc_api.import_is(path=json_raw_file, name="ruby") + json_raw_file = self.oc_api.get_raw_url_for_json( + container="postgresql-container", dir="imagestreams", filename="postgresql-rhel.json" + ) + self.oc_api.import_is(path=json_raw_file, name="postgresql") + + def teardown_method(self): + self.oc_api.delete_project() + + def test_template_inside_cluster(self): + if VERSION.startswith("3.3"): + branch_to_test = "3.3" + else: + branch_to_test = "master" + expected_output = "Welcome to your Rails application" + template_json = test_dir / "../openshift/templates" / "rails-postgresql-persistent.json" + assert self.oc_api.deploy_template( + template=str(template_json), name_in_template="rails-example", expected_output=expected_output, + openshift_args=[ + f"SOURCE_REPOSITORY_REF={branch_to_test}", + f"RUBY_VERSION={VERSION}", + "NAME=rails-example", + "POSTGRESQL_VERSION=12-el8" + ] + ) + assert self.oc_api.template_deployed(name_in_template="rails-example") + assert self.oc_api.check_response_inside_cluster( + name_in_template="rails-example", expected_output=expected_output + ) + + def test_template_by_request(self): + if VERSION.startswith("3.3"): + branch_to_test = "3.3" + else: + branch_to_test = "master" + expected_output = "Welcome to your Rails application" + template_json = test_dir / "../openshift/templates" / "rails-postgresql-persistent.json" + assert self.oc_api.deploy_template( + template=str(template_json), name_in_template="rails-example", expected_output=expected_output, + openshift_args=[ + f"SOURCE_REPOSITORY_REF={branch_to_test}", + f"RUBY_VERSION={VERSION}", + "NAME=rails-example", + "POSTGRESQL_VERSION=12-el8" + ] + ) + assert self.oc_api.template_deployed(name_in_template="rails-example") + assert self.oc_api.check_response_outside_cluster( + name_in_template="rails-example", expected_output=expected_output + )