Manage the polling with lavacli 61/21861/2
authorKhouloud Touil <ktouil@baylibre.com>
Fri, 12 Jul 2019 12:45:37 +0000 (14:45 +0200)
committerKhouloud Touil <ktouil@baylibre.com>
Fri, 26 Jul 2019 15:11:06 +0000 (17:11 +0200)
Instead of using a timeout to manage the polling part, this patch
replace it with a lavacli command which is 'lavacli jobs wait'that will
wait for the job to finish, but after 2 hours the 'job wait' will be
stopped even the job if not finished, we are estimating after a 2 hours
of waiting, a problem is occurring in the job.

Signed-off-by: Khouloud Touil <ktouil@baylibre.com>
Change-Id: Ic81a635b0cc2dc5dda3028aefb78f88be0d79a31

jjb/common/include-agl-lava-jobs-submit.sh

index 4617275..0f7844f 100644 (file)
@@ -41,46 +41,14 @@ echo "Submitted as job: $JOB_URL"
 echo ""
 echo "####################################################"
 echo ""
-#
-# LAVA job details, get job status from lavacli output
-#
-# There is no version of blocking call (--block) for lavacli
-# If the job didn't finish after JOB_TIMEOUT, will exit and display
-# an error message
-# example: lava-slave crash
-if [ -z $JOB_TIMEOUT ]; then
-       # if the JOB_TIMEOUT is not set, it's 1 hour by default
-       JOB_TIMEOUT=360
-fi
 
-# FIXME: this section needs to run under set +e
-set +e
-for i in $(seq 1 $JOB_TIMEOUT); do
-    lavacli -i $lab jobs show $job_id --yaml > $JOB_STATUS
-    if [ $? -ne 0 ];then
-               # be patient in case of a temporary error
-               sleep 10
-               continue
-    fi
-    state=$(grep ^state: $JOB_STATUS| cut -d' ' -f2)
-    if [ $state == "Canceled" ]; then
-               status=$(grep ^health: $JOB_STATUS| cut -d' ' -f2)
-               echo "LAVA job $job_id completed with status: $status"
-               break
-    fi
-    if [ $state == "Finished" ]; then
-               status=$(grep ^health: $JOB_STATUS| cut -d' ' -f2)
-               echo "LAVA job $job_id completed with status: $status"
-               break
-    fi
-    sleep 10
-done
-set -e
-# enable set -e again
-
-if [ $i -ge $JOB_TIMEOUT ];then
-       echo "ERROR: job did not finished before 1 hour"
-       exit 1
+# use lavacli wait job instead of the polling.
+lavacli -i agl jobs wait $job_id --timeout 7200
+lavacli -i agl jobs show $job_id --yaml > $JOB_STATUS
+state=$(grep ^state: $JOB_STATUS| cut -d' ' -f2)
+if [ "$state" == "Finished" ]; then
+        status=$(grep ^health: $JOB_STATUS| cut -d' ' -f2)
+        echo "LAVA job $job_id completed with status: $status"
 fi
 
 echo "####"