#!/usr/bin/env bash # SPDX-License-Identifier: LGPL-2.1-or-later # shellcheck disable=SC2016 set -eux set -o pipefail # shellcheck source=test/units/util.sh . "$(dirname "$0")"/util.sh at_exit() { set +e machinectl kill --signal=KILL nss-mymachines-{noip,singleip,manyips} mountpoint -q /var/lib/machines && timeout 10 sh -c "until umount /var/lib/machines; do sleep .5; done" rm -f /run/systemd/nspawn/*.nspawn } trap at_exit EXIT mkdir -p /var/lib/machines mount -t tmpfs tmpfs /var/lib/machines # Create a bunch of containers that: # 1) Have no IP addresses assigned create_dummy_container /var/lib/machines/nss-mymachines-noip cat >/var/lib/machines/nss-mymachines-noip/sbin/init <<\EOF #!/usr/bin/bash -ex ip addr show dev ve-noip touch /initialized sleep infinity & # Run the sleep command asynchronously, so bash is able to process signals while :; do wait || : done EOF # 2) Have one IP address assigned (IPv4 only) create_dummy_container /var/lib/machines/nss-mymachines-singleip cat >/var/lib/machines/nss-mymachines-singleip/sbin/init <<\EOF #!/usr/bin/bash -ex ip addr add 10.1.0.2/24 dev ve-singleip ip addr show dev ve-singleip touch /initialized sleep infinity & while :; do wait || : done EOF # 3) Have bunch of IP addresses assigned (both IPv4 and IPv6) create_dummy_container /var/lib/machines/nss-mymachines-manyips cat >/var/lib/machines/nss-mymachines-manyips/sbin/init <<\EOF #!/usr/bin/bash -ex ip addr add 10.2.0.2/24 dev ve-manyips for i in {100..120}; do ip addr add 10.2.0.$i/24 dev ve-manyips done ip addr add fd00:dead:beef:cafe::2/64 dev ve-manyips ip addr show dev ve-manyips touch /initialized sleep infinity while :; do wait || : done EOF # Create the respective .nspawn config files mkdir -p /run/systemd/nspawn for container in noip singleip manyips; do cat >"/run/systemd/nspawn/nss-mymachines-$container.nspawn" <