Skip to content

Commit

Permalink
Merge pull request #347 from b10n1k/label_known_issues_override
Browse files Browse the repository at this point in the history
Prevent override the autoinst-log context within handle_unreachable
  • Loading branch information
mergify[bot] authored Nov 27, 2024
2 parents f748781 + eabd76b commit e8d8e56
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 55 deletions.
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
41 changes: 25 additions & 16 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)')
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 @@ -116,7 +130,8 @@ label_on_issues_without_tickets() {
}

investigate_issue() {
local id="${1##*/}"
local testurl=$1
local id="${testurl##*/}"
local reason
local curl_output
echo "Requesting jobs/${id} via openqa-cli"
Expand All @@ -136,15 +151,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
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 All @@ -166,7 +175,7 @@ investigate_issue() {
}

label_issue() {
testurl="${1:?"Need 'testurl'"}"
local testurl="${1:?"Need 'testurl'"}"
[[ "$dry_run" = "1" ]] && client_prefix="echo"
if [[ -z "$client_call" ]]; then
client_call=(openqa-cli "${client_args[@]}")
Expand Down
74 changes: 36 additions & 38 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,61 +55,64 @@ action
Job incompletes with reason auto_review:\"(?m)api failure$\" (and no further details)
action"

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

setup() {
id=$1
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}"
try-client-output investigate_issue $id
is "$rc" 0 'investigate_issue with missing autoinst-log and with reason in job_data'
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 $testurl
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
try-client-output investigate_issue $id
is "$rc" 0 'investigate_issue with missing autoinst-log but with reason in job_data'
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 $testurl
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
try-client-output investigate_issue $testurl
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}"
try-client-output investigate_issue $id
setup 414
try-client-output investigate_issue $testurl
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
try-client-output investigate_issue $testurl
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
try-client-output investigate_issue $testurl
is "$rc" 0 'job with empty autoinst-log checks unknown issue'
has "$got" "Unknown test issue, to be reviewed" "investigation still label Unknown issue"

echo -n "[error] Failed to download" > $out
try-client-output investigate_issue $id
try-client-output investigate_issue $testurl
is "$rc" 0 'job label without tickets'
has "$got" "label:download_error potentially out-of-space worker?" "investistigation label correctly job without ticket"

0 comments on commit e8d8e56

Please sign in to comment.