Skip to contentSkip to conversation

ci: check the device health

PATCH New Jan Kiszka 1 participant 1 message Sep 4, 2025

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH v3 1/1 ci: check the device health

From: Quirin Gylstorff <[email protected]>

If there is no healthy device available, try for "WAIT_FOR_DEVICE_TIMEOUT" minutes until aborting the test.

The default of the variable WAIT_FOR_DEVICE_TIMEOUT is 10.

[Jan: ignore device state, only fail if there are no healthy devices]
---
 scripts/run-lava-tests.sh | 33 +++++++++++++++++++++++++++++++--
 tests/README.md           |  1 +
 2 files changed, 32 insertions(+), 2 deletions(-)
scripts/run-lava-tests.sh +31 -2
index 5545dc5..8f9dac0 100755
@@ -24,6 +24,20 @@ get_first_xml_attr_value()
 	grep -m 1 -o "${tag}=\".*\"" ${file} | cut -d\" -f2
 }
 
+get_device_state()
+{
+	device_type=$(grep -oP 'device_type: \K.*' "$1")
+	devices=$(lavacli device-types show "$device_type" --json | jq .devices[] --raw-output)
+	for device in $devices; do
+		available=$(lavacli devices show "$device" --json |
+			jq -c 'select(.health == "Good" or .health == "Unknown")' --raw-output)
+		if [ -n "$available" ]; then
+			return 0
+		fi
+	done
+	return 1
+}
+
 # S3 artifacts
 artifact_url="${LAVA_ARTIFACTS_URL:-https://d1a54g2tyy2hl.cloudfront.net/artifacts}"
 # public master
@@ -42,12 +56,27 @@ TEST_TIMEOUT_MINUTES=$((TEST_RUNTIME_SECONDS / 60 + ADDITIONAL_TEST_TIMEOUT_MINU
 export TEST_TIMEOUT_MINUTES
 
 echo "Deploy artifacts from '${artifact_url}'"
+test_definition="tests/jobs/xenomai-${TARGET}.yml"
 
 tmp_dir=$(mktemp -d)
 template="${tmp_dir}/job_${TARGET}_${CI_PIPELINE_ID}.yml"
 
-cat "tests/jobs/xenomai-${TARGET}.yml" | envsubst > "$template"
-
+cat "$test_definition" | envsubst > "$template"
+
+echo "check for device"
+time_elapsed=0
+while true; do
+	if get_device_state "$test_definition"; then
+		break
+	fi
+	time_elapsed="$((time_elapsed+1))"
+	if [ "$time_elapsed" -gt "${WAIT_FOR_DEVICE_TIMEOUT:-10}" ]; then
+		echo "An test device for '$TARGET' is not available"
+		exit 1
+	fi
+	echo "Wait for test device '$TARGET'"
+	sleep 60
+done
 echo "Submit lava job"
 
 test_id=$(lavacli jobs submit "${template}")
tests/README.md +1 -0
index b6421b4..b8288e7 100644
@@ -111,6 +111,7 @@ The following variables are used and set by the ci system:
   - `LAVA_ARTIFACTS_URL`: optional variable where to get the artifacts for testing
   - `LAVA_MASTER_URL`: URL to the LAVA Master
   - `CONTAINER_REGISTRY`: Container registry server to pull lavacli base image from. Uses registry.gitlab.com if unset.
+  - `WAIT_FOR_DEVICE_TIMEOUT`: Timeout for device health check. Default is 10 minutes.
 
 - Image deployment settings:
   - `USE_S3_BUCKET`: Set to `1` in order to upload build artifacts to AWS S3
Signature · 1 line
2.43.0