Skip to contentSkip to conversation

travis: handle the case of multiple rawhide images

PATCH Applied Ondrej Mosnacek 1 participant 2 messages Nov 2, 2020 – Nov 4, 2020 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 travis: handle the case of multiple rawhide images

For whatever reason, some mirrors contain more than one image version in the directory, causing the test to bail out. This happens only sometimes and restarting the Travis job usually helps, but it's better to adapt the script to handle this case.

Tweak the script to pick the lexicographically last image and exit with error only if there is no image at all.

---
 travis-ci/run-kvm-test.sh | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
travis-ci/run-kvm-test.sh +7 -5
index 6afbf96..bb7c3b7 100755
@@ -36,8 +36,9 @@ VCPUS="$(nproc)"
 #  - https://alt.fedoraproject.org/en/verify.html
 cd "$HOME"
 wget -r -nd -np -l 1 -H -e robots=off -A "*.raw.xz,*-CHECKSUM" "$BASE_URL"
-if [ $(ls -1q *.raw.xz | wc -l) -ne 1 ]; then
-    echo "$0: too many image files downloaded!" 1>&2
+latest_image="$(ls -1q *.raw.xz | tail -n 1)"
+if [ -z "$latest_image" ]; then
+    echo "$0: no image file downloaded!" 1>&2
     exit 1
 fi
 
@@ -49,7 +50,8 @@ fi
 sha256sum --ignore-missing -c ./*-CHECKSUM
 
 # Extract the image
-unxz -T0 *.raw.xz
+unxz -T0 "$latest_image"
+latest_image="${latest_image%.xz}"
 
 # Search is needed for $HOME so virt service can access the image file.
 chmod a+x "$HOME"
@@ -60,7 +62,7 @@ chmod a+x "$HOME"
 #   - Enable passwordless login
 #     - Force a relabel to fix labels on ssh keys
 #
-sudo virt-sysprep -a *.raw \
+sudo virt-sysprep -a "$latest_image" \
   --root-password password:123456 \
   --hostname fedoravm \
   --append-line '/etc/ssh/sshd_config:PermitRootLogin yes' \
@@ -81,7 +83,7 @@ sudo virt-install \
   --name fedoravm \
   --memory $MEMORY \
   --vcpus $VCPUS \
-  --disk *.raw \
+  --disk "$latest_image" \
   --import --noautoconsole
 
 #
Signature · 1 line
2.26.2
author Applied
#1 lore raw
Quoted 58 lines · Ondrej Mosnacek

For whatever reason, some mirrors contain more than one image version in the directory, causing the test to bail out. This happens only sometimes and restarting the Travis job usually helps, but it's better to adapt the script to handle this case.

Tweak the script to pick the lexicographically last image and exit with error only if there is no image at all.

---
 travis-ci/run-kvm-test.sh | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
travis-ci/run-kvm-test.sh +7 -6
index 6afbf96..bb7c3b7 100755
@@ -36,8 +36,9 @@ VCPUS="$(nproc)"
 #  - https://alt.fedoraproject.org/en/verify.html
 cd "$HOME"
 wget -r -nd -np -l 1 -H -e robots=off -A "*.raw.xz,*-CHECKSUM" "$BASE_URL"
-if [ $(ls -1q *.raw.xz | wc -l) -ne 1 ]; then
-    echo "$0: too many image files downloaded!" 1>&2
+latest_image="$(ls -1q *.raw.xz | tail -n 1)"
+if [ -z "$latest_image" ]; then
+    echo "$0: no image file downloaded!" 1>&2
     exit 1
 fi
 
@@ -49,7 +50,8 @@ fi
 sha256sum --ignore-missing -c ./*-CHECKSUM
 
 # Extract the image
-unxz -T0 *.raw.xz
+unxz -T0 "$latest_image"
+latest_image="${latest_image%.xz}"
 
 # Search is needed for $HOME so virt service can access the image file.
 chmod a+x "$HOME"
@@ -60,7 +62,7 @@ chmod a+x "$HOME"
 #   - Enable passwordless login
 #     - Force a relabel to fix labels on ssh keys
 #
-sudo virt-sysprep -a *.raw \
+sudo virt-sysprep -a "$latest_image" \
   --root-password password:123456 \
   --hostname fedoravm \
   --append-line '/etc/ssh/sshd_config:PermitRootLogin yes' \
@@ -81,7 +83,7 @@ sudo virt-install \
   --name fedoravm \
   --memory $MEMORY \
   --vcpus $VCPUS \
-  --disk *.raw \
+  --disk "$latest_image" \
   --import --noautoconsole
 
 #
--
Quoted 1 line

2.26.2

Applied:
https://github.com/SELinuxProject/selinux-testsuite/commit/025fe57d9b707c925590b78c26dfc9726a4a3933

Signature · 3 lines
Ondrej Mosnacek
Software Engineer, Platform Security - SELinux kernel
Red Hat, Inc.