Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent override the autoinst-log context within handle_unreachable #347

Merged
merged 8 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
python --version
pytest --version
- run: |
sudo apt-get install cpanminus
sudo apt-get install cpanminus html-xml-utils
sudo cpanm -n -M https://cpan.metacpan.org --installdeps .
- name: unit- and integration tests
run: |
Expand Down
36 changes: 22 additions & 14 deletions openqa-label-known-issues
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@ client_args=(api --header 'User-Agent: openqa-label-known-issues (https://github

out="${REPORT_FILE:-$(mktemp -t openqa-label-known-issues--output-XXXX)}"
trap 'error-handler "$LINENO"' ERR
trap 'test "$KEEP_REPORT_FILE" == "1" || rm "$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 out=$2

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)
if ! grep -q "$host_url" <<< "$testurl"; then
Expand All @@ -51,18 +56,27 @@ handle_unreachable() {
return 1
fi
# resorting to downloading the job details page instead of the
# log, overwrites $out
if ! curl "${curl_args[@]}" -s "$testurl" -o "$out"; then
# log
if ! curl "${curl_args[@]}" -s "$testurl" -o "${html_out}"; then
echoerr "'$testurl' can be reached but not downloaded, bailing out"
curl "${curl_args[@]}" "$testurl"
exit 2
fi

if hxnormalize -x "$out" | hxselect -s '\n' -c '.links_a .resborder' | grep -qPzo '(?s)Gru job failed.*connection error.*Inactivity timeout'; then
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 1
fi

# Checking timestamp given by job details page
timeago=$(grep timeago "$html_out" | hxselect -s '\n' -c '.timeago::attr(title)')
perlpunk marked this conversation as resolved.
Show resolved Hide resolved
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
}

label_on_issues_from_issue_tracker() {
Expand Down Expand Up @@ -136,15 +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
perlpunk marked this conversation as resolved.
Show resolved Hide resolved

[[ $curl_output != 404 ]] && return
# Checking timestamp
if [[ $(date -uIs -d '-14days') > $(grep timeago "$out" | hxselect -s '\n' -c '.timeago::attr(title)') ]]; 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
61 changes: 30 additions & 31 deletions test/07-openqa-label-known-issues.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ source openqa-label-known-issues
client_args=(api --host "$host_url")

export KEEP_REPORT_FILE=1
export KEEP_JOB_HTML_FILE=1

client_output=''
mock-client-output() {
Expand Down Expand Up @@ -39,14 +40,8 @@ comment_on_job() {
echo "$comment"
}
out=''
hxnormalize() {
cat "$2"
}
hxselect() {
cat -
}

try investigate_issue
try investigate_issue || true
is "$rc" 1 'id required'
# error in tap output is from here

Expand All @@ -60,56 +55,60 @@ action
Job incompletes with reason auto_review:\"(?m)api failure$\" (and no further details)
action"

tmplog=$(mktemp)
out=$tmplog
tmpjobpage=$(mktemp)

setup() {
local id=$1
declare -g id=$id
declare -g testurl="https://openqa.opensuse.org/tests/${id}"
}

# test data with reason but 404 in curl respond
id=404
testurl="https://openqa.opensuse.org/tests/${id}"
setup 404
older40d_date=$(date -uIs -d '-40days')
echo -n "Result:<b>incomplete</b>finished<abbr class=\"timeago\" title=\"${older40d_date}\"</abbr>>" > $tmpjobpage
export JOB_HTML_FILE=$tmpjobpage
try-client-output investigate_issue $id
is "$rc" 0 'investigate_issue with missing autoinst-log and with reason in job_data'
is "$rc" 0 'investigate_issue with missing autoinst-log and with reason in job_data' #ok 3
has "$got" "without autoinst-log.txt older than 14 days. Do not label" "exits succefully when is old job without autoinst-log.txt"

# all assets are missing
id=101
testurl="https://openqa.opensuse.org/tests/${id}"
# `cur_date` is used on the following 4 test cases
cur_date=$(date +%F)
sed -i "s/yyyy-mm-dd/${cur_date}/" "$dir/data/${id}.json"
+fs:mktemp
tmplog=$temp
echo -n "Result: <b>incomplete</b>, finished <abbr class=\"timeago\" title=\"${cur_date}T08:06:42Z\"</abbr>>" > $tmplog
out=$tmplog
setup 101
# `older1d_date` is used on the following 4 test cases
older1d_date=$(date -uIs -d '-1days')
sed -i "s/yyyy-mm-dd/${older1d_date}/" "$dir/data/${id}.json"
echo -n "Result:<b>incomplete</b>finished<abbr class=\"timeago\" title=\"${older1d_date}\"</abbr>>" > $tmpjobpage
html_out=$tmpjobpage
export JOB_HTML_FILE=$tmpjobpage
echo > $tmplog
try-client-output investigate_issue $id
is "$rc" 0 'investigate_issue with missing autoinst-log but with reason in job_data'
is "$rc" 0 'investigate_issue with missing autoinst-log but with reason in job_data' # ok 4
has "$got" "does not have autoinst-log.txt or reason, cannot label" "investigation exits when no reason and autoinst-log"
# Cleanup 404.json
sed -i "s/${cur_date}/yyyy-mm-dd/" "$dir/data/${id}.json"
sed -i "s/${older1d_date}/yyyy-mm-dd/" "$dir/data/${id}.json"

# Unknown reason - not included in issues
id=102
testurl="https://openqa.opensuse.org/tests/${id}"
echo -n "Result: <b>incomplete</b>, finished <abbr class=\"timeago\" title=\"${cur_date}T08:06:42Z\"</abbr>>" > $tmplog
setup 102
echo -n "\nthe reason is whatever" >> $tmplog
out=$tmplog
try-client-output investigate_issue $id
is "$rc" 0 'investigate no old issue with missing autoinst-log and unknown reason in job_data'
has "$got" "Unknown test issue, to be reviewed" "investigation still label Unknown reason"

id=414
testurl="https://openqa.opensuse.org/tests/${id}"
setup 414
try-client-output investigate_issue $id
is "$rc" 0 'investigate_issue with missing old autoinst-log and without reason in job_data'
has "$got" "does not have autoinst-log.txt or reason, cannot label" "investigation exits successfully when no reason and no autoinst-log"

id=200
testurl="https://openqa.opensuse.org/tests/${id}"
setup 200
cp $autoinst_log $tmplog
out=$tmplog
try-client-output investigate_issue $id
is "$rc" 0 'investigate_issue with autoinst-log and without reason'
has "$got" "test fails in network_peering" "investigation label job with matched autoinst-log context"

# handle_unreview branch
echo > "$tmplog"
out=$tmplog
try-client-output investigate_issue $id
is "$rc" 0 'job with empty autoinst-log checks unknown issue'
has "$got" "Unknown test issue, to be reviewed" "investigation still label Unknown issue"
Expand Down