Skip to content

Commit 178f445

Browse files
authored
Add support to upload artifacts to SQUAD server (#497)
* upload-to-squad.sh: add support to upload archives to SQUAD to replace the uploading to archive.vlo Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org> * noninteractive-tradefed: add support for uploading archives to SQUAD via specifying the SQUAD_UPLOAD_URL variables. To be noted, to avoid leak of tokens, the SQUAD_ARCHIVE_SUBMIT_TOKEN used to upload is not supported to be defined in the job definition in the plain text format, it's must be defined as one profile managed token by the submitter Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org> --------- Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
1 parent d761dae commit 178f445

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

automated/android/noninteractive-tradefed/tradefed.yaml

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ params:
2525
TEST_PATH: "android-cts"
2626
# Specify result format: aggregated or atomic
2727
RESULTS_FORMAT: "aggregated"
28+
# The SQUAD url to be used to upload the result and log files.
29+
# see https://squad.readthedocs.io/en/latest/intro.html#submitting-results.
30+
# SQUAD_ARCHIVE_SUBMIT_TOKEN is used for uploading authentication,
31+
# and must be defined by the submitter as one profile managed token
32+
SQUAD_UPLOAD_URL: ""
2833
# Specify url and token for file uploading.
2934
URL: "https://archive.validation.linaro.org/artifacts/team/qa/"
3035
TOKEN: ""
@@ -65,7 +70,8 @@ run:
6570
- sudo dmesg > ./output/dmesg-host.txt || true
6671
- if ! tar caf tradefed-output-$(date +%Y%m%d%H%M%S).tar.xz ./output; then error_fatal "tradefed - failed to collect results and log files [$ANDROID_SERIAL]"; fi
6772
- ATTACHMENT=$(ls tradefed-output-*.tar.xz)
68-
- ../../utils/upload-to-artifactorial.sh -a "${ATTACHMENT}" -u "${URL}" -t "${TOKEN}"
73+
- if [ -n "${SQUAD_UPLOAD_URL}" ]; then ../../utils/upload-to-squad.sh -a "${ATTACHMENT}" -u "${SQUAD_UPLOAD_URL}"; fi
74+
- if [ -z "${SQUAD_UPLOAD_URL}" ]; then ../../utils/upload-to-artifactorial.sh -a "${ATTACHMENT}" -u "${URL}" -t "${TOKEN}"; fi
6975
# Send test result to LAVA.
7076
- ../../utils/send-to-lava.sh ./output/result.txt
7177
- userdel testuser -f -r || true

automated/utils/upload-to-squad.sh

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/sh
2+
3+
ATTACHMENT=""
4+
ARTIFACTORIAL_URL=""
5+
CURL_VERBOSE_FLAG=""
6+
FAILURE_RETURN_VALUE=0
7+
8+
usage() {
9+
echo "Usage: $0 [-a <attachment>] [-u <artifactorial_url>] [-v] [-r]" 1>&2
10+
echo " -a attachment Path to the file to upload" 1>&2
11+
echo " -u squad_url SQUAD_URL where the attachment will be uploaded to" 1>&2
12+
echo " This script will try to fetch the SQUAD_ARCHIVE_SUBMIT_TOKEN" 1>&2
13+
echo " token from (lava_test_dir)/secrets or environments for the upload." 1>&2
14+
echo " -v Pass -v (verbose) flag to curl for debugging." 1>&2
15+
echo " -r Report failure. If the upload fails and this flag is set, the script will exit" 1>&2
16+
echo " with return value 1. If the upload is skipped (no URL or no token found)," 1>&2
17+
echo " this script will still return 0." 1>&2
18+
exit 1
19+
}
20+
21+
while getopts ":a:u:vr" opt; do
22+
case "${opt}" in
23+
a) ATTACHMENT="${OPTARG}" ;;
24+
u) ARTIFACTORIAL_URL="${OPTARG}" ;;
25+
v) CURL_VERBOSE_FLAG="-v" ;;
26+
r) FAILURE_RETURN_VALUE=1 ;;
27+
*) usage ;;
28+
esac
29+
done
30+
31+
if [ -z "${ARTIFACTORIAL_URL}" ]; then
32+
echo "test-attachment skip"
33+
command -v lava-test-case > /dev/null 2>&1 && lava-test-case "test-attachment" --result "skip"
34+
exit 0
35+
fi
36+
37+
if command -v lava-test-reference > /dev/null 2>&1; then
38+
# The 'SQUAD_ARCHIVE_SUBMIT_TOKEN' needs to be defined in 'secrects' dictionary in job
39+
# definition file, or defined in the environment, it will be used.
40+
# One issue here Milosz pointed out:
41+
# If there is lava_test_results_dir set in the job context, "/lava-*" might not be correct.
42+
lava_test_dir="$(find /lava-* -maxdepth 0 -type d | grep -E '^/lava-[0-9]+' 2>/dev/null | sort | tail -1)"
43+
if test -f "${lava_test_dir}/secrets"; then
44+
# shellcheck disable=SC1090
45+
. "${lava_test_dir}/secrets"
46+
fi
47+
48+
if [ -z "${SQUAD_ARCHIVE_SUBMIT_TOKEN}" ]; then
49+
echo "WARNING: SQUAD_ARCHIVE_SUBMIT_TOKEN is empty! File uploading skipped."
50+
echo "test-attachment skip"
51+
command -v lava-test-case > /dev/null 2>&1 && lava-test-case "test-attachment" --result "skip"
52+
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+
fi
57+
58+
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
71+
else
72+
echo "test-attachment skip"
73+
command -v lava-test-case > /dev/null 2>&1 && lava-test-case "test-attachment" --result "skip"
74+
fi

0 commit comments

Comments
 (0)