|
| 1 | +import os |
| 2 | +import sys |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | +from pathlib import Path |
| 7 | + |
| 8 | +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 | +test_dir = Path(os.path.abspath(os.path.dirname(__file__))) |
| 16 | + |
| 17 | + |
| 18 | +VERSION = os.getenv("VERSION") |
| 19 | +IMAGE_NAME = os.getenv("IMAGE_NAME") |
| 20 | +OS = os.getenv("TARGET") |
| 21 | + |
| 22 | +TAGS = { |
| 23 | + "rhel8": "-ubi8", |
| 24 | + "rhel9": "-ubi9" |
| 25 | +} |
| 26 | +TAG = TAGS.get(OS, None) |
| 27 | + |
| 28 | + |
| 29 | +class TestHelmNginxTemplate: |
| 30 | + |
| 31 | + def setup_method(self): |
| 32 | + package_name = "nginx-template" |
| 33 | + path = test_dir |
| 34 | + self.hc_api = HelmChartsAPI(path=path, package_name=package_name, tarball_dir=test_dir, remote=True) |
| 35 | + self.hc_api.clone_helm_chart_repo( |
| 36 | + repo_url="https://github.com/sclorg/helm-charts", repo_name="helm-charts", |
| 37 | + subdir="charts/redhat" |
| 38 | + ) |
| 39 | + |
| 40 | + def teardown_method(self): |
| 41 | + self.hc_api.delete_project() |
| 42 | + |
| 43 | + def test_curl_connection(self): |
| 44 | + if self.hc_api.oc_api.shared_cluster: |
| 45 | + pytest.skip("Do NOT test on shared cluster") |
| 46 | + new_version = VERSION |
| 47 | + if "micro" in VERSION: |
| 48 | + new_version = VERSION.replace("-micro", "") |
| 49 | + self.hc_api.package_name = "nginx-imagestreams" |
| 50 | + assert self.hc_api.helm_package() |
| 51 | + assert self.hc_api.helm_installation() |
| 52 | + self.hc_api.package_name = "nginx-template" |
| 53 | + assert self.hc_api.helm_package() |
| 54 | + assert self.hc_api.helm_installation( |
| 55 | + values={ |
| 56 | + "nginx_version": f"{new_version}{TAG}", |
| 57 | + "namespace": self.hc_api.namespace |
| 58 | + } |
| 59 | + ) |
| 60 | + expected_str = "Welcome to your static nginx application on OpenShift" |
| 61 | + assert self.hc_api.is_s2i_pod_running(pod_name_prefix="nginx-example") |
| 62 | + assert self.hc_api.test_helm_curl_output( |
| 63 | + route_name="nginx-example", |
| 64 | + expected_str=expected_str |
| 65 | + ) |
| 66 | + |
| 67 | + def test_helm_connection(self): |
| 68 | + self.hc_api.package_name = "nginx-imagestreams" |
| 69 | + new_version = VERSION |
| 70 | + if "micro" in VERSION: |
| 71 | + new_version = VERSION.replace("-micro", "") |
| 72 | + assert self.hc_api.helm_package() |
| 73 | + assert self.hc_api.helm_installation() |
| 74 | + self.hc_api.package_name = "nginx-template" |
| 75 | + assert self.hc_api.helm_package() |
| 76 | + assert self.hc_api.helm_installation( |
| 77 | + values={ |
| 78 | + "nginx_version": f"{new_version}{TAG}", |
| 79 | + "namespace": self.hc_api.namespace |
| 80 | + } |
| 81 | + ) |
| 82 | + expected_str = "Welcome to your static nginx application on OpenShift" |
| 83 | + assert self.hc_api.is_s2i_pod_running(pod_name_prefix="nginx-example") |
| 84 | + assert self.hc_api.test_helm_chart(expected_str=[expected_str]) |
0 commit comments