Skip to content

Commit cb5168b

Browse files
committed
Store logdetective output to tempfile
and at the end store it to $TMT_TEST_DATA directory so we see it in Testing Farm results Signed-off-by: Petr "Stone" Hracek <[email protected]>
1 parent 4f4ea96 commit cb5168b

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

build.sh

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ parse_output ()
6666
}
6767

6868
analyze_logs_by_logdetective() {
69+
# logdetective should not break the build functionality
70+
set +e
6971
local log_file_name="$1"
7072
echo "Sending failed log by fpaste command to paste bin."
7173
paste_bin_link=$(fpaste "$log_file_name")
@@ -79,14 +81,26 @@ analyze_logs_by_logdetective() {
7981
raw_paste_bin_link="${paste_bin_link//view/view\/raw}"
8082
echo "Sending log file to logdetective server: ${raw_paste_bin_link}"
8183
echo "-------- LOGDETECTIVE BUILD LOG ANALYSIS START --------"
84+
logdetective_build_file=$(mktemp "/tmp/logdetective_build.XXXXXX")
8285
# shellcheck disable=SC2181
83-
if ! curl -k --insecure --header "Content-Type: application/json" --request POST --data "{\"url\":\"${raw_paste_bin_link}\"}" "$LOGDETECTIVE_SERVER/analyze" > /tmp/logdetective_output.txt; then
86+
if ! curl -k --insecure --header "Content-Type: application/json" --request POST --data "{\"url\":\"${raw_paste_bin_link}\"}" "$LOGDETECTIVE_SERVER/analyze" >> "${logdetective_build_file}"; then
8487
echo "ERROR: Failed to analyze log file by logdetective server."
85-
cat "/tmp/logdetective_output.txt"
88+
cat "${logdetective_build_file}"
8689
echo "-------- LOGDETECTIVE BUILD LOG ANALYSIS FAILED --------"
90+
set -e
8791
return
8892
fi
89-
jq -rC '.explanation.text' < "/tmp/logdetective_output.txt"
93+
set -e
94+
jq -rC '.explanation.text' < "${logdetective_build_file}"
95+
# This part of code is from https://github.com/teemtee/tmt/blob/main/tmt/steps/scripts/tmt-file-submit
96+
if [ -z "$TMT_TEST_PIDFILE" ]; then
97+
echo "File submit to data dir can be used only in the context of a running test."
98+
return
99+
fi
100+
# This variable is set by tmt
101+
[ -d "$TMT_TEST_DATA" ] || mkdir -p "$TMT_TEST_DATA"
102+
cp -f "${logdetective_build_file}" "$TMT_TEST_DATA"
103+
echo "File '${logdetective_build_file}' stored to '$TMT_TEST_DATA'."
90104
echo "-------- LOGDETECTIVE BUILD LOG ANALYSIS FINISHED --------"
91105
}
92106

test.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ failed_version() {
2525
}
2626

2727
analyze_logs_by_logdetective() {
28+
# logdetective should not break the test functionality
2829
set +e
2930
local log_file_name="$1"
3031
echo "Sending failed log by fpaste command to paste bin."
@@ -39,16 +40,26 @@ analyze_logs_by_logdetective() {
3940
raw_paste_bin_link="${paste_bin_link//view/view\/raw}"
4041
echo "Sending log file to logdetective server: ${raw_paste_bin_link}"
4142
echo "-------- LOGDETECTIVE TEST LOG ANALYSIS START --------"
43+
logdetective_test_file=$(mktemp "/tmp/logdetective_test.XXXXXX")
4244
# shellcheck disable=SC2181
43-
if ! curl -k --insecure --header "Content-Type: application/json" --request POST --data "{\"url\":\"${raw_paste_bin_link}\"}" "$LOGDETECTIVE_SERVER/analyze" > /tmp/logdetective_test_output.txt; then
45+
if ! curl -k --insecure --header "Content-Type: application/json" --request POST --data "{\"url\":\"${raw_paste_bin_link}\"}" "$LOGDETECTIVE_SERVER/analyze" >> "${logdetective_test_file}"; then
4446
echo "ERROR: Failed to analyze log file by logdetective server."
45-
cat "/tmp/logdetective_test_output.txt"
47+
cat "${logdetective_test_file}"
4648
echo "-------- LOGDETECTIVE TEST LOG ANALYSIS FAILED --------"
4749
set -e
4850
return
4951
fi
50-
jq -rC '.explanation.text' < "/tmp/logdetective_test_output.txt"
5152
set -e
53+
jq -rC '.explanation.text' < "${logdetective_test_file}"
54+
# This part of code is from https://github.com/teemtee/tmt/blob/main/tmt/steps/scripts/tmt-file-submit
55+
if [ -z "$TMT_TEST_PIDFILE" ]; then
56+
echo "File submit to data dir can be used only in the context of a running test."
57+
return
58+
fi
59+
# This variable is set by tmt
60+
[ -d "$TMT_TEST_DATA" ] || mkdir -p "$TMT_TEST_DATA"
61+
cp -f "${logdetective_test_file}" "$TMT_TEST_DATA"
62+
echo "File '${logdetective_test_file}' stored to '$TMT_TEST_DATA'."
5263
echo "-------- LOGDETECTIVE TEST LOG ANALYSIS FINISHED --------"
5364
}
5465

0 commit comments

Comments
 (0)