From: Frantisek Sumsal Date: Wed, 17 May 2023 17:10:55 +0000 (+0200) Subject: test: get rid of the busybox stuff X-Git-Tag: v254-rc1~454^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5656759d0617594ee8e850a258a21d3e187bf02c;p=thirdparty%2Fsystemd.git test: get rid of the busybox stuff It already required a lot of workarounds, since the busybox utilities often work differently than their "full" counterparts, and putting the container together using our "tools" is quite simple anyway. --- diff --git a/test/TEST-13-NSPAWN/test.sh b/test/TEST-13-NSPAWN/test.sh index 8bf33ceb12e..47862f1dc2a 100755 --- a/test/TEST-13-NSPAWN/test.sh +++ b/test/TEST-13-NSPAWN/test.sh @@ -11,19 +11,34 @@ TEST_NO_NSPAWN=1 test_append_files() { local workspace="${1:?}" + local container="$workspace/testsuite-13-container-template" - # On openSUSE the static linked version of busybox is named "busybox-static". - busybox="$(type -P busybox-static || type -P busybox)" - inst_simple "$busybox" "$(dirname "$busybox")/busybox" + # Create a dummy container "template" with a minimal toolset, which we can + # then use as a base for our nspawn/machinectl tests + initdir="$container" setup_basic_dirs + initdir="$container" image_install \ + bash \ + cat \ + hostname \ + grep \ + ip \ + ls \ + md5sum \ + mountpoint \ + nc \ + ps \ + seq \ + sleep \ + stat \ + touch - if command -v selinuxenabled >/dev/null && selinuxenabled; then - image_install chcon selinuxenabled - cp -ar /etc/selinux "$workspace/etc/selinux" - sed -i "s/^SELINUX=.*$/SELINUX=permissive/" "$workspace/etc/selinux/config" - fi - - "$TEST_BASE_DIR/create-busybox-container" "$workspace/testsuite-13.nc-container" - initdir="$workspace/testsuite-13.nc-container" image_install nc ip md5sum + cp /etc/os-release "$container/usr/lib/os-release" + cat >"$container/sbin/init" <"$root/usr/bin/getent" <<\EOF -#!/bin/sh - -if [[ $# - eq 0 ]]; then - : -elif [[ $1 == passwd ]]; then - echo "testuser:x:1000:1000:testuser:/:/bin/sh" -elif [[ $1 == initgroups ]]; then - echo "testuser" -fi -EOF -chmod +x "$root/usr/bin/getent" - -mkdir -p "$root/usr/sbin" -cat >"$root/usr/sbin/init" <<\EOF -#!/bin/sh - -printf "ps aufx:\n" -ps aufx - -printf "/proc/1/cmdline:\n" -printf "%s\n\n" "$(tr '\0' ' ' /var/lib/machines/long-running/sbin/init <<\EOF -#!/bin/sh -x -# +#!/usr/bin/bash -x + PID=0 -# sh doesn't recognize RTMIN+4, so we have to use the signal number directly -trap "touch /poweroff" 38 +trap "touch /poweroff" RTMIN+4 trap "touch /reboot" INT trap "touch /trap" TRAP trap 'kill $PID' EXIT @@ -82,24 +82,24 @@ machinectl disable long-running test ! -L /etc/systemd/system/machines.target.wants/systemd-nspawn@long-running.service machinectl disable long-running long-running long-running container1 -[[ "$(machinectl shell testuser@ /bin/sh -c 'echo -ne $FOO')" == "" ]] -[[ "$(machinectl shell --setenv=FOO=bar testuser@ /bin/sh -c 'echo -ne $FOO')" == "bar" ]] +[[ "$(machinectl shell testuser@ /usr/bin/bash -c 'echo -ne $FOO')" == "" ]] +[[ "$(machinectl shell --setenv=FOO=bar testuser@ /usr/bin/bash -c 'echo -ne $FOO')" == "bar" ]] [[ "$(machinectl show --property=State --value long-running)" == "running" ]] # Equivalent to machinectl kill --signal=SIGRTMIN+4 --kill-whom=leader rm -f /var/lib/machines/long-running/poweroff machinectl poweroff long-running -timeout 10 sh -c "while ! test -e /var/lib/machines/long-running/poweroff; do sleep .5; done" +timeout 10 bash -c "while ! test -e /var/lib/machines/long-running/poweroff; do sleep .5; done" machinectl poweroff long-running long-running long-running # Equivalent to machinectl kill --signal=SIGINT --kill-whom=leader rm -f /var/lib/machines/long-running/reboot machinectl reboot long-running -timeout 10 sh -c "while ! test -e /var/lib/machines/long-running/reboot; do sleep .5; done" +timeout 10 bash -c "while ! test -e /var/lib/machines/long-running/reboot; do sleep .5; done" machinectl reboot long-running long-running long-running # Skip machinectl terminate for now, as it doesn't play well with our "init" rm -f /var/lib/machines/long-running/trap machinectl kill --signal=SIGTRAP --kill-whom=leader long-running -timeout 10 sh -c "while ! test -e /var/lib/machines/long-running/trap; do sleep .5; done" +timeout 10 bash -c "while ! test -e /var/lib/machines/long-running/trap; do sleep .5; done" machinectl kill --signal=SIGTRAP --kill-whom=leader long-running long-running long-running # All used signals should've been caught by a handler [[ "$(machinectl show --property=State --value long-running)" == "running" ]] @@ -181,7 +181,7 @@ machinectl import-fs /tmp/container.dir container-dir machinectl start container-dir rm -fr /tmp/container.dir -timeout 10 sh -c "while ! machinectl clean --all; do sleep .5; done" +timeout 10 bash -c "while ! machinectl clean --all; do sleep .5; done" NSPAWN_FRAGMENT="machinectl-test-$RANDOM.nspawn" cat >"/var/lib/machines/$NSPAWN_FRAGMENT" <"$OCI/config.json" <"$OCI/config.json" <"$OCI/rootfs/entrypoint.sh" <"$root/bin/getent" <<\EOF +#!/bin/bash + +if [[ $# -eq 0 ]]; then + : +elif [[ $1 == passwd ]]; then + echo "testuser:x:1000:1000:testuser:/:/bin/sh" +elif [[ $1 == initgroups ]]; then + echo "testuser" +fi +EOF + chmod +x "$root/bin/getent" + systemd-nspawn --directory="$root" bash -xec '[[ $USER == root ]]' + systemd-nspawn --directory="$root" --user=testuser bash -xec '[[ $USER == testuser ]]' # --settings= + .nspawn files mkdir -p /run/systemd/nspawn/ @@ -146,22 +162,22 @@ testcase_sanity_check() { systemd-nspawn --directory="$root" \ --machine=foo-bar \ --settings=yes \ - sh -xec '[[ $container_uuid == deadbeef-dead-dead-beef-111111111111 ]]' + bash -xec '[[ $container_uuid == deadbeef-dead-dead-beef-111111111111 ]]' systemd-nspawn --directory="$root" \ --machine=foo-bar \ --uuid="$uuid" \ --settings=yes \ - sh -xec "[[ \$container_uuid == $uuid ]]" + bash -xec "[[ \$container_uuid == $uuid ]]" systemd-nspawn --directory="$root" \ --machine=foo-bar \ --uuid="$uuid" \ --settings=override \ - sh -xec '[[ $container_uuid == deadbeef-dead-dead-beef-111111111111 ]]' + bash -xec '[[ $container_uuid == deadbeef-dead-dead-beef-111111111111 ]]' systemd-nspawn --directory="$root" \ --machine=foo-bar \ --uuid="$uuid" \ --settings=trusted \ - sh -xec "[[ \$container_uuid == $uuid ]]" + bash -xec "[[ \$container_uuid == $uuid ]]" # Mounts mkdir "$tmpdir"/{1,2,3} @@ -170,35 +186,35 @@ testcase_sanity_check() { # --bind= systemd-nspawn --directory="$root" \ --bind="$tmpdir:/foo" \ - sh -xec 'test -e /foo/foo; touch /foo/bar' + bash -xec 'test -e /foo/foo; touch /foo/bar' test -e "$tmpdir/bar" # --bind-ro= systemd-nspawn --directory="$root" \ --bind-ro="$tmpdir:/foo" \ - sh -xec 'test -e /foo/foo; touch /foo/baz && exit 1; true' + bash -xec 'test -e /foo/foo; touch /foo/baz && exit 1; true' # --inaccessible= systemd-nspawn --directory="$root" \ --inaccessible=/var \ - sh -xec 'touch /var/foo && exit 1; true' + bash -xec 'touch /var/foo && exit 1; true' # --tmpfs= systemd-nspawn --directory="$root" \ --tmpfs=/var:rw,nosuid,noexec \ - sh -xec 'touch /var/nope' + bash -xec 'touch /var/nope' test ! -e "$root/var/nope" # --overlay= systemd-nspawn --directory="$root" \ --overlay="$tmpdir/1:$tmpdir/2:$tmpdir/3:/var" \ - sh -xec 'test -e /var/one; test -e /var/two; test -e /var/three; touch /var/foo' + bash -xec 'test -e /var/one; test -e /var/two; test -e /var/three; touch /var/foo' test -e "$tmpdir/3/foo" # --overlay-ro= systemd-nspawn --directory="$root" \ --overlay-ro="$tmpdir/1:$tmpdir/2:$tmpdir/3:/var" \ - sh -xec 'test -e /var/one; test -e /var/two; test -e /var/three; touch /var/nope && exit 1; true' + bash -xec 'test -e /var/one; test -e /var/two; test -e /var/three; touch /var/nope && exit 1; true' test ! -e "$tmpdir/3/nope" rm -fr "$tmpdir" # Assorted tests - systemd-nspawn --directory="$root" --suppress-sync=yes sh -xec 'echo hello' + systemd-nspawn --directory="$root" --suppress-sync=yes bash -xec 'echo hello' systemd-nspawn --capability=help systemd-nspawn --resolv-conf=help systemd-nspawn --timezone=help @@ -252,12 +268,12 @@ testcase_check_bind_tmp_path() { local root root="$(mktemp -d /var/lib/machines/testsuite-13.bind-tmp-path.XXX)" - "$CREATE_BB_CONTAINER" "$root" + create_dummy_container "$root" : >/tmp/bind systemd-nspawn --register=no \ --directory="$root" \ --bind=/tmp/bind \ - /bin/sh -c 'test -e /tmp/bind' + bash -c 'test -e /tmp/bind' rm -fr "$root" /tmp/bind } @@ -271,12 +287,12 @@ testcase_check_norbind() { echo -n "outer" >/tmp/binddir/subdir/file mount -t tmpfs tmpfs /tmp/binddir/subdir echo -n "inner" >/tmp/binddir/subdir/file - "$CREATE_BB_CONTAINER" "$root" + create_dummy_container "$root" systemd-nspawn --register=no \ --directory="$root" \ --bind=/tmp/binddir:/mnt:norbind \ - /bin/sh -c 'CONTENT=$(cat /mnt/subdir/file); if [[ $CONTENT != "outer" ]]; then echo "*** unexpected content: $CONTENT"; return 1; fi' + bash -c 'CONTENT=$(cat /mnt/subdir/file); if [[ $CONTENT != "outer" ]]; then echo "*** unexpected content: $CONTENT"; exit 1; fi' umount /tmp/binddir/subdir rm -fr "$root" /tmp/binddir/ @@ -304,13 +320,13 @@ testcase_check_rootidmap() { touch /tmp/rootidmap/bind/file chown -R "$owner:$owner" /tmp/rootidmap/bind - "$CREATE_BB_CONTAINER" "$root" + create_dummy_container "$root" cmd='PERMISSIONS=$(stat -c "%u:%g" /mnt/file); if [[ $PERMISSIONS != "0:0" ]]; then echo "*** wrong permissions: $PERMISSIONS"; return 1; fi; touch /mnt/other_file' if ! SYSTEMD_LOG_TARGET=console \ systemd-nspawn --register=no \ --directory="$root" \ --bind=/tmp/rootidmap/bind:/mnt:rootidmap \ - /bin/sh -c "$cmd" |& tee nspawn.out; then + bash -c "$cmd" |& tee nspawn.out; then if grep -q "Failed to map ids for bind mount.*: Function not implemented" nspawn.out; then echo "idmapped mounts are not supported, skipping the test..." return 0 @@ -328,21 +344,24 @@ testcase_check_rootidmap() { testcase_check_notification_socket() { # https://github.com/systemd/systemd/issues/4944 - local cmd='echo a | $(busybox which nc) -U -u -w 1 /run/host/notify' + local root + local cmd='echo a | nc -U -u -w 1 /run/host/notify' + + root="$(mktemp -d /var/lib/machines/testsuite-13.check_notification_socket.XXX)" + create_dummy_container "$root" - # /testsuite-13.nc-container is prepared by test.sh - systemd-nspawn --register=no --directory=/testsuite-13.nc-container /bin/sh -x -c "$cmd" - systemd-nspawn --register=no --directory=/testsuite-13.nc-container -U /bin/sh -x -c "$cmd" + systemd-nspawn --register=no --directory="$root" bash -x -c "$cmd" + systemd-nspawn --register=no --directory="$root" -U bash -x -c "$cmd" } testcase_check_os_release() { local root entrypoint os_release_source root="$(mktemp -d /var/lib/machines/testsuite-13.check-os-release.XXX)" - "$CREATE_BB_CONTAINER" "$root" + create_dummy_container "$root" entrypoint="$root/entrypoint.sh" cat >"$entrypoint" <<\EOF -#!/bin/sh -ex +#!/usr/bin/bash -ex . /tmp/os-release [[ -n "${ID:-}" && "$ID" != "$container_host_id" ]] && exit 1 @@ -378,18 +397,18 @@ EOF testcase_check_machinectl_bind() { local service_path service_name root container_name ec - local cmd='for i in $(seq 1 20); do if test -f /tmp/marker; then exit 0; fi; usleep 500000; done; exit 1;' + local cmd='for i in $(seq 1 20); do if test -f /tmp/marker; then exit 0; fi; sleep .5; done; exit 1;' root="$(mktemp -d /var/lib/machines/testsuite-13.check-machinectl-bind.XXX)" - "$CREATE_BB_CONTAINER" "$root" - container_name="${root##*/}" + create_dummy_container "$root" + container_name="$(basename "$root")" service_path="$(mktemp /run/systemd/system/nspawn-machinectl-bind-XXX.service)" service_name="${service_path##*/}" cat >"$service_path" <&2 "Missing container template, probably not running in TEST-13-NSPAWN?" + exit 1 + fi + + mkdir -p "$root" + cp -a /testsuite-13-container-template/* "$root" +}