From 7b1c292953bf5726b2f5e03379de84c2488277c6 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 26 Jan 2024 15:29:49 +0100 Subject: [PATCH 1/3] test: set -ex separately We call the entrypoint.sh script using `bash entrypoint.sh`, so -ex from the shebang won't be used in that case. Whoopsie. --- test/units/testsuite-13.nspawn.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/units/testsuite-13.nspawn.sh b/test/units/testsuite-13.nspawn.sh index e984d585ca..6647ac8b27 100755 --- a/test/units/testsuite-13.nspawn.sh +++ b/test/units/testsuite-13.nspawn.sh @@ -411,7 +411,8 @@ Port=tcp:60 Port=udp:60:61 EOF cat >"$root/entrypoint.sh" <<\EOF -#!/bin/bash -ex +#!/bin/bash +set -ex [[ "$1" == "foo bar" ]] [[ "$2" == "bar baz" ]] From 8ee32f688fa864a04c5c94fd9c3dbea00cffdc07 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 26 Jan 2024 15:44:39 +0100 Subject: [PATCH 2/3] test: fix the container ID check It never worked, but the fail was masked by missing set -e, see the previous commit. Also, throw env into the test container and dump the environment on container start, to make potential failures easier to debug. --- test/TEST-13-NSPAWN/test.sh | 1 + test/units/testsuite-13.nspawn.sh | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/test/TEST-13-NSPAWN/test.sh b/test/TEST-13-NSPAWN/test.sh index 28d845c94b..6dfb527718 100755 --- a/test/TEST-13-NSPAWN/test.sh +++ b/test/TEST-13-NSPAWN/test.sh @@ -22,6 +22,7 @@ test_append_files() { initdir="$container" setup_basic_dirs initdir="$container" image_install \ bash \ + env \ cat \ hostname \ grep \ diff --git a/test/units/testsuite-13.nspawn.sh b/test/units/testsuite-13.nspawn.sh index 6647ac8b27..79ee239d8d 100755 --- a/test/units/testsuite-13.nspawn.sh +++ b/test/units/testsuite-13.nspawn.sh @@ -414,6 +414,8 @@ EOF #!/bin/bash set -ex +env + [[ "$1" == "foo bar" ]] [[ "$2" == "bar baz" ]] @@ -421,7 +423,7 @@ set -ex [[ "$FOO" == bar ]] [[ "$BAZ" == "hello world" ]] [[ "$PWD" == /tmp ]] -[[ "$( Date: Fri, 26 Jan 2024 18:09:09 +0100 Subject: [PATCH 3/3] test: clean up the code a bit --- test/units/testsuite-13.nspawn.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/test/units/testsuite-13.nspawn.sh b/test/units/testsuite-13.nspawn.sh index 79ee239d8d..b35c6c1e05 100755 --- a/test/units/testsuite-13.nspawn.sh +++ b/test/units/testsuite-13.nspawn.sh @@ -332,7 +332,7 @@ nspawn_settings_cleanup() { } testcase_nspawn_settings() { - local root container dev private_users wlan_names='' wlan_checks='' + local root container dev private_users wlan_names mkdir -p /run/systemd/nspawn root="$(mktemp -d /var/lib/machines/testsuite-13.nspawn-settings.XXX)" @@ -343,8 +343,7 @@ testcase_nspawn_settings() { # add virtual wlan interfaces if modprobe mac80211_hwsim radios=2; then - wlan_names='wlan0 wlan1:wl-renamed1' - wlan_checks='ip link | grep wlan0\nip link | grep wl-renamed1' + wlan_names="wlan0 wlan1:wl-renamed1" fi for dev in sd-host-only sd-shared{1,2,3} sd-macvlan{1,2} sd-macvlanloong sd-ipvlan{1,2} sd-ipvlanlooong; do @@ -401,7 +400,7 @@ Private=yes VirtualEthernet=yes VirtualEthernetExtra=my-fancy-veth1 VirtualEthernetExtra=fancy-veth2:my-fancy-veth2 -Interface=sd-shared1 sd-shared2:sd-renamed2 sd-shared3:sd-altname3 ${wlan_names} +Interface=sd-shared1 sd-shared2:sd-renamed2 sd-shared3:sd-altname3 ${wlan_names:-} MACVLAN=sd-macvlan1 sd-macvlan2:my-macvlan2 sd-macvlanloong IPVLAN=sd-ipvlan1 sd-ipvlan2:my-ipvlan2 sd-ipvlanlooong Zone=sd-zone0 @@ -456,7 +455,12 @@ ip link | grep my-macvlan2@ ip link | grep iv-sd-ipvlan1@ ip link | grep my-ipvlan2@ EOF - echo -e "$wlan_checks" >>"$root/entrypoint.sh" + if [[ -n "${wlan_names:-}" ]]; then + cat >>"$root/entrypoint.sh" <<\EOF +ip link | grep wlan0 +ip link | grep wl-renamed1 +EOF + fi timeout 30 systemd-nspawn --directory="$root"