aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2023-07-09 23:54:51 -0400
committerTheodore Ts'o <tytso@mit.edu>2023-07-10 09:00:35 -0400
commit835e610f676a25d340c96c93db5b40010e91e6c8 (patch)
tree0da141a75d83ebb61afa40c989ad62daab57356a
parent766e8628d6d4a205310e36f5f0f9be14f9fdb8cc (diff)
downloadxfstests-bld-835e610f676a25d340c96c93db5b40010e91e6c8.tar.gz
test-appliance: get the instance name from the metadata server
When the GCE scripts set the hostname to the GCE instance name is not something that we can count upon; so just query the metadata server to get the information and cache it in /var/lib/gce-xfstests/instance. Between the fact that it can be a fully-qualified domain name, and set at apparently random times while systemd unit files are getting run, it's just safer to not rely on the hostname. This fixes an issue where the test-run ID would sometimes get set to a random value instead of one based on the VM instance name, based on racy systemd unit files' run order on Debian Bookworm based test appliances. Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r--test-appliance/files/usr/local/lib/gce-funcs12
1 files changed, 9 insertions, 3 deletions
diff --git a/test-appliance/files/usr/local/lib/gce-funcs b/test-appliance/files/usr/local/lib/gce-funcs
index 200289d7..be192f1f 100644
--- a/test-appliance/files/usr/local/lib/gce-funcs
+++ b/test-appliance/files/usr/local/lib/gce-funcs
@@ -1,7 +1,5 @@
#!/bin/bash
-instance=$(hostname | cut -d "." -f1)
-
GCE_STATE_DIR=/var/lib/gce-xfstests
if test -z "$MDS_PREFIX"
@@ -92,13 +90,21 @@ else
echo $GCE_ID > $GCE_STATE_DIR/gce_id
fi
+if test -f $GCE_STATE_DIR/instance
+then
+ instance="$(cat $GCE_STATE_DIR/instance)"
+else
+ instance=$(get_metadata_value_with_retries name)
+ echo "$instance" > "$GCE_STATE_DIR/instance"
+fi
+
if test -f $GCE_STATE_DIR/testrunid
then
TESTRUNID=$(cat $GCE_STATE_DIR/testrunid)
else
case "$HOSTNAME" in
xfstests-*)
- TESTRUNID=$(echo $HOSTNAME | sed -e 's/xfstests-//')
+ TESTRUNID=$(echo $instance | sed -e 's/xfstests-//')
;;
*)
TESTRUNID=$(date +%Y%m%d%H%M%S)