Skip to content

Commit

Permalink
Fix return values and move check for timeago back
Browse files Browse the repository at this point in the history
Fix exit handler
  • Loading branch information
perlpunk committed Nov 26, 2024
1 parent 0f59bc3 commit 38ba8dc
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions openqa-label-known-issues
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@ MOJO_CONNECT_TIMEOUT=${MOJO_CONNECT_TIMEOUT:-30}
client_args=(api --header 'User-Agent: openqa-label-known-issues (https://github.com/os-autoinst/scripts)' --host "$host_url" --retries="$retries")

out="${REPORT_FILE:-$(mktemp -t openqa-label-known-issues--output-XXXX)}"
declare timeago
trap 'error-handler "$LINENO"' ERR
trap 'test "$KEEP_REPORT_FILE" == "1" || rm "$out"' EXIT
trap 'test "$KEEP_JOB_HTML_FILE" == "1" || rm "$html_out"' EXIT
trap '_cleanup' EXIT

_cleanup() {
test "$KEEP_REPORT_FILE" == "1" || rm "$out"
test "$KEEP_JOB_HTML_FILE" == "1" || rm -f "$html_out"
}

echoerr() { echo "$@" >&2; }

handle_unreachable() {
local testurl=$1
local timeago
html_out=${JOB_HTML_FILE:-$(mktemp -t openqa-label-known-issues--job-details-XXXX)}
if ! curl "${curl_args[@]}" -s --head "$testurl" -o /dev/null; then
# the page might be gone, try the scheme+host we configured (might be different one though)
Expand All @@ -58,12 +62,20 @@ handle_unreachable() {
curl "${curl_args[@]}" "$testurl"
exit 2
fi
timeago=$(grep timeago "$html_out" | hxselect -s '\n' -c '.timeago::attr(title)')

if hxnormalize -x "${html_out}" | hxselect -s '\n' -c '.links_a .resborder' | grep -qPzo '(?s)Gru job failed.*connection error.*Inactivity timeout'; then
"${client_call[@]}" -X POST jobs/"$id"/comments text='poo#62456 test incompletes after failing in GRU download task on "Inactivity timeout" with no logs'
"${client_call[@]}" -X POST jobs/"$id"/restart
return
return 1
fi

# Checking timestamp given by job details page
timeago=$(grep timeago "$html_out" | hxselect -s '\n' -c '.timeago::attr(title)')
if [[ $(date -uIs -d '-14days') > $timeago ]]; then
# if the page is there but not even an autoinst-log.txt exists
# then the job might be too old and logs are already deleted.
echoerr "'$testurl' job#${id} without autoinst-log.txt older than 14 days. Do not label"
return 1
fi
}

Expand Down Expand Up @@ -138,16 +150,9 @@ investigate_issue() {
echo "$reason" >> "$out"
if [[ "$curl_output" != "200" ]] && [[ "$curl_output" != "301" ]]; then
# if we can not even access the page it is something more critical
handle_unreachable "$testurl" "$out" || return
handle_unreachable "$testurl" "$out" || return 0

[[ $curl_output != 404 ]] && return
# Checking timestamp given by job details page
if [[ $(date -uIs -d '-14days') > $timeago ]]; then
# if the page is there but not even an autoinst-log.txt exists
# then the job might be too old and logs are already deleted.
echoerr "'$testurl' job#${id} without autoinst-log.txt older than 14 days. Do not label"
return
fi
# not unreachable, no log, no reason, not too old
if [[ -z $reason ]] || [[ $reason = null ]]; then
echoerr "'$testurl' does not have autoinst-log.txt or reason, cannot label"
Expand Down

0 comments on commit 38ba8dc

Please sign in to comment.