# -*- shell-script -*- # Copyright 2021-2022 Ian Jackson and contributors to Hippotat # SPDX-License-Identifier: GPL-3.0-or-later WITH LicenseRef-Hippotat-OpenSSL-Exception # There is NO WARRANTY. set -o pipefail set -x . "${0%/*}"/../test/tcommon on_failure=: test-prep () { trap ' rc=$? : =================== ^^ TEST FAILURE ^^ ==================== set +e tail -500 /var/log/daemon.log $on_failure exit $rc ' 0 determine-tname adt if [ "$AUTOPKGTEST_TMP" ]; then tmp=$AUTOPKGTEST_TMP else tmp=$PWD/tmp/$tname hosts-cleanup mkdir -p tmp rm -rf "$tmp" mkdir "$tmp" fi } filesystem-prep () { cs=$1; shift # expects $tmp to be set to test-specific temp dir (abs path) host-cleanup $cs mkdir "$tmp"/$cs-overlay for fs in root dev home; do case "$fs" in root) lower=/ ;; dev) lower=/dev ;; home) lower=/home ;; *) x-internal-error ;; esac rm -rf "$tmp"/$cs-$fs-{upper,work} mkdir "$tmp"/$cs-$fs-{upper,work} mount -t overlay -o \ lowerdir=$lower,upperdir="$tmp"/$cs-$fs-upper,workdir="$tmp"/$cs-$fs-work \ none "$tmp"/$cs-overlay$lower done } hosts-cleanup () { host-cleanup client host-cleanup server } host-cleanup () { cs=$1; shift fuser -Mkm "$tmp"/$cs-overlay ||: umount "$tmp"/$cs-overlay/proc ||: umount "$tmp"/$cs-overlay/dev ||: umount "$tmp"/$cs-overlay/home ||: umount "$tmp"/$cs-overlay ||: umount "$tmp"/$cs-pidns ||: if test -d "$tmp"/$cs-overlay; then rmdir "$tmp"/$cs-overlay fi } pidnamespace-prep () { cs=$1; shift touch "$tmp"/$cs-pidns rm -f "$tmp"/$cs-overlay/adt-pidns-sentinel mkfifo -m 600 "$tmp"/$cs-overlay/adt-pidns-sentinel unshare --fork --pid="$tmp"/$cs-pidns \ chroot "$tmp"/$cs-overlay \ sh -ec ' mount -t proc none /proc >/adt-pidns-sentinel sleep 10000000 ' & cat "$tmp"/$cs-overlay/adt-pidns-sentinel } configure () { cs=$1; shift in- $cs dd <$tmp/$cs-unwanted-deps local unwanted_deps=$(perl -ne ' next if m{^(?:userv-utils|libnetaddr-ip-perl|net-tools)$}; next if m{^hippotat-'"$cs"'$}; next if m{^(?:iptables|rsyslog|authbind)$} && '"$cs"' eq "server"; # TODO for rsyslog, record bug number here next if m{^(?:orphan-sysvinit-scripts)$} && '"$cs"' eq "server"; print; ' $tmp/$cs-unwanted-deps) in- $cs apt-mark auto $unwanted_deps in- $cs apt-get -y autoremove in- $cs service userv start configure $cs finish-setup-host-$cs } finish-setup-host-client () { yes '' | \ in- client adduser --disabled-password user ||: in- client adduser user _hippotat } finish-setup-host-server () { in- server iptables -D INPUT -j empty -s 192.0.2.0/24 ||: in- server iptables -N empty ||: in- server iptables -I INPUT -j empty -s 192.0.2.0/24 rsyslog-capture-daemon in- server in- server service rsyslog start } in- () { cs=$1; shift in-ns $cs \ nsenter --pid="$tmp"/$cs-pidns \ chroot "$tmp"/$cs-overlay \ "$@" } setup-pair () { test-prep on_failure=pair-on-failure $test/netns-setup $tname setup-host client setup-host server } pair-on-failure () { tail -500 "$tmp"/server-overlay/var/log/daemon.log ||: hosts-cleanup } rsyslog-capture-daemon () { "$@" dd <