Skip to content

Commit c86086b

Browse files
committed
WIP
1 parent a016cf5 commit c86086b

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

openqa-run-multi

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
3+
# Usage
4+
# echo openqa-run-multi -j <job_id> -r retires
5+
6+
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
7+
set -euo pipefail
8+
9+
# shellcheck source=/dev/null
10+
. "$(dirname "${BASH_SOURCE[0]}")"/_common
11+
12+
job_to_clone=""
13+
retries=100
14+
15+
while getopts "j:r:" opt; do
16+
case $opt in
17+
j) job_to_clone=$OPTARG ;;
18+
r) retries=$OPTARG ;;
19+
*) echo "Usage: $0 -j <job_id> [-r retires]" >&2; exit 1 ;;
20+
esac
21+
done
22+
23+
# Ensure job_to_clone is provided
24+
if [[ -z "$job_to_clone" ]]; then
25+
echo "Error: -j <job_id> is mandatory" >&2
26+
exit 1
27+
fi
28+
29+
declare -i passed=0 failed=0 skipped=0
30+
SECONDS=0 # https://stackoverflow.com/questions/8903239/how-can-i-calculate-time-elapsed-in-a-bash-script
31+
32+
failed_jobs=()
33+
while (( retries > 0 )); do
34+
clone_output=$(openqa-clone-job --within-instance https://openqa.suse.de "$job_to_clone" _GROUP=0 {BUILD,TEST}+=-gpuliti-poo188082 2>/dev/null) #TODO: {BUILD,TEST}+=something coming from args or optional
35+
# clone_output='Cloning parents of sle-15-SP4-...
36+
# Cloning children of sle-15-SP4-...
37+
# 2 jobs have been created:
38+
# - sle-15-SP4-mru... -> https://openqa.suse.de/tests/19333074
39+
# - sle-15-SP4-mau... -> https://openqa.suse.de/tests/19333073
40+
# '
41+
42+
jobs=()
43+
while IFS= read -r line; do
44+
if [[ $line =~ mau.*https:\/\/.*\/tests\/([0-9]+) ]]; then #TODO: mau is my case, but not generalized
45+
jobs+=("${BASH_REMATCH[1]}")
46+
fi
47+
done <<< "$clone_output"
48+
49+
echo "Running retry $retries..."
50+
echo "Job running at https://openqa.suse.de/tests/${jobs[0]}" #TODO: remove or transform
51+
i=$(( ${#jobs[@]} - 1 ))
52+
while (( i >= 0 )); do #TODO: remvoe this since we only need the parent job that we are filtering with the line above
53+
result=$(openqa-cli api --osd --json jobs/"${jobs[$i]}" | jq -r '(.job.result)')
54+
# result="passed"
55+
if [[ $result == 'passed' ]]; then
56+
passed+=1
57+
elif [[ $result == 'failed' ]]; then
58+
failed+=1
59+
failed_jobs+=( "${jobs[$i]}" )
60+
elif [[ $result == 'cancelled' ]]; then
61+
skipped+=1
62+
elif [[ $result == 'none' ]]; then
63+
sleep 10
64+
continue
65+
fi
66+
(( i-=1 ))
67+
done
68+
(( retries-=1 )) || :
69+
done
70+
71+
duration=$SECONDS
72+
echo "$((duration / 60)) minutes and $((duration % 60)) seconds elapsed."
73+
74+
echo "Tests passed: $passed, failed: $failed, skipped: $skipped"
75+
76+
echo "Failed jobs:"
77+
for job in "${failed_jobs[@]}"; do
78+
echo "- https://openqa.suse.de/tests/$job"
79+
done
80+
81+
82+

0 commit comments

Comments
 (0)