blob: 8ef5fe4e32c76b0225cfd52b761c4abdf7582b19 [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
Leonardo Sandoval5a335662021-03-26 19:57:40 -06005# Wait for the LAVA job to finished
6# By default, timeout at 5400 secs (1.5 hours) and monitor every 60 seconds
7wait_lava_job() {
8 local id=$1
9 local timeout="${2:-5400}"
10 local interval="${3:-60}"
11
12 (( t = timeout ))
13
14 while ((t > 0)); do
15 sleep $interval
16 resilient_cmd lavacli jobs show $id | tee "${WORKSPACE}/lava-progress.show"
17 if grep 'state.*: Finished' "${WORKSPACE}/lava-progress.show"; then
18 echo finished
19 return
20 fi
21 ((t -= interval))
22 done
23 echo timeout
24}
25
Leonardo Sandovaleb94e912021-01-29 12:23:59 -060026# Run the given command passed through parameters, if fails, try
27# at most more N-times with a pause of M-seconds until success.
28resilient_cmd() {
29 local cmd="$*"
30 local max_wait=10
31 local sleep_body=2
32 local iter=0
33
Leonardo Sandovaleb94e912021-01-29 12:23:59 -060034 while true; do
35 if ${cmd}; then
Leonardo Sandovaleb94e912021-01-29 12:23:59 -060036 break
37 fi
38
39 sleep ${sleep_body}
40
41 iter=$(( iter + 1 ))
42 if [ ${iter} -ge ${max_wait} ]; then
43 return 1
44 fi
45 done
46 return 0
47}
48
Milosz Wasilewski10438582020-12-03 11:36:21 +000049ls -l ${WORKSPACE}
50
Leonardo Sandoval9f159802021-01-20 16:47:25 -060051if [ -n "${QA_SERVER_VERSION}" ]; then
52 if [ -n "${GERRIT_CHANGE_NUMBER}" ] && [ -n "${GERRIT_PATCHSET_NUMBER}" ]; then
Milosz Wasilewski10438582020-12-03 11:36:21 +000053 curl \
54 --retry 4 \
55 -X POST \
56 --header "Auth-Token: ${QA_REPORTS_TOKEN}" \
57 -d patch_source=${GERRIT_HOST} \
58 -d patch_id=${GERRIT_CHANGE_NUMBER},${GERRIT_PATCHSET_NUMBER} \
59 ${QA_SERVER}/api/createbuild/${QA_SERVER_TEAM}/${QA_SERVER_PROJECT}/${QA_SERVER_VERSION}
60 fi
61
62 TESTJOB_ID=$(curl \
63 --retry 4 \
64 -X POST \
65 --header "Auth-Token: ${QA_REPORTS_TOKEN}" \
66 --form backend=${LAVA_SERVER} \
67 --form definition=@artefacts/debug/job.yaml \
68 ${QA_SERVER}/api/submitjob/${QA_SERVER_TEAM}/${QA_SERVER_PROJECT}/${QA_SERVER_VERSION}/${DEVICE_TYPE})
Leonardo Sandoval9f159802021-01-20 16:47:25 -060069
70 if [ -n "${TESTJOB_ID}" ]; then
Milosz Wasilewski10438582020-12-03 11:36:21 +000071 echo "TEST JOB URL: ${QA_SERVER}/testjob/${TESTJOB_ID} TEST JOB ID: ${TESTJOB_ID}"
Leonardo Sandoval9f159802021-01-20 16:47:25 -060072
Leonardo Sandoval9f159802021-01-20 16:47:25 -060073
Leonardo Sandoval73d301a2021-02-12 13:42:55 -060074 # The below loop with a sleep is intentional: LAVA could be under heavy load so previous job creation can
75 # take 'some' time to get the right numeric LAVA JOB ID
76 renumber='^[0-9]+$'
77 LAVAJOB_ID="null"
78 iter=0
79 max_tries=10
80 while ! [[ $LAVAJOB_ID =~ $renumber ]]; do
81 if [ $iter -eq $max_tries ] ; then
82 LAVAJOB_ID=''
83 break
84 fi
85 sleep 2
86 LAVAJOB_ID=$(curl --retry 4 ${QA_SERVER}/api/testjobs/${TESTJOB_ID}/?fields=job_id)
87
88 # Get the job_id value (whatever it is)
89 LAVAJOB_ID=$(echo ${LAVAJOB_ID} | jq '.job_id')
90 LAVAJOB_ID="${LAVAJOB_ID//\"/}"
91
92 iter=$(( iter + 1 ))
93 done
Leonardo Sandoval9f159802021-01-20 16:47:25 -060094
95 # check that rest query at least get non-empty value
96 if [ -n "${LAVAJOB_ID}" ]; then
97
Leonardo Sandoval73d301a2021-02-12 13:42:55 -060098 echo "LAVA URL: https://${LAVA_SERVER}/scheduler/job/${LAVAJOB_ID} LAVA JOB ID: ${LAVAJOB_ID}"
Leonardo Sandoval9f159802021-01-20 16:47:25 -060099
Leonardo Sandoval73d301a2021-02-12 13:42:55 -0600100 resilient_cmd lavacli identities add --username ${LAVA_USER} --token ${LAVA_TOKEN} --uri "https://${LAVA_SERVER}/RPC2" default
Leonardo Sandovala8078d62021-02-11 16:29:25 -0600101
Leonardo Sandoval5a335662021-03-26 19:57:40 -0600102 wait_status="$(wait_lava_job ${LAVAJOB_ID})"
Leonardo Sandoval6ed62092021-03-09 09:32:05 -0600103
104 # if timeout on waiting for LAVA to complete, create an 'artificial' lava.log indicating
105 # job ID and timeout seconds
Leonardo Sandoval5a335662021-03-26 19:57:40 -0600106 if [ "${wait_status}" == "timeout" ]; then
107 echo "Stopped monitoring LAVA JOB ${LAVAJOB_ID}, likely stuck or timeout too short?" > "${WORKSPACE}/lava.log"
Leonardo Sandovale9450132021-04-19 13:51:11 -0500108 exit 1
Leonardo Sandoval9f159802021-01-20 16:47:25 -0600109 else
Arthur She5fc74272021-03-26 21:24:34 -0700110 # Retrieve the test job plain log which is a yaml format file from LAVA
111 resilient_cmd lavacli jobs logs --raw ${LAVAJOB_ID} > "${WORKSPACE}/lava-raw.log"
112
113 # Split the UART messages to the corresponding log files
Leonardo Sandovale9450132021-04-19 13:51:11 -0500114 ${WORKSPACE}/tf-a-job-configs/tf-a-builder/log-splitter.py "${WORKSPACE}/lava-raw.log"
Leonardo Sandoval6ed62092021-03-09 09:32:05 -0600115
116 # Fetch and store LAVA job result (1 failure, 0 success)
Leonardo Sandoval5bb3ad62021-03-09 15:59:19 -0600117 resilient_cmd lavacli jobs show ${LAVAJOB_ID} | tee "${WORKSPACE}/lava.show"
118 if grep 'state.*: Finished' "${WORKSPACE}/lava.show"; then
119 if grep 'Health.*: Complete' "${WORKSPACE}/lava.show"; then
Leonardo Sandovale9450132021-04-19 13:51:11 -0500120 exit 0
Leonardo Sandoval5bb3ad62021-03-09 15:59:19 -0600121 else
Leonardo Sandovale9450132021-04-19 13:51:11 -0500122 exit 1
Leonardo Sandoval5bb3ad62021-03-09 15:59:19 -0600123 fi
Leonardo Sandoval6ed62092021-03-09 09:32:05 -0600124 else
Leonardo Sandovale9450132021-04-19 13:51:11 -0500125 exit 1
Leonardo Sandoval6ed62092021-03-09 09:32:05 -0600126 fi
Leonardo Sandoval9f159802021-01-20 16:47:25 -0600127 fi
128 else
129 echo "LAVA Job ID could not be obtained"
Leonardo Sandovale9450132021-04-19 13:51:11 -0500130 exit 1
Leonardo Sandoval9f159802021-01-20 16:47:25 -0600131 fi
Milosz Wasilewski10438582020-12-03 11:36:21 +0000132 fi
133fi