1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
#!/bin/sh
# check behaviour of "allow-hotplug" interface
set -e
date -R
IFACE=sdtest42
IFACE_DUMMY=ethdummy0
if [ -z "$AUTOPKGTEST_REBOOT_MARK" ]; then
if [ -e /sys/class/net/$IFACE ]; then
echo "SKIP: network interface $IFACE already exists"
exit 0
fi
fi
# different kinds of installs/images have different conventions; e. g.
# cloud-init sources *.cfg, a Debian desktop sources only prefix-less files
if grep -q 'source-directory .*interfaces.d' /etc/network/interfaces; then
IFACE_CFG=/etc/network/interfaces.d/${IFACE}
IFACE_DUMMY_CFG=/etc/network/interfaces.d/${IFACE_DUMMY}
elif grep -q 'source .*interfaces.d.*cfg' /etc/network/interfaces; then
IFACE_CFG=/etc/network/interfaces.d/${IFACE}.cfg
IFACE_DUMMY_CFG=/etc/network/interfaces.d/${IFACE_DUMMY}.cfg
elif grep -q 'source .*interfaces.d.*conf' /etc/network/interfaces; then
IFACE_CFG=/etc/network/interfaces.d/${IFACE}.conf
IFACE_DUMMY_CFG=/etc/network/interfaces.d/${IFACE_DUMMY}.conf
else
echo "making /etc/network/interfaces source /e/n/interfaces.d/*.conf"
cat <<EOF > /etc/network/interfaces
source /etc/network/interfaces.d/*.conf
EOF
IFACE_CFG=/etc/network/interfaces.d/${IFACE}.conf
IFACE_DUMMY_CFG=/etc/network/interfaces.d/${IFACE_DUMMY}.conf
fi
if [ -z "$AUTOPKGTEST_REBOOT_MARK" ]; then
cat <<EOF > $IFACE_CFG
allow-hotplug $IFACE
iface $IFACE inet static
address 192.168.234.129
netmask 255.255.255.0
EOF
fi
# these should trigger uevents and ifup@.service
ip link add name $IFACE type veth peer name v$IFACE
trap "ip link del dev $IFACE; rm $IFACE_CFG" EXIT INT QUIT PIPE
sleep 3
# $IFACE is configured in ifupdown, should succeed and be up
ifquery --state $IFACE
if [ -d /run/systemd/system ]; then
systemctl status -l ifup@${IFACE}.service
fi
OUT=$(ip a show dev $IFACE)
if ! echo "$OUT" | grep -q 'inet 192.168.234.129/24'; then
echo "interface $IFACE not configured" >&2
echo "$OUT" >&2
exit 1
fi
# v$IFACE is not configured in ifupdown, should be down
! ifquery --state v$IFACE
if [ -d /run/systemd/system ]; then
! systemctl status -l ifup@v${IFACE}.service
fi
OUT=$(ip a show dev v$IFACE)
if echo "$OUT" | grep -q 'inet'; then
echo "interface $IFACE unexpectedly configured" >&2
echo "$OUT" >&2
exit 1
fi
echo "restarting network"
systemctl restart networking
sleep 3
echo "stop"
systemctl stop networking
if [ -z "$AUTOPKGTEST_REBOOT_MARK" ]; then
echo "adding a dummy unplugged interface"
cat <<EOF > $IFACE_DUMMY_CFG
allow-hotplug $IFACE_DUMMY
iface $IFACE_DUMMY inet dhcp
EOF
fi
echo "start"
systemctl start networking
ip link show
ip a
echo "query"
ifquery $IFACE_DUMMY
echo "query state"
! ifquery --state $IFACE_DUMMY
if [ -d /run/systemd/system ]; then
! systemctl status -l ifup@${IFACE_DUMMY}.service
fi
date -R
if [ -z "$AUTOPKGTEST_REBOOT_MARK" ]; then
echo "preparing to reboot"; /tmp/autopkgtest-reboot mark1
fi
echo "test end"
|