@@ -4,24 +4,30 @@ ATTACHMENT=""
4
4
ARTIFACTORIAL_URL=" "
5
5
CURL_VERBOSE_FLAG=" "
6
6
FAILURE_RETURN_VALUE=0
7
+ RETRY_COUNT=5
8
+ RETRY_INTERVAL=30
7
9
8
10
usage () {
9
- echo " Usage: $0 [-a <attachment>] [-u <artifactorial_url>] [-v] [-r]" 1>&2
11
+ echo " Usage: $0 [-a <attachment>] [-u <artifactorial_url>] [-c <retry_count>] [-i <retry_interval>] [- v] [-r]" 1>&2
10
12
echo " -a attachment Path to the file to upload" 1>&2
11
13
echo " -u squad_url SQUAD_URL where the attachment will be uploaded to" 1>&2
12
14
echo " This script will try to fetch the SQUAD_ARCHIVE_SUBMIT_TOKEN" 1>&2
13
15
echo " token from (lava_test_dir)/secrets or environments for the upload." 1>&2
16
+ echo " -c retry_count How many times to try when the uploading failed" 1>&2
17
+ echo " -i retry_interval The interval seconds between the re-tries." 1>&2
14
18
echo " -v Pass -v (verbose) flag to curl for debugging." 1>&2
15
19
echo " -r Report failure. If the upload fails and this flag is set, the script will exit" 1>&2
16
20
echo " with return value 1. If the upload is skipped (no URL or no token found)," 1>&2
17
21
echo " this script will still return 0." 1>&2
18
22
exit 1
19
23
}
20
24
21
- while getopts " :a:u:vr" opt; do
25
+ while getopts " :a:u:c:i: vr" opt; do
22
26
case " ${opt} " in
23
27
a) ATTACHMENT=" ${OPTARG} " ;;
24
28
u) ARTIFACTORIAL_URL=" ${OPTARG} " ;;
29
+ c) RETRY_COUNT=" ${OPTARG} " ;;
30
+ i) RETRY_INTERVAL=" ${OPTARG} " ;;
25
31
v) CURL_VERBOSE_FLAG=" -v" ;;
26
32
r) FAILURE_RETURN_VALUE=1 ;;
27
33
* ) usage ;;
@@ -50,24 +56,39 @@ if command -v lava-test-reference > /dev/null 2>&1; then
50
56
echo " test-attachment skip"
51
57
command -v lava-test-case > /dev/null 2>&1 && lava-test-case " test-attachment" --result " skip"
52
58
exit 0
53
- else
54
- # return is the squad testrun id
55
- return=$( curl ${CURL_VERBOSE_FLAG} --header " Auth-Token: ${SQUAD_ARCHIVE_SUBMIT_TOKEN} " --form " attachment=@${ATTACHMENT} " " ${ARTIFACTORIAL_URL} " )
56
59
fi
57
60
58
61
attachmentBasename=" $( basename " ${ATTACHMENT} " ) "
59
- if echo " ${return} " | grep -E " ^[0-9]+$" ; then
60
- # ARTIFACTORIAL_URL will be in the format like this:
61
- # https://qa-reports.linaro.org/api/submit/squad_group/squad_project/squad_build/environment
62
- url_squad=$( echo " ${ARTIFACTORIAL_URL} " | sed ' s|/api/submit/.*||' )
63
- url_uploaded=" ${url_squad} /api/testruns/${return} /attachments/?filename=${attachmentBasename} "
64
- lava-test-reference " test-attachment" --result " pass" --reference " ${url_uploaded} "
65
- else
66
- echo " test-attachment fail"
67
- echo " Expected one SQUAD testrun id returend, but curl returned \" ${return} \" ."
68
- command -v lava-test-case > /dev/null 2>&1 && lava-test-case " test-attachment" --result " fail"
69
- exit " ${FAILURE_RETURN_VALUE} "
70
- fi
62
+ # Re-run the upload for ${RETRY_COUNT} times with the interval of ${RETRY_INTERVAL} seconds when it fails
63
+ i=1
64
+ while [ $i -le " ${RETRY_COUNT} " ]; do
65
+ # response is the squad testrun id when succeed
66
+ response=$( curl ${CURL_VERBOSE_FLAG} --header " Auth-Token: ${SQUAD_ARCHIVE_SUBMIT_TOKEN} " --form " attachment=@${ATTACHMENT} " " ${ARTIFACTORIAL_URL} " )
67
+
68
+ # generate the SQUAD url for download and report pass when uploading succeed
69
+ if echo " ${response} " | grep -E " ^[0-9]+$" ; then
70
+ # ARTIFACTORIAL_URL will be in the format like this:
71
+ # https://qa-reports.linaro.org/api/submit/squad_group/squad_project/squad_build/environment
72
+ url_squad=$( echo " ${ARTIFACTORIAL_URL} " | sed ' s|/api/submit/.*||' )
73
+ url_uploaded=" ${url_squad} /api/testruns/${response} /attachments/?filename=${attachmentBasename} "
74
+ lava-test-reference " test-attachment" --result " pass" --reference " ${url_uploaded} "
75
+ break
76
+ fi
77
+
78
+ # still print the output every time for investigation purpose
79
+ echo " Expected one SQUAD testrun id returend, but curl returned \" ${response} \" ."
80
+
81
+ # report fail if the uploading failed for ${RETRY_COUNT} times
82
+ if [ $i -eq " ${RETRY_COUNT} " ]; then
83
+ echo " test-attachment fail"
84
+ command -v lava-test-case > /dev/null 2>&1 && lava-test-case " test-attachment" --result " fail"
85
+ exit " ${FAILURE_RETURN_VALUE} "
86
+ fi
87
+
88
+ # try again in ${RETRY_INTERVAL} seconds
89
+ sleep " ${RETRY_INTERVAL} "
90
+ i=$(( i + 1 ))
91
+ done
71
92
else
72
93
echo " test-attachment skip"
73
94
command -v lava-test-case > /dev/null 2>&1 && lava-test-case " test-attachment" --result " skip"
0 commit comments