]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: avoid nspawn failure due to scope in use in TEST-06-SELINUX
authorLuca Boccassi <luca.boccassi@gmail.com>
Mon, 4 May 2026 22:41:10 +0000 (23:41 +0100)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Tue, 5 May 2026 08:45:04 +0000 (10:45 +0200)
TEST-06-SELINUX occasionally fails because repeated nspawn invocations use
the same machine name and scope:

TEST-06-SELINUX.sh[598]: Failed to allocate scope: Unit H.scope was already loaded or has a fragment file.

Use a different machine name/scope for each invocation in the test
case to avoid hitting this issue

test/units/TEST-06-SELINUX.sh

index 5cf6e80815b125154d8e37d5ce6f9313aa90dd84..76f5c1652bf0731ca5ba49202fb92f7a26ed3462 100755 (executable)
@@ -39,12 +39,13 @@ CONTEXT="$(stat -c %C /proc/sys/kernel/core_pattern)"
 (! systemd-run --wait --pipe -p ConditionSecurity='selinux' false)
 systemd-run --wait --pipe -p ConditionSecurity='!selinux' false
 
+# Pass a unique --machine= name on each invocation to avoid "already loaded" flakiness
 NSPAWN_ARGS=(systemd-nspawn -q --volatile=yes --directory=/ --bind-ro=/etc --inaccessible=/etc/machine-id)
-[[ "$("${NSPAWN_ARGS[@]}" cat /proc/self/attr/current | tr -d '\0')" != "$CONTEXT" ]]
-[[ "$("${NSPAWN_ARGS[@]}" --selinux-context="$CONTEXT" cat /proc/self/attr/current | tr -d '\0')" == "$CONTEXT" ]]
-[[ "$("${NSPAWN_ARGS[@]}" stat --printf %C /run)" != "$CONTEXT" ]]
-[[ "$("${NSPAWN_ARGS[@]}" --selinux-apifs-context="$CONTEXT" stat --printf %C /run)" == "$CONTEXT" ]]
-[[ "$("${NSPAWN_ARGS[@]}" --selinux-apifs-context="$CONTEXT" --tmpfs=/tmp stat --printf %C /tmp)" == "$CONTEXT" ]]
+[[ "$("${NSPAWN_ARGS[@]}" --machine="nspawn-test-0" cat /proc/self/attr/current | tr -d '\0')" != "$CONTEXT" ]]
+[[ "$("${NSPAWN_ARGS[@]}" --machine="nspawn-test-1" --selinux-context="$CONTEXT" cat /proc/self/attr/current | tr -d '\0')" == "$CONTEXT" ]]
+[[ "$("${NSPAWN_ARGS[@]}" --machine="nspawn-test-2" stat --printf %C /run)" != "$CONTEXT" ]]
+[[ "$("${NSPAWN_ARGS[@]}" --machine="nspawn-test-3" --selinux-apifs-context="$CONTEXT" stat --printf %C /run)" == "$CONTEXT" ]]
+[[ "$("${NSPAWN_ARGS[@]}" --machine="nspawn-test-4" --selinux-apifs-context="$CONTEXT" --tmpfs=/tmp stat --printf %C /tmp)" == "$CONTEXT" ]]
 
 if [[ -n "${TEST_SELINUX_CHECK_AVCS:-}" ]] && ((TEST_SELINUX_CHECK_AVCS)); then
     (! journalctl -t audit -g AVC -o cat)