Skip to content

Commit

Permalink
Catch traceback in case of helm test failed
Browse files Browse the repository at this point in the history
Signed-off-by: Petr "Stone" Hracek <[email protected]>
  • Loading branch information
phracek committed Jan 8, 2024
1 parent d1f6488 commit 3983599
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
24 changes: 17 additions & 7 deletions container_ci_suite/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import random
import time
import requests
import subprocess

from typing import Dict, List, Any
from pathlib import Path
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import os
import json
import yaml
from pathlib import Path

import pytest
Expand Down Expand Up @@ -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())
13 changes: 13 additions & 0 deletions tests/data/Chart.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion tests/test_helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 3983599

Please sign in to comment.