Skip to content

Commit 91a4a95

Browse files
committed
WIP
1 parent a016cf5 commit 91a4a95

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

openqa-run-multi

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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
30+
SECONDS=0 # https://stackoverflow.com/questions/8903239/how-can-i-calculate-time-elapsed-in-a-bash-script
31+
32+
failed_jobs=()
33+
cancelled_jobs=()
34+
while (( retries > 0 )); do
35+
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
36+
# clone_output='Cloning parents of sle-15-SP4-...
37+
# Cloning children of sle-15-SP4-...
38+
# 2 jobs have been created:
39+
# - sle-15-SP4-mru... -> https://openqa.suse.de/tests/19333074
40+
# - sle-15-SP4-mau... -> https://openqa.suse.de/tests/19333073
41+
# '
42+
43+
jobs=()
44+
while IFS= read -r line; do
45+
if [[ $line =~ mau.*https:\/\/.*\/tests\/([0-9]+) ]]; then #TODO: mau is my case, but not generalized
46+
jobs+=("${BASH_REMATCH[1]}")
47+
fi
48+
done <<< "$clone_output"
49+
50+
echo "Running retry $retries..."
51+
echo "Job running at https://openqa.suse.de/tests/${jobs[0]}" #TODO: remove or transform
52+
i=$(( ${#jobs[@]} - 1 ))
53+
while (( i >= 0 )); do #TODO: remvoe this since we only need the parent job that we are filtering with the line above
54+
result=$(openqa-cli api --osd --json jobs/"${jobs[$i]}" | jq -r '(.job.result)')
55+
# result="passed"
56+
if [[ $result == 'passed' ]]; then
57+
(( passed+=1 ))
58+
elif [[ $result == 'failed' ]]; then
59+
failed_jobs+=( "${jobs[$i]}" )
60+
elif [[ $result == 'cancelled' ]]; then
61+
cancelled_jobs+=( "${jobs[$i]}" )
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_jobs[@]}, cancelled: ${#cancelled_jobs[@]}"
75+
76+
echo "Failed jobs:"
77+
for job in "${failed_jobs[@]}"; do
78+
echo "- https://openqa.suse.de/tests/$job"
79+
done
80+
81+
echo "Cancelled jobs:"
82+
for job in "${cancelled_jobs[@]}"; do
83+
echo "- https://openqa.suse.de/tests/$job"
84+
done
85+

0 commit comments

Comments
 (0)