blob: eed7d1b119b1cbb3998d4ba53fbb661130fe1618 [file] [log] [blame]
Milosz Wasilewski10438582020-12-03 11:36:21 +00001#!/bin/bash
2
Leonardo Sandoval9f159802021-01-20 16:47:25 -06003set -xe
Milosz Wasilewski10438582020-12-03 11:36:21 +00004
Paul Sokolovsky7bdac642023-12-30 00:40:00 +03005USE_TUXSUITE_FVP=${USE_TUXSUITE_FVP:-0}
6
7# Get LAVA device type from a job file
8get_lava_device_type() {
9 local job_file=$1
10 awk '/^device_type:/ {print $2}' ${job_file}
11}
12
13setup_tuxsuite() {
14 mkdir -p ~/.config/tuxsuite/
15 cat > ~/.config/tuxsuite/config.ini <<EOF
16[default]
17token=$TUXSUITE_TOKEN
Arthur She78acaae2025-02-05 06:15:04 +010018group=$TUXSUITE_GROUP
19project=$TUXSUITE_PROJECT
Paul Sokolovsky7bdac642023-12-30 00:40:00 +030020EOF
21}
Paul Sokolovsky35c231a2023-05-12 22:53:23 +030022
Leonardo Sandoval5a335662021-03-26 19:57:40 -060023# Wait for the LAVA job to finished
24# By default, timeout at 5400 secs (1.5 hours) and monitor every 60 seconds
25wait_lava_job() {
Paul Sokolovsky99eaff62023-01-25 19:41:23 +070026 set +x
Leonardo Sandoval5a335662021-03-26 19:57:40 -060027 local id=$1
28 local timeout="${2:-5400}"
29 local interval="${3:-60}"
30
31 (( t = timeout ))
32
33 while ((t > 0)); do
34 sleep $interval
Paul Sokolovsky99eaff62023-01-25 19:41:23 +070035 resilient_cmd lavacli jobs show $id | tee "${WORKSPACE}/lava-progress.show" | grep 'state *:'
36 set +x
Leonardo Sandoval5a335662021-03-26 19:57:40 -060037 if grep 'state.*: Finished' "${WORKSPACE}/lava-progress.show"; then
Paul Sokolovsky99eaff62023-01-25 19:41:23 +070038 set -x
39 cat "${WORKSPACE}/lava-progress.show"
Paul Sokolovskya153b602022-10-12 20:50:05 +030040 # finished
41 return 0
Leonardo Sandoval5a335662021-03-26 19:57:40 -060042 fi
43 ((t -= interval))
44 done
Paul Sokolovsky99eaff62023-01-25 19:41:23 +070045 set -x
46 cat "${WORKSPACE}/lava-progress.show"
47 echo "Timeout waiting for job to finish"
Paul Sokolovskya153b602022-10-12 20:50:05 +030048 # timeout
49 return 1
Leonardo Sandoval5a335662021-03-26 19:57:40 -060050}
51
Leonardo Sandovaleb94e912021-01-29 12:23:59 -060052# Run the given command passed through parameters, if fails, try
53# at most more N-times with a pause of M-seconds until success.
54resilient_cmd() {
Paul Sokolovsky99eaff62023-01-25 19:41:23 +070055 set +x
Paul Sokolovsky7fb59b52023-05-13 10:00:57 +030056 local max_retries=10
Leonardo Sandovaleb94e912021-01-29 12:23:59 -060057 local sleep_body=2
58 local iter=0
59
Leonardo Sandovaleb94e912021-01-29 12:23:59 -060060 while true; do
Paul Sokolovsky04004c12023-02-24 18:27:40 +070061 if "$@"; then
Leonardo Sandovaleb94e912021-01-29 12:23:59 -060062 break
63 fi
64
65 sleep ${sleep_body}
Paul Sokolovsky719ac1d2023-05-13 10:03:37 +030066 # Exponential backoff
67 sleep_body=$(( sleep_body * 2 ))
68 if [ ${sleep_body} -ge 60 ]; then
69 sleep_body=60
70 echo "WARNING: Command '$@' still not successful on retry #${iter}, exp backoff already limited" 1>&2
71 fi
Leonardo Sandovaleb94e912021-01-29 12:23:59 -060072
73 iter=$(( iter + 1 ))
Paul Sokolovsky7fb59b52023-05-13 10:00:57 +030074 if [ ${iter} -ge ${max_retries} ]; then
Paul Sokolovsky1f0b7482023-05-09 22:47:49 +030075 echo "ERROR: Command '$@' failed ${iter} times in row" 1>&2
Paul Sokolovsky99eaff62023-01-25 19:41:23 +070076 set -x
Leonardo Sandovaleb94e912021-01-29 12:23:59 -060077 return 1
78 fi
79 done
Paul Sokolovsky99eaff62023-01-25 19:41:23 +070080 set -x
Leonardo Sandovaleb94e912021-01-29 12:23:59 -060081 return 0
82}
83
Milosz Wasilewski10438582020-12-03 11:36:21 +000084ls -l ${WORKSPACE}
85
Paul Sokolovsky7bdac642023-12-30 00:40:00 +030086DEVICE=$(get_lava_device_type artefacts-lava/job.yaml)
87
88if [ "${DEVICE}" == "fvp" -a "${USE_TUXSUITE_FVP}" -ne 0 ]; then
89 setup_tuxsuite
90 set -o pipefail
Paul Sokolovsky5ca3d092024-01-24 00:31:34 +070091 for i in $(seq 1 ${LAVA_RETRIES:-3}); do
92 echo "# TuxSuite submission iteration #$i"
93 if python3 -u -m tuxsuite test submit --device fvp-lava --job-definition artefacts-lava/job.yaml | tee tuxsuite-submit.out; then
94 status=0
95 break
96 else
97 status=$?
98 echo "TuxSuite test failed, status: ${status}"
99 fi
100 done
Paul Sokolovsky7bdac642023-12-30 00:40:00 +0300101 TUXID=$(awk '/^uid:/ {print $2}' tuxsuite-submit.out)
102 echo "TuxSuite test ID: ${TUXID}"
103 echo ${TUXID} > ${WORKSPACE}/tux.id
104 tuxsuite test logs --raw ${TUXID} > ${WORKSPACE}/lava-raw.log
105
Paul Sokolovsky4b16d2d2024-03-04 17:12:27 +0700106 if tuxsuite test results ${TUXID} | grep -v "lava.http-download" | grep -q 'fail'; then
Paul Sokolovsky7bdac642023-12-30 00:40:00 +0300107 echo "tuxsuite test submit status was: ${status}, failing testcases found, setting as 1 (failed)"
108 status=1
109 fi
110
Paul Sokolovskyff615d92024-01-26 16:29:55 +0700111 echo "TuxSuite test result: ${status}"
112
Paul Sokolovsky7bdac642023-12-30 00:40:00 +0300113 exit ${status}
114fi
115
Chris Kaybe24f242025-07-28 13:49:32 +0100116function submit_via_lava() {
117 lavacli identities add --username ${LAVA_USER} --token ${LAVA_TOKEN} --uri "https://${LAVA_SERVER}/RPC2" default
Paul Sokolovsky35c231a2023-05-12 22:53:23 +0300118 LAVAJOB_ID=$(resilient_cmd lavacli jobs submit artefacts-lava/job.yaml)
Leonardo Sandoval9f159802021-01-20 16:47:25 -0600119
Chris Kaybe24f242025-07-28 13:49:32 +0100120 # check that rest query at least get non-empty value
121 if [ -n "${LAVAJOB_ID}" ]; then
122 echo "LAVA URL: https://${LAVA_SERVER}/scheduler/job/${LAVAJOB_ID} LAVA JOB ID: ${LAVAJOB_ID}"
Paul Sokolovsky35c231a2023-05-12 22:53:23 +0300123
Chris Kaybe24f242025-07-28 13:49:32 +0100124 # if timeout on waiting for LAVA to complete, create an 'artificial' lava.log indicating
125 # job ID and timeout seconds
126 if ! wait_lava_job ${LAVAJOB_ID}; then
127 echo "Stopped monitoring LAVA JOB ${LAVAJOB_ID}, likely stuck or timeout too short?" | tee "${WORKSPACE}/lava.log"
128 exit 1
Leonardo Sandoval9f159802021-01-20 16:47:25 -0600129 else
Chris Kaybe24f242025-07-28 13:49:32 +0100130 # Retrieve the test job plain log which is a yaml format file from LAVA
131 resilient_cmd sh -c "lavacli jobs logs --raw ${LAVAJOB_ID} > ${WORKSPACE}/lava-raw.log"
Paul Sokolovsky74cd2e02023-05-12 23:40:55 +0300132
Chris Kaybe24f242025-07-28 13:49:32 +0100133 # Fetch and store LAVA job result (1 failure, 0 success)
134 resilient_cmd lavacli results ${LAVAJOB_ID} | tee "${WORKSPACE}/lava.results"
135 if grep -q '\[fail\]' "${WORKSPACE}/lava.results"; then
136 return 1
137 else
138 return 0
139 fi
140 fi
141 else
142 echo "LAVA Job ID could not be obtained"
143 exit 1
144 fi
Paul Sokolovskyeab838b2023-12-30 00:15:48 +0300145}
146
147# FIXME: Juno and FVP jobs may fail due to non-related users changes,
148# so CI needs to resubmit the job, at most three times:
149# Juno jobs may fail due to LAVA lab infrastructure issues (see
150# https://projects.linaro.org/browse/LSS-2128)
151# FVP jobs may hang at some particular TFTF test (see
152# https://linaro.atlassian.net/browse/TFC-176)
153
154# UPDATE: We want to keep retrying for LAVA for historical reasons,
155# but we want to start from clean page with TuxSuite, so don't
156# retry for it for now, and see how it goes.
157
158status=1
159for i in $(seq 1 ${LAVA_RETRIES:-3}); do
160 echo "# LAVA submission iteration #$i"
Chris Kaybe24f242025-07-28 13:49:32 +0100161 if submit_via_lava; then
Paul Sokolovskyeab838b2023-12-30 00:15:48 +0300162 status=0
163 break
164 fi
165done
166
167exit ${status}