From abf062674ea04b9f0fe5a05b4daeacea74a5b53b Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Tue, 3 Aug 2021 08:18:13 +0200 Subject: [PATCH 1/7] test: add support for NO_BUILD=1 on openSUSE --- test/test-functions | 49 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/test/test-functions b/test/test-functions index abe421c505c..0dc8837e464 100644 --- a/test/test-functions +++ b/test/test-functions @@ -935,11 +935,52 @@ install_debian_systemd() { done < <(grep -E '^Package:' "${SOURCE_DIR}/debian/control" | cut -d ':' -f 2) } +install_suse_systemd() { + local testsdir=/usr/lib/systemd/tests + local pkgs + + dinfo "Install SUSE systemd" + + pkgs=( + systemd + systemd-container + systemd-coredump + systemd-experimental + systemd-journal-remote + systemd-portable + udev + ) + + for p in "${pkgs[@]}"; do + rpm -q "$p" &>/dev/null || continue + + ddebug "Install files from package $p" + while read -r f; do + [ -e "$f" ] || continue + [ -d "$f" ] && continue + inst "$f" + done < <(rpm -ql "$p") + done + + # we only need testsdata dir as well as the unit tests (for + # TEST-02-UNITTESTS) in the image. + dinfo "Install unit tests and testdata directory" + + mkdir -p "$initdir/$testsdir" + cp "$testsdir"/test-* "$initdir/$testsdir/" + cp -a "$testsdir/testdata" "$initdir/$testsdir/" + + # On openSUSE, these dirs are not created at package install for now on. + mkdir -p "$initdir/var/log/journal/remote" +} + install_distro_systemd() { dinfo "Install distro systemd" if get_bool "$LOOKS_LIKE_DEBIAN"; then install_debian_systemd + elif get_bool "$LOOKS_LIKE_SUSE"; then + install_suse_systemd else dfatal "NO_BUILD not supported for this distro" exit 1 @@ -957,8 +998,6 @@ install_systemd() { # remove unneeded documentation rm -fr "$initdir"/usr/share/{man,doc} - get_bool "$LOOKS_LIKE_SUSE" && setup_suse - # enable debug logging in PID1 echo LogLevel=debug >>"$initdir/etc/systemd/system.conf" # store coredumps in journal @@ -2405,12 +2444,6 @@ instmods() { return 0 } -setup_suse() { - ln -fs ../usr/bin/systemctl "${initdir:?}/bin/" - ln -fs ../usr/lib/systemd "$initdir/lib/" - inst_simple "/usr/lib/systemd/system/haveged.service" -} - _umount_dir() { local mountpoint="${1:?}" if mountpoint -q "$mountpoint"; then From dfd73ccb14e6839df7d8633984c382d01d630b3f Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Tue, 3 Aug 2021 08:44:47 +0200 Subject: [PATCH 2/7] test: don't try to find BUILD_DIR when NO_BUILD is set NO_BUILD=1 indicates that we want to test systemd from the local system and not the one from the local build. Hence there should be no need to call find-build-dir.sh when NO_BUID=1 especially since it's likely that the script will fail to find a local build in this case. This avoids find-build-dir.sh to emit 'Specify build directory with $BUILD_DIR' message when NO_BUILD=1 and no local build can be found. This introduces a behavior change though: systemd from the local system will always be preferred when NO_BUILD=1 even if a local build can be found. --- test/test-functions | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/test/test-functions b/test/test-functions index 0dc8837e464..fe3081106fe 100644 --- a/test/test-functions +++ b/test/test-functions @@ -83,13 +83,11 @@ TOOLS_DIR="$SOURCE_DIR/tools" export TEST_BASE_DIR TEST_UNITS_DIR SOURCE_DIR TOOLS_DIR # note that find-build-dir.sh will return $BUILD_DIR if provided, else it will try to find it -if ! BUILD_DIR="$("$TOOLS_DIR"/find-build-dir.sh)"; then - if get_bool "${NO_BUILD:=}"; then - BUILD_DIR="$SOURCE_DIR" - else - echo "ERROR: no build found, please set BUILD_DIR or use NO_BUILD" >&2 - exit 1 - fi +if get_bool "${NO_BUILD:=}"; then + BUILD_DIR="$SOURCE_DIR" +elif ! BUILD_DIR="$("$TOOLS_DIR"/find-build-dir.sh)"; then + echo "ERROR: no build found, please set BUILD_DIR or use NO_BUILD" >&2 + exit 1 fi PATH_TO_INIT="$ROOTLIBDIR/systemd" From 6c8ba239d534ebdd124993e7a2e2bbc9d672d695 Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Thu, 5 Aug 2021 08:38:27 +0200 Subject: [PATCH 3/7] TEST-13-*: in busybox container sleep(1) takes a delay in seconds only --- test/create-busybox-container | 1 + test/units/testsuite-13.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/test/create-busybox-container b/test/create-busybox-container index b2b7b262940..27897cded2b 100755 --- a/test/create-busybox-container +++ b/test/create-busybox-container @@ -30,6 +30,7 @@ ln -s busybox "$root/bin/ps" ln -s busybox "$root/bin/ip" ln -s busybox "$root/bin/seq" ln -s busybox "$root/bin/sleep" +ln -s busybox "$root/bin/usleep" ln -s busybox "$root/bin/test" mkdir -p "$root/sbin" diff --git a/test/units/testsuite-13.sh b/test/units/testsuite-13.sh index 8f3c0b2df83..7a6723953a4 100755 --- a/test/units/testsuite-13.sh +++ b/test/units/testsuite-13.sh @@ -93,7 +93,7 @@ if echo test >>/run/host/os-release; then exit 1; fi } function check_machinectl_bind { - local _cmd='for i in $(seq 1 20); do if test -f /tmp/marker; then exit 0; fi; sleep 0.5; done; exit 1;' + local _cmd='for i in $(seq 1 20); do if test -f /tmp/marker; then exit 0; fi; usleep 500000; done; exit 1;' cat >/run/systemd/system/nspawn_machinectl_bind.service < Date: Sun, 8 Aug 2021 07:35:04 +0200 Subject: [PATCH 4/7] test: on openSUSE the static linked version of busybox is named "busybox-static" --- test/TEST-13-NSPAWN-SMOKE/test.sh | 5 ++++- test/create-busybox-container | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/test/TEST-13-NSPAWN-SMOKE/test.sh b/test/TEST-13-NSPAWN-SMOKE/test.sh index 8455cc60adf..faba5ba0c49 100755 --- a/test/TEST-13-NSPAWN-SMOKE/test.sh +++ b/test/TEST-13-NSPAWN-SMOKE/test.sh @@ -11,7 +11,10 @@ TEST_NO_NSPAWN=1 test_append_files() { ( local workspace="${1:?}" - dracut_install busybox + + # 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" if selinuxenabled >/dev/null; then dracut_install selinuxenabled diff --git a/test/create-busybox-container b/test/create-busybox-container index 27897cded2b..3ceb23eb91a 100755 --- a/test/create-busybox-container +++ b/test/create-busybox-container @@ -7,7 +7,10 @@ set -o pipefail root="${1:?Usage $0 container-root}" mkdir -p "$root" mkdir "$root/bin" -cp $(type -P busybox) "$root/bin" + +# On openSUSE the static linked version of busybox is named "busybox-static". +busybox="$(type -P busybox-static || type -P busybox)" +cp "$busybox" "$root/bin/busybox" os_release=$(test -e /etc/os-release && echo /etc/os-release || echo /usr/lib/os-release) ID_LIKE=$(awk -F= '$1=="ID_LIKE" { print $2 ;}' $os_release) From d8167c5212ee5100aebe3d5cee499bac505d1080 Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Tue, 3 Aug 2021 12:18:40 +0200 Subject: [PATCH 5/7] Revert "test: adapt TEST-13-NSPAWN-SMOKE for SUSE" This reverts commit 491b736a49fb9d64b0b515aa773297a30c8bab1d. If the _static_ linked version of busybox is installed, openSUSE doesn't need any specific code. A following commit will make sure that the static linked version of busybox is installed in the busybox container. --- test/create-busybox-container | 11 ----------- test/units/testsuite-13.sh | 30 ++++++++++++------------------ 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/test/create-busybox-container b/test/create-busybox-container index 3ceb23eb91a..b6f34b47ecf 100755 --- a/test/create-busybox-container +++ b/test/create-busybox-container @@ -12,17 +12,6 @@ mkdir "$root/bin" busybox="$(type -P busybox-static || type -P busybox)" cp "$busybox" "$root/bin/busybox" -os_release=$(test -e /etc/os-release && echo /etc/os-release || echo /usr/lib/os-release) -ID_LIKE=$(awk -F= '$1=="ID_LIKE" { print $2 ;}' $os_release) -if [[ "$ID_LIKE" = *"suse"* ]]; then - mkdir -p "$root/lib" - mkdir -p "$root/lib64" - for lib in $(find /lib*/ld*); do - [[ -d $root/$(dirname $lib) ]] || mkdir -p $root/$(dirname $lib) - cp $lib $root/$lib - done -fi - mkdir -p "$root/usr/lib" touch "$root/usr/lib/os-release" diff --git a/test/units/testsuite-13.sh b/test/units/testsuite-13.sh index 7a6723953a4..3f5a5427386 100755 --- a/test/units/testsuite-13.sh +++ b/test/units/testsuite-13.sh @@ -30,19 +30,13 @@ if unshare -U sh -c :; then is_user_ns_supported=yes fi -SUSE_OPTS=() -ID_LIKE=$(awk -F= '$1=="ID_LIKE" { print $2 ;}' /etc/os-release) -if [[ "$ID_LIKE" = *"suse"* ]]; then - SUSE_OPTS+=(--bind /lib64 --bind /usr/lib64) -fi - function check_bind_tmp_path { # https://github.com/systemd/systemd/issues/4789 local _root="/var/lib/machines/testsuite-13.bind-tmp-path" rm -rf "$_root" /usr/lib/systemd/tests/testdata/create-busybox-container "$_root" : >/tmp/bind - systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D "$_root" --bind=/tmp/bind /bin/sh -c 'test -e /tmp/bind' + systemd-nspawn --register=no -D "$_root" --bind=/tmp/bind /bin/sh -c 'test -e /tmp/bind' } function check_norbind { @@ -54,15 +48,15 @@ function check_norbind { mount -t tmpfs tmpfs /tmp/binddir/subdir echo -n "inner" >/tmp/binddir/subdir/file /usr/lib/systemd/tests/testdata/create-busybox-container "$_root" - systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D "$_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' + systemd-nspawn --register=no -D "$_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' } function check_notification_socket { # https://github.com/systemd/systemd/issues/4944 local _cmd='echo a | $(busybox which nc) -U -u -w 1 /run/host/notify' # /testsuite-13.nc-container is prepared by test.sh - systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D /testsuite-13.nc-container /bin/sh -x -c "$_cmd" - systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D /testsuite-13.nc-container -U /bin/sh -x -c "$_cmd" + systemd-nspawn --register=no -D /testsuite-13.nc-container /bin/sh -x -c "$_cmd" + systemd-nspawn --register=no -D /testsuite-13.nc-container -U /bin/sh -x -c "$_cmd" } function check_os_release { @@ -84,7 +78,7 @@ if echo test >>/run/host/os-release; then exit 1; fi echo MARKER=1 >>/etc/os-release fi - systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D /testsuite-13.nc-container --bind="${_os_release_source}":/tmp/os-release /bin/sh -x -e -c "$_cmd" + systemd-nspawn --register=no -D /testsuite-13.nc-container --bind="${_os_release_source}":/tmp/os-release /bin/sh -x -e -c "$_cmd" if grep -q MARKER /etc/os-release; then rm /etc/os-release @@ -138,16 +132,16 @@ function run { local _root="/var/lib/machines/testsuite-13.unified-$1-cgns-$2-api-vfs-writable-$3" rm -rf "$_root" /usr/lib/systemd/tests/testdata/create-busybox-container "$_root" - SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D "$_root" -b - SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D "$_root" --private-network -b + SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" -b + SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" --private-network -b - if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D "$_root" -U -b; then + if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" -U -b; then [[ "$is_user_ns_supported" = "yes" && "$3" = "network" ]] && return 1 else [[ "$is_user_ns_supported" = "no" && "$3" = "network" ]] && return 1 fi - if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D "$_root" --private-network -U -b; then + if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" --private-network -U -b; then [[ "$is_user_ns_supported" = "yes" && "$3" = "yes" ]] && return 1 else [[ "$is_user_ns_supported" = "no" && "$3" = "yes" ]] && return 1 @@ -167,21 +161,21 @@ function run { # --network-namespace-path and network-related options cannot be used together for netopt in "${_net_opts[@]}"; do echo "$_netns_opt in combination with $netopt should fail" - if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D "$_root" -b "$_netns_opt" "$netopt"; then + if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" -b "$_netns_opt" "$netopt"; then echo >&2 "unexpected pass" return 1 fi done # allow combination of --network-namespace-path and --private-network - if ! SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D "$_root" -b "$_netns_opt" --private-network; then + if ! SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" -b "$_netns_opt" --private-network; then return 1 fi # test --network-namespace-path works with a network namespace created by "ip netns" ip netns add nspawn_test _netns_opt="--network-namespace-path=/run/netns/nspawn_test" - SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn "${SUSE_OPTS[@]}" --register=no -D "$_root" "$_netns_opt" /bin/ip a | grep -v -E '^1: lo.*UP' + SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" /bin/ip a | grep -v -E '^1: lo.*UP' local r=$? ip netns del nspawn_test From 138f761904d8630adc2b333ae43e309577d6f65a Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Thu, 5 Aug 2021 15:34:37 +0200 Subject: [PATCH 6/7] test: adapt install_pam() for openSUSE On openSUSE the default pam config files are shipped in /usr/etc/pam.d. Also empty password is not allowed by default. --- test/test-functions | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/test-functions b/test/test-functions index fe3081106fe..8b8c89a2062 100644 --- a/test/test-functions +++ b/test/test-functions @@ -1587,7 +1587,7 @@ install_pam() { paths+=(/lib*/security) fi - for d in /etc/pam.d /etc/security /usr/lib/pam.d; do + for d in /etc/pam.d /etc/security /usr/{etc,lib}/pam.d; do [ -d "$d" ] && paths+=("$d") done @@ -1601,6 +1601,13 @@ install_pam() { # set empty root password for easy debugging sed -i 's/^root:x:/root::/' "${initdir:?}/etc/passwd" + + # And make sure pam_unix will accept it by making sure that + # the PAM module has the nullok option. + for d in /etc/pam.d /usr/{etc,lib}/pam.d; do + [ -d "$initdir/$d" ] || continue + sed -i '/^auth.*pam_unix.so/s/$/ nullok/' "$initdir/$d"/* + done } install_keymaps() { From d93857ae096c70c462da167d36b3c51269070028 Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Fri, 6 Aug 2021 16:47:32 +0200 Subject: [PATCH 7/7] test: if haveged is part of initrd it needs to be installed in the image too Otherwise haveged won't survive when switching root from initrd to host making haveged service in host fail. --- test/test-functions | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/test-functions b/test/test-functions index 8b8c89a2062..fc545302715 100644 --- a/test/test-functions +++ b/test/test-functions @@ -664,6 +664,7 @@ setup_basic_environment() { install_fs_tools install_modules install_plymouth + install_haveged install_debug_tools install_ld_so_conf install_testuser @@ -1426,6 +1427,16 @@ install_plymouth() { # fi } +install_haveged() { + # If haveged is installed and probably included in initrd, it needs to be + # installed in the image too. + if [ -x /usr/sbin/haveged ]; then + dinfo "Install haveged files" + inst /usr/sbin/haveged + inst /usr/lib/systemd/system/haveged.service + fi +} + install_ld_so_conf() { dinfo "Install /etc/ld.so.conf*" cp -a /etc/ld.so.conf* "${initdir:?}/etc"