diff --git a/automated/android/apk-automation/apk-automation.yaml b/automated/android/apk-automation/apk-automation.yaml index 5b6881b58..3e409ee69 100644 --- a/automated/android/apk-automation/apk-automation.yaml +++ b/automated/android/apk-automation/apk-automation.yaml @@ -27,16 +27,13 @@ params: APK_DIR: "./apks" BASE_URL: "http://testdata.validation.linaro.org/apks/" # Specify url and token for publishing artifacts. - ARTIFACTORIAL_URL: "https://archive.validation.linaro.org/artifacts/team/qa/" - # For safety reasons, please set 'ARTIFACTORIAL_TOKEN' variable in job definition with + # For safety reasons, please set 'ARTIFACTORIAL_TOKEN' or + # 'SQUAD_ARCHIVE_SUBMIT_TOKEN' variable in job definition with # 'secrets' dictionary, and set job visibility to personal or group. # Refer to https://validation.linaro.org/static/docs/v2/publishing-artifacts.html - ARTIFACTORIAL_TOKEN: "" # The SQUAD url to be used to upload the result and log files. # see https://squad.readthedocs.io/en/latest/intro.html#submitting-results. - # SQUAD_ARCHIVE_SUBMIT_TOKEN is used for uploading authentication, - # and must be defined by the submitter as one profile managed token - SQUAD_UPLOAD_URL: "" + UPLOAD_URL: "https://archive.validation.linaro.org/artifacts/team/qa/" run: steps: @@ -45,7 +42,7 @@ run: # Upload test output to artifactorial. - cp "./output/${TEST_NAME}/result.txt" "./output/result.txt" - tar caf "output-${TEST_NAME}.tar.xz" "./output" - - if [ -n "${SQUAD_UPLOAD_URL}" ]; then ../../utils/upload-to-squad.sh -a "output-${TEST_NAME}.tar.xz" -u "${SQUAD_UPLOAD_URL}"; fi - - if [ -z "${SQUAD_UPLOAD_URL}" ]; then ../../utils/upload-to-artifactorial.sh -a "output-${TEST_NAME}.tar.xz" -u "${ARTIFACTORIAL_URL}" -t "${ARTIFACTORIAL_TOKEN}"; fi + - if [ -n "${SQUAD_UPLOAD_URL}" ]; then UPLOAD_URL="${SQUAD_UPLOAD_URL}"; fi + - ../../utils/upload-artifacts.sh -a "output-${TEST_NAME}.tar.xz" -u "${UPLOAD_URL}" # Send test result to LAVA. - ../../utils/send-to-lava.sh "./output/result.txt" diff --git a/automated/android/boottime/boottime.yaml b/automated/android/boottime/boottime.yaml index 981f20bea..6a82c20b9 100644 --- a/automated/android/boottime/boottime.yaml +++ b/automated/android/boottime/boottime.yaml @@ -31,19 +31,19 @@ params: OPERATION: "COLLECT" COLLECT_NO: "1" # Specify url and token for file uploading. - URL: "https://archive.validation.linaro.org/artifacts/team/qa/" - TOKEN: "" + # For safety reasons, please set 'ARTIFACTORIAL_TOKEN' or + # 'SQUAD_ARCHIVE_SUBMIT_TOKEN' variable in job definition with + # 'secrets' dictionary, and set job visibility to personal or group. + # Refer to https://validation.linaro.org/static/docs/v2/publishing-artifacts.html # The SQUAD url to be used to upload the result and log files. # see https://squad.readthedocs.io/en/latest/intro.html#submitting-results. - # SQUAD_ARCHIVE_SUBMIT_TOKEN is used for uploading authentication, - # and must be defined by the submitter as one profile managed token - SQUAD_UPLOAD_URL: "" + UPLOAD_URL: "https://archive.validation.linaro.org/artifacts/team/qa/" run: steps: - cd ./automated/android/boottime - ./boottime.sh -S "${SKIP_INSTALL}" -t "${BOOT_TIMEOUT}" -o "${OPERATION}" -n "${COLLECT_NO}" -v "${ANDROID_VERSION}" - - if [ -n "${SQUAD_UPLOAD_URL}" ] && [ "${OPERATION}" = "ANALYZE" ]; then ../../utils/upload-to-squad.sh -a "output/boottime.tgz" -u "${SQUAD_UPLOAD_URL}"; fi - - if [ -z "${SQUAD_UPLOAD_URL}" ] && [ "${OPERATION}" = "ANALYZE" ]; then ../../utils/upload-to-artifactorial.sh -a "output/boottime.tgz" -u "${URL}" -t "${TOKEN}"; fi + - if [ -n "${SQUAD_UPLOAD_URL}" ]; then UPLOAD_URL="${SQUAD_UPLOAD_URL}"; fi + - ../../utils/upload-artifacts.sh -a "output/boottime.tgz" -u "${UPLOAD_URL}" - ../../utils/send-to-lava.sh ./output/boot_result.txt - ../../utils/send-to-lava.sh ./output/result.txt diff --git a/automated/android/noninteractive-tradefed/tradefed.yaml b/automated/android/noninteractive-tradefed/tradefed.yaml index 33487a34c..80adf14fa 100644 --- a/automated/android/noninteractive-tradefed/tradefed.yaml +++ b/automated/android/noninteractive-tradefed/tradefed.yaml @@ -25,14 +25,14 @@ params: TEST_PATH: "android-cts" # Specify result format: aggregated or atomic RESULTS_FORMAT: "aggregated" + # Specify url and token for publishing artifacts. + # For safety reasons, please set 'ARTIFACTORIAL_TOKEN' or + # 'SQUAD_ARCHIVE_SUBMIT_TOKEN' variable in job definition with + # 'secrets' dictionary, and set job visibility to personal or group. + # Refer to https://validation.linaro.org/static/docs/v2/publishing-artifacts.html # The SQUAD url to be used to upload the result and log files. # see https://squad.readthedocs.io/en/latest/intro.html#submitting-results. - # SQUAD_ARCHIVE_SUBMIT_TOKEN is used for uploading authentication, - # and must be defined by the submitter as one profile managed token - SQUAD_UPLOAD_URL: "" - # Specify url and token for file uploading. - URL: "https://archive.validation.linaro.org/artifacts/team/qa/" - TOKEN: "" + UPLOAD_URL: "https://archive.validation.linaro.org/artifacts/team/qa/" AP_SSID: "" AP_KEY: "" # Specify the failures number to be printed @@ -70,8 +70,8 @@ run: - sudo dmesg > ./output/dmesg-host.txt || true - 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 - ATTACHMENT=$(ls tradefed-output-*.tar.xz) - - if [ -n "${SQUAD_UPLOAD_URL}" ]; then ../../utils/upload-to-squad.sh -a "${ATTACHMENT}" -u "${SQUAD_UPLOAD_URL}"; fi - - if [ -z "${SQUAD_UPLOAD_URL}" ]; then ../../utils/upload-to-artifactorial.sh -a "${ATTACHMENT}" -u "${URL}" -t "${TOKEN}"; fi + - if [ -n "${SQUAD_UPLOAD_URL}" ]; then UPLOAD_URL="${SQUAD_UPLOAD_URL}"; fi + - ../../utils/upload-artifacts.sh -a "${ATTACHMENT}" -u "${UPLOAD_URL}" # Send test result to LAVA. - ../../utils/send-to-lava.sh ./output/result.txt - userdel testuser -f -r || true diff --git a/automated/utils/upload-artifacts.sh b/automated/utils/upload-artifacts.sh new file mode 120000 index 000000000..2f2ee164f --- /dev/null +++ b/automated/utils/upload-artifacts.sh @@ -0,0 +1 @@ +upload-to-artifactorial.sh \ No newline at end of file diff --git a/automated/utils/upload-to-artifactorial.sh b/automated/utils/upload-to-artifactorial.sh index ed1dabb04..ac70e877b 100755 --- a/automated/utils/upload-to-artifactorial.sh +++ b/automated/utils/upload-to-artifactorial.sh @@ -1,7 +1,7 @@ #!/bin/sh ATTACHMENT="" -ARTIFACTORIAL_URL="" +URL="" ARTIFACTORIAL_TOKEN="" CURL_VERBOSE_FLAG="" FAILURE_RETURN_VALUE=0 @@ -23,7 +23,7 @@ usage() { while getopts ":a:u:t:vr" opt; do case "${opt}" in a) ATTACHMENT="${OPTARG}" ;; - u) ARTIFACTORIAL_URL="${OPTARG}" ;; + u) URL="${OPTARG}" ;; t) ARTIFACTORIAL_TOKEN="${OPTARG}" ;; v) CURL_VERBOSE_FLAG="-v" ;; r) FAILURE_RETURN_VALUE=1 ;; @@ -31,7 +31,7 @@ while getopts ":a:u:t:vr" opt; do esac done -if [ -z "${ARTIFACTORIAL_URL}" ]; then +if [ -z "${URL}" ]; then echo "test-attachment skip" command -v lava-test-case > /dev/null 2>&1 && lava-test-case "test-attachment" --result "skip" exit 0 @@ -41,18 +41,27 @@ if command -v lava-test-reference > /dev/null 2>&1; then # If 'ARTIFACTORIAL_TOKEN' defined in 'secrects' dictionary defined in job # definition file, it will be used. lava_test_dir="$(find /lava-* -maxdepth 0 -type d | grep -E '^/lava-[0-9]+' 2>/dev/null | sort | tail -1)" - if test -f "${lava_test_dir}/secrets" && grep -q "ARTIFACTORIAL_TOKEN" "${lava_test_dir}/secrets"; then + if test -f "${lava_test_dir}/secrets" && grep -q "_TOKEN" "${lava_test_dir}/secrets"; then # shellcheck disable=SC1090 . "${lava_test_dir}/secrets" fi - if [ -z "${ARTIFACTORIAL_TOKEN}" ]; then - echo "WARNING: ARTIFACTORIAL_TOKEN is empty! File uploading skipped." + if [ -n "${ARTIFACTORIAL_TOKEN}" ]; then + return=$(curl ${CURL_VERBOSE_FLAG} -F "path=@${ATTACHMENT}" -F "token=${ARTIFACTORIAL_TOKEN}" "${URL}") + elif [ -n "${SQUAD_ARCHIVE_SUBMIT_TOKEN}" ]; then + squad_testrun_id=$(curl ${CURL_VERBOSE_FLAG} --header "Auth-Token: ${SQUAD_ARCHIVE_SUBMIT_TOKEN}" --form "attachment=@${ATTACHMENT}" "${URL}") + # URL will be in the format like this: + # https://qa-reports.linaro.org/api/submit/squad_group/squad_project/squad_build/environment + url_squad=$(echo "${URL}"|sed 's|/api/submit/.*||') + return="${url_squad}/api/testruns/${squad_testrun_id}/attachments/?filename=${attachmentBasename}" + if ! echo "${return}" | grep -E "^[0-9]+$"; then + return="${squad_testrun_id}" + fi + else + echo "WARNING: ARTIFACTORIAL_TOKEN or SQUAD_ARCHIVE_SUBMIT_TOKEN is empty! File uploading skipped." echo "test-attachment skip" command -v lava-test-case > /dev/null 2>&1 && lava-test-case "test-attachment" --result "skip" exit 0 - else - return=$(curl ${CURL_VERBOSE_FLAG} -F "path=@${ATTACHMENT}" -F "token=${ARTIFACTORIAL_TOKEN}" "${ARTIFACTORIAL_URL}") fi attachmentBasename="$(basename "${ATTACHMENT}")" @@ -61,7 +70,7 @@ if command -v lava-test-reference > /dev/null 2>&1; then else echo "test-attachment fail" echo "Expected the basename of the attachment file (\"${attachmentBasename}\") to be part \ -of the Artifactorial URL, but curl returned \"${return}\"." +of the ${URL}, but curl returned \"${return}\"." command -v lava-test-case > /dev/null 2>&1 && lava-test-case "test-attachment" --result "fail" exit "${FAILURE_RETURN_VALUE}" fi diff --git a/automated/utils/upload-to-squad.sh b/automated/utils/upload-to-squad.sh deleted file mode 100755 index df9d2fb06..000000000 --- a/automated/utils/upload-to-squad.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/sh - -ATTACHMENT="" -ARTIFACTORIAL_URL="" -CURL_VERBOSE_FLAG="" -FAILURE_RETURN_VALUE=0 - -usage() { - echo "Usage: $0 [-a ] [-u ] [-v] [-r]" 1>&2 - echo " -a attachment Path to the file to upload" 1>&2 - echo " -u squad_url SQUAD_URL where the attachment will be uploaded to" 1>&2 - echo " This script will try to fetch the SQUAD_ARCHIVE_SUBMIT_TOKEN" 1>&2 - echo " token from (lava_test_dir)/secrets or environments for the upload." 1>&2 - echo " -v Pass -v (verbose) flag to curl for debugging." 1>&2 - echo " -r Report failure. If the upload fails and this flag is set, the script will exit" 1>&2 - echo " with return value 1. If the upload is skipped (no URL or no token found)," 1>&2 - echo " this script will still return 0." 1>&2 - exit 1 -} - -while getopts ":a:u:vr" opt; do - case "${opt}" in - a) ATTACHMENT="${OPTARG}" ;; - u) ARTIFACTORIAL_URL="${OPTARG}" ;; - v) CURL_VERBOSE_FLAG="-v" ;; - r) FAILURE_RETURN_VALUE=1 ;; - *) usage ;; - esac -done - -if [ -z "${ARTIFACTORIAL_URL}" ]; then - echo "test-attachment skip" - command -v lava-test-case > /dev/null 2>&1 && lava-test-case "test-attachment" --result "skip" - exit 0 -fi - -if command -v lava-test-reference > /dev/null 2>&1; then - # The 'SQUAD_ARCHIVE_SUBMIT_TOKEN' needs to be defined in 'secrects' dictionary in job - # definition file, or defined in the environment, it will be used. - # One issue here Milosz pointed out: - # If there is lava_test_results_dir set in the job context, "/lava-*" might not be correct. - lava_test_dir="$(find /lava-* -maxdepth 0 -type d | grep -E '^/lava-[0-9]+' 2>/dev/null | sort | tail -1)" - if test -f "${lava_test_dir}/secrets"; then - # shellcheck disable=SC1090 - . "${lava_test_dir}/secrets" - fi - - if [ -z "${SQUAD_ARCHIVE_SUBMIT_TOKEN}" ]; then - echo "WARNING: SQUAD_ARCHIVE_SUBMIT_TOKEN is empty! File uploading skipped." - echo "test-attachment skip" - command -v lava-test-case > /dev/null 2>&1 && lava-test-case "test-attachment" --result "skip" - exit 0 - else - # return is the squad testrun id - return=$(curl ${CURL_VERBOSE_FLAG} --header "Auth-Token: ${SQUAD_ARCHIVE_SUBMIT_TOKEN}" --form "attachment=@${ATTACHMENT}" "${ARTIFACTORIAL_URL}") - fi - - attachmentBasename="$(basename "${ATTACHMENT}")" - if echo "${return}" | grep -E "^[0-9]+$"; then - # ARTIFACTORIAL_URL will be in the format like this: - # https://qa-reports.linaro.org/api/submit/squad_group/squad_project/squad_build/environment - url_squad=$(echo "${ARTIFACTORIAL_URL}"|sed 's|/api/submit/.*||') - url_uploaded="${url_squad}/api/testruns/${return}/attachments/?filename=${attachmentBasename}" - lava-test-reference "test-attachment" --result "pass" --reference "${url_uploaded}" - else - echo "test-attachment fail" - echo "Expected one SQUAD testrun id returend, but curl returned \"${return}\"." - command -v lava-test-case > /dev/null 2>&1 && lava-test-case "test-attachment" --result "fail" - exit "${FAILURE_RETURN_VALUE}" - fi -else - echo "test-attachment skip" - command -v lava-test-case > /dev/null 2>&1 && lava-test-case "test-attachment" --result "skip" -fi