Skip to content

Commit 369b6ac

Browse files
committed
Create function run_test_and_analyze_failed_logs()
This function calls test suite specified by first parameter and in case of failure it sends the failed logs to logdetective Signed-off-by: Petr "Stone" Hracek <[email protected]>
1 parent c93a1b9 commit 369b6ac

File tree

1 file changed

+31
-38
lines changed

1 file changed

+31
-38
lines changed

test.sh

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,32 @@ failed_version() {
2828
return "$result"
2929
}
3030

31+
# run_test_and_analyze_failed_logs
32+
# ------------------------------------------
33+
# Function calls specific test suite and in case of failure
34+
# it sends the failed logs to logdetective and prints report
35+
# generated by logdetective AI
36+
# Argument: test_run - what kind of test that will be executed. Like 'test/run'
37+
run_test_and_analyze_failed_logs() {
38+
local test_run="$1"
39+
set -o pipefail
40+
tmp_file=$(mktemp "/tmp/${OS}-${dir}.XXXXXX")
41+
VERSION=$dir $test_run 2>&1 | tee "$tmp_file"
42+
ret_code=$?
43+
set +o pipefail
44+
cat "${tmp_file}"
45+
if [[ "$ret_code" != "0" ]]; then
46+
if [[ "${OS}" == "rhel8" ]] || [[ "${OS}" == "rhel9" ]] || [[ "${OS}" == "rhel10" ]]; then
47+
set +e
48+
analyze_logs_by_logdetective "$tmp_file"
49+
# Let's switch it back
50+
set -e
51+
fi
52+
fi
53+
failed_version "$ret_code" "$dir"
54+
rm -f "$tmp_file"
55+
56+
}
3157
# This adds backwards compatibility if only single version needs to be testing
3258
# In CI we would like to test single version but VERSIONS= means, that nothing is tested
3359
# make test TARGET=<OS> VERSIONS=<something> ... checks single version for CLI
@@ -51,22 +77,7 @@ for dir in ${VERSIONS}; do
5177
fi
5278

5379
if [ -n "${TEST_MODE}" ]; then
54-
set -o pipefail
55-
tmp_file=$(mktemp "/tmp/${OS}-${dir}.XXXXXX")
56-
VERSION=$dir test/run 2>&1 | tee "$tmp_file"
57-
ret_code=$?
58-
set +o pipefail
59-
cat "${tmp_file}"
60-
if [[ "$ret_code" != "0" ]]; then
61-
if [[ "${OS}" == "rhel8" ]] || [[ "${OS}" == "rhel9" ]] || [[ "${OS}" == "rhel10" ]]; then
62-
set +e
63-
analyze_logs_by_logdetective "$tmp_file"
64-
# Let's switch it back
65-
set -e
66-
fi
67-
fi
68-
failed_version "$ret_code" "$dir"
69-
rm -f "$tmp_file"
80+
run_test_and_analyze_failed_logs "test/run"
7081
fi
7182

7283
if [ -n "${TEST_OPENSHIFT_4}" ]; then
@@ -76,8 +87,7 @@ for dir in ${VERSIONS}; do
7687
echo "-> .exclude-openshift file exists for version $dir, skipping OpenShift-4 tests."
7788
else
7889
if [ -x test/run-openshift-remote-cluster ]; then
79-
VERSION=$dir test/run-openshift-remote-cluster
80-
failed_version "$?" "$dir"
90+
run_test_and_analyze_failed_logs "test/run-openshift-remote-cluster"
8191
else
8292
echo "-> Tests for OpenShift 4 are not present. Add run-openshift-remote-cluster script, skipping"
8393
fi
@@ -87,40 +97,23 @@ for dir in ${VERSIONS}; do
8797

8898
if [ -n "${TEST_UPSTREAM}" ]; then
8999
if [ -x test/run-upstream ]; then
90-
set -o pipefail
91-
tmp_file=$(mktemp "/tmp/${OS}-${dir}.XXXXXX")
92-
VERSION=$dir test/run-upstream 2>&1 | tee "$tmp_file"
93-
ret_code=$?
94-
set +o pipefail
95-
cat "${tmp_file}"
96-
if [[ "$ret_code" != "0" ]]; then
97-
if [[ "${OS}" == "rhel8" ]] || [[ "${OS}" == "rhel9" ]] || [[ "${OS}" == "rhel10" ]]; then
98-
set +e
99-
analyze_logs_by_logdetective "$tmp_file"
100-
# Let's switch it back
101-
set -e
102-
fi
103-
fi
104-
failed_version "$ret_code" "$dir"
105-
rm -f "$tmp_file"
100+
run_test_and_analyze_failed_logs "test/run-upstream"
106101
else
107102
echo "-> Upstream tests are not present, skipping"
108103
fi
109104
fi
110105

111106
if [ -n "${TEST_OPENSHIFT_PYTEST}" ]; then
112107
if [ -x test/run-openshift-pytest ]; then
113-
VERSION=$dir test/run-openshift-pytest
114-
failed_version "$?" "$dir"
108+
run_test_and_analyze_failed_logs "test/run-openshift-pytest"
115109
else
116110
echo "-> OpenShift PyTest tests are not present, skipping"
117111
fi
118112
fi
119113

120114
if [ -n "${TEST_PYTEST}" ]; then
121115
if [ -x test/run-pytest ]; then
122-
VERSION=$dir test/run-pytest
123-
failed_version "$?" "$dir"
116+
run_test_and_analyze_failed_logs "test/run-pytest"
124117
else
125118
echo "-> PyTest tests are not present, skipping"
126119
fi

0 commit comments

Comments
 (0)