]> git.proxmox.com Git - ifupdown-pve.git/blob - debian/tests/hotplug
Squashed 'src/' content from commit c732260
[ifupdown-pve.git] / debian / tests / hotplug
1 #!/bin/sh
2 # check behaviour of "allow-hotplug" interface
3 set -e
4
5 IFACE=sdtest42
6
7 if [ -e /sys/class/net/$IFACE ]; then
8 echo "SKIP: network interface $IFACE already exists"
9 exit 0
10 fi
11
12 # different kinds of installs/images have different conventions; e. g.
13 # cloud-init sources *.cfg, a Debian desktop sources only prefix-less files
14 if grep -q 'source-directory .*interfaces.d' /etc/network/interfaces; then
15 IFACE_CFG=/etc/network/interfaces.d/${IFACE}
16 elif grep -q 'source .*interfaces.d.*cfg' /etc/network/interfaces; then
17 IFACE_CFG=/etc/network/interfaces.d/${IFACE}.cfg
18 else
19 echo "SKIP: /etc/network/interfaces does not include interfaces.d/"
20 exit 0
21 fi
22
23 cat <<EOF > $IFACE_CFG
24 allow-hotplug $IFACE
25 iface $IFACE inet static
26 address 192.168.234.129
27 netmask 255.255.255.0
28 EOF
29
30 # these should trigger uevents and ifup@.service
31 ip link add name $IFACE type veth peer name v$IFACE
32 trap "ip link del dev $IFACE; rm $IFACE_CFG" EXIT INT QUIT PIPE
33
34 sleep 3
35
36 # $IFACE is configured in ifupdown, should succeed and be up
37 ifquery --state $IFACE
38 if [ -d /run/systemd/system ]; then
39 systemctl status -l ifup@${IFACE}.service
40 fi
41
42 OUT=$(ip a show dev $IFACE)
43 if ! echo "$OUT" | grep -q 'inet 192.168.234.129/24'; then
44 echo "interface $IFACE not configured" >&2
45 echo "$OUT" >&2
46 exit 1
47 fi
48
49 # v$IFACE is not configured in ifupdown, should be down
50 ! ifquery --state v$IFACE
51 if [ -d /run/systemd/system ]; then
52 ! systemctl status -l ifup@v${IFACE}.service
53 fi
54
55 OUT=$(ip a show dev v$IFACE)
56 if echo "$OUT" | grep -q 'inet'; then
57 echo "interface $IFACE unexpectedly configured" >&2
58 echo "$OUT" >&2
59 exit 1
60 fi