jjb/common: lava-labs-prepare.sh 17/13017/2
authorLoys Ollivier <lollivier@baylibre.com>
Wed, 27 Dec 2017 10:49:58 +0000 (11:49 +0100)
committerLoys Ollivier <lollivier@baylibre.com>
Wed, 27 Dec 2017 12:41:21 +0000 (13:41 +0100)
When device status was reserved, the script would exit and the job fail.

If device status is reserved poll the device status a limited amount of
time. If the status within the defined polling time changes continue
otherwise exit.

Polling as been set to 10 retries on the minute.

JIRA: SPEC-1210
Change-Id: I7ee950777f0881a4a588c9c0dc8db12a7f6dda4a
Signed-off-by: Loys Ollivier <lollivier@baylibre.com>
jjb/common/include-agl-lava-labs-prepare.sh

index 947e086..8a40704 100644 (file)
@@ -84,14 +84,41 @@ for lab in "${!labs[@]}"; do
     device_status=${arr[2]}
     IFS=${OFS}
 
-    # device is only available if "idle" or "running"
-    device_available=0
-    if [ x"$device_status" = x"idle" ]; then
-        device_available=1
-    elif [ x"$device_status" = x"running" ]; then
-        device_available=1;
+    if [ x"$device_status" = x"reserved" ]; then
+        retries=10
+    else
+        retries=1
     fi
 
+    # If the device is reserved poll it's status every minutes.
+    # The max polling time is set to $retries * 60 seconds = 10 minutes.
+    for i in `seq 1 $retries`
+    do
+        # device is only available if "idle" or "running"
+        device_available=0
+        if [ x"$device_status" = x"idle" ]; then
+            device_available=1
+            break
+        elif [ x"$device_status" = x"running" ]; then
+            device_available=1;
+            break
+        fi
+        sleep 60s
+        # Find the LAVA Lab that has the device available to run the job
+        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:]')
+
+        if [ -z "$line" ]; then
+            echo "not found."
+            continue
+        fi
+        IFS='|'
+        arr=($line)
+        device_status=${arr[2]}
+        IFS=${OFS}
+    done
+
     if [ $device_available = 0 ]; then
         echo " Not Available.  Status: $device_status"
         continue