Replace lava-tool with lavacli 94/21194/1
authorKhouloud Touil <ktouil@baylibre.com>
Tue, 2 Apr 2019 08:49:17 +0000 (10:49 +0200)
committerJan-Simon Möller <jsmoeller@linuxfoundation.org>
Mon, 29 Apr 2019 14:33:51 +0000 (16:33 +0200)
In order to move totally to lavacli, this patch:
- Apply changes to submit jobs using lavacli. As the blocking call
(--block) no longer exists with lavacli, so had to replace that with
a polling loop.
- Replace lava-tool with lavacli in the polling part in the labs-prepare
file, which checks the device status and availability.

Different changes tested at Baylibre.

Change-Id: I25b1ad4b47ae09a158e1e1cf42e30da5e6aa8b57
Signed-off-by: Khouloud Touil <ktouil@baylibre.com>
jjb/common/include-agl-lava-jobs-submit-only.sh
jjb/common/include-agl-lava-jobs-submit.sh
jjb/common/include-agl-lava-labs-prepare.sh

index a835439..f2a20fe 100644 (file)
@@ -19,8 +19,12 @@ cat $JOB_FILE | sed "s/device_type: $releng_device$/device_type: $lava_device/"
 #
 # LAVA job submit, get job ID from lava-tool output
 #
-JOB_STATUS="${JOB_BASE}_${LAVA_LAB}.status"
-lava-tool submit-job --block $full_url $JOB_FILE_NEW |tee $JOB_STATUS
+job_id=$(lavacli -i $lab jobs submit $JOB_FILE_NEW)
+if [ $? -ne 0 ]; then
+       echo "ERROR: job submission error"
+       exit 1
+fi
 # Printing the job URL in the log
-grep "submitted as job:" $JOB_STATUS
+JOB_URL="${url}scheduler/job/${job_id}"
+echo "Submitted as job: $JOB_URL"
 
index 22dc0c3..30f11ee 100644 (file)
@@ -20,24 +20,48 @@ cat $JOB_FILE | sed "s/device_type: $releng_device$/device_type: $lava_device/"
 # LAVA job submit, get job ID from lava-tool output
 #
 JOB_STATUS="${JOB_BASE}_${LAVA_LAB}.status"
-lava-tool submit-job --block $full_url $JOB_FILE_NEW |tee $JOB_STATUS
+
+job_id=$(lavacli -i $lab jobs submit $JOB_FILE_NEW)
+if [ $? -ne 0 ]; then
+       echo "ERROR: job submission error"
+       exit 1
+fi
 # Printing the job URL in the log
-grep "submitted as job:" $JOB_STATUS
-job_id=$(grep "submitted as job:" $JOB_STATUS | sed 's/.*\/\([0-9]*$\)/\1/')
+echo "THe job id is: ${job_id}"
+JOB_URL="${url}scheduler/job/${job_id}"
+echo "Submitted as job: $JOB_URL"
 
 #
-# LAVA job details, get job status from lava-tool output
+# LAVA job details, get job status from lavacli output
 #
-lava-tool job-details $full_url $job_id | tee $JOB_STATUS
-
-IFS=':'
-line=$(grep "^status:" $JOB_STATUS)
-line=$(echo "$line" | tr -d '[:space:]')
-arr=($line)
-status=${arr[1]}
-IFS=${OFS}
+# 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 ]
+       # if the JOB_TIMEOUT is not set, it's 1 hour by default
+       JOB_TIMEOUT=360
+fi
 
-echo "LAVA job $job_id completed with status: $status"
+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 == "Finished" ]; then
+               status=$(grep ^Health: $JOB_STATUS| cut -d' ' -f2)
+               echo "LAVA job $job_id completed with status: $status"
+               break
+    fi
+    sleep 10
+done
+if [ $i -ge $JOB_TIMEOUT ];then
+       echo "ERROR: job did not finished before 1 hour"
+       exit 1
+fi
 
 echo "####"
 echo "#### Start: Output from LAVA job $job_id ####"
index f32e16f..19801e1 100644 (file)
@@ -75,7 +75,7 @@ for lab in "${!labs[@]}"; do
 
     # lavacli: Find the LAVA lab that has the device available to run the job
     echo -n "lavacli: Checking for $lava_device at $full_url... "
-    lavacli_line=$(lavacli -i $lab devices list | grep $lava_device | grep Idle,Good | head -1)
+    lavacli_line=$(lavacli -i $lab devices list | grep $lava_device | grep Good | head -1)
     lavacli_line=$(echo "$lavacli_line" | tr -d '[:space:]')
 
     if [ -z "$lavacli_line" ]; then
@@ -105,12 +105,8 @@ for lab in "${!labs[@]}"; do
         echo "not found."
         continue
     fi
-    IFS='|'
-    arr=($line)
-    device_status=${arr[2]}
-    IFS=${OFS}
 
-    if [ x"$device_status" = x"reserved" ]; then
+    if [ x"$device_status" = x"Reserved,Good" ]; then
         retries=10
     else
         retries=1
@@ -122,26 +118,26 @@ for lab in "${!labs[@]}"; do
     do
         # device is only available if "idle" or "running"
         device_available=0
-        if [ x"$device_status" = x"reserved" ]; then
+        if [ x"$device_status" = x"Reserved,Good" ]; then
             sleep 60s
             # Look if the status of the board has changed from reserved in the lab
             echo -n "Checking for $lava_device at $full_url... "
-            line=$(lava-tool devices-list $full_url | grep $lava_device)
-            line=$(echo "$line" | tr -d '[:space:]')
+            lavacli_line=$(lavacli -i $lab devices list | grep $lava_device | grep Good | head -1)
+            lavacli_line=$(echo "$lavacli_line" | tr -d '[:space:]')
 
-            if [ -z "$line" ]; then
+            if [ -z "$lavacli_line" ]; then
                 echo "not found."
                 continue
             fi
-            IFS='|'
-            arr=($line)
-            device_status=${arr[2]}
+            IFS=':'
+            arr=($lavacli_line)
+            device_status=${arr[1]}
             IFS=${OFS}
         fi
-        if [ x"$device_status" = x"idle" ]; then
+        if [ x"$device_status" = x"Idle,Good" ]; then
             device_available=1
             break
-        elif [ x"$device_status" = x"running" ]; then
+        elif [ x"$device_status" = x"Running,Good" ]; then
             device_available=1;
             break
         fi