Skip to content

Commit e7d99cc

Browse files
committed
WIP
1 parent a016cf5 commit e7d99cc

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

openqa-run-multi

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 failed skipped
30+
SECONDS=0 # https://stackoverflow.com/questions/8903239/how-can-i-calculate-time-elapsed-in-a-bash-script
31+
32+
while (( retries > 0 )); do
33+
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
34+
35+
jobs=()
36+
while IFS= read -r line; do
37+
if [[ $line =~ mau.*https:\/\/.*\/tests\/([0-9]+) ]]; then #TODO: mau is my case, but not generalized
38+
jobs+=("${BASH_REMATCH[1]}")
39+
fi
40+
done <<< "$clone_output"
41+
42+
echo "Running retry $retries..."
43+
i=$(( ${#jobs[@]} - 1 ))
44+
while (( i >= 0 )); do #TODO: remvoe this since we only need the parent job that we are filtering with the line above
45+
result=$(openqa-cli api --osd --json jobs/"${jobs[$i]}" | jq -r '(.job.result)')
46+
if [[ $result == 'passed' ]]; then
47+
passed+=1
48+
elif [[ $result == 'failed' ]]; then
49+
failed+=1
50+
elif [[ $result == 'cancelled' ]]; then
51+
skipped+=1
52+
elif [[ $result == 'none' ]]; then
53+
sleep 10
54+
continue
55+
fi
56+
(( i-=1 ))
57+
done
58+
(( retries-=1 ))
59+
done
60+
duration=$SECONDS
61+
62+
echo "Tot passed: $passed, failed: $failed, skipped: $skipped"
63+
echo "$((duration / 60)) minutes and $((duration % 60)) seconds elapsed."
64+

0 commit comments

Comments
 (0)