diff --git a/container_ci_suite/helm.py b/container_ci_suite/helm.py index 564d8de..dd28698 100644 --- a/container_ci_suite/helm.py +++ b/container_ci_suite/helm.py @@ -25,6 +25,7 @@ import random import time import requests +import subprocess from typing import Dict, List, Any from pathlib import Path @@ -115,8 +116,12 @@ def helm_package(self) -> bool: if not self.is_chart_yaml_present(): print(f"Chart.yaml file is not present in directory {self.full_package_dir}") return False + self.version = self.get_version_from_chart_yaml() + print(f"Helm package command is: helm package {self.full_package_dir}") output = HelmChartsAPI.run_helm_command(f"package {self.full_package_dir}", json_output=False) + print(output) if "Successfully packaged chart" in output: + print(self.get_tarball_name) if self.get_tarball_name in output: return True return False @@ -288,13 +293,18 @@ def check_test_output(self, output, expected_str: List[str]): return True def test_helm_chart(self, expected_str: List[str]) -> bool: - time.sleep(10) - output = HelmChartsAPI.run_helm_command( - f"test {self.package_name} --logs", json_output=False - ) - print(f"Helm test output: {output}") - if self.check_test_output(output, expected_str=expected_str): - return True + for count in range(6): + time.sleep(10) + try: + output = HelmChartsAPI.run_helm_command( + f"test {self.package_name} --logs", json_output=False + ) + print(f"Helm test output: {output}") + except subprocess.CalledProcessError: + print("Helm test command `test {self.package_name} --logs`failed. Let's try more time.") + continue + if self.check_test_output(output, expected_str=expected_str): + return True output = OpenShiftAPI.run_oc_command("status", json_output=False) print(output) output = OpenShiftAPI.run_oc_command("get all", json_output=False) diff --git a/tests/conftest.py b/tests/conftest.py index c0ea272..2732048 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -22,6 +22,7 @@ import os import json +import yaml from pathlib import Path import pytest @@ -90,3 +91,8 @@ def helm_list_json(): @pytest.fixture() def oc_get_is_ruby_json(): return json.loads((DATA_DIR / "oc_get_is_ruby.json").read_text()) + + +@pytest.fixture() +def get_chart_yaml(): + return yaml.safe_load((DATA_DIR / "Chart.yaml").read_text()) diff --git a/tests/data/Chart.yaml b/tests/data/Chart.yaml new file mode 100644 index 0000000..85c3371 --- /dev/null +++ b/tests/data/Chart.yaml @@ -0,0 +1,13 @@ +description: |- + This content is expermental, do not use it in production. Red Hat PostgreSQL database service imagestreams. + For more information about PostgreSQL container see https://github.com/sclorg/postgresql-container/. +annotations: + charts.openshift.io/name: Red Hat PostgreSQL database service imagestreams (experimental) +apiVersion: v2 +appVersion: 0.0.1 +kubeVersion: '>=1.20.0' +name: postgresql-imagestreams +tags: database,postgresql +sources: + - https://github.com/sclorg/helm-charts +version: 0.0.1 diff --git a/tests/test_helm.py b/tests/test_helm.py index 3dad972..7eb3208 100644 --- a/tests/test_helm.py +++ b/tests/test_helm.py @@ -62,9 +62,11 @@ def test_check_imagestreams(self, tag, registry, expected_value, postgresql_json self.helm_chart.tag = tag assert self.helm_chart.check_imagestreams(tag, registry=registry) == expected_value - def test_package_helm_chart_success(self, helm_package_success): + def test_package_helm_chart_success(self, helm_package_success, get_chart_yaml): flexmock(HelmChartsAPI).should_receive("is_chart_yaml_present").and_return(True) flexmock(HelmChartsAPI).should_receive("run_helm_command").and_return(helm_package_success) + flexmock(HelmChartsAPI).should_receive("get_version_from_chart_yaml").and_return("0.0.1") + assert self.helm_chart.package_name == "postgresql-imagestreams" assert self.helm_chart.helm_package() def test_package_helm_chart_failed(self, helm_package_failed):