Debian Codegraph @

debian/tests/qemu-net

raw
1 #!/bin/sh
2 set -eu
3
4 # Some simple tests of the initramfs network configuration.
5
6 # The basic idea is to make an ext2 root image that only ships a /sbin/init to
7 # just gather some data and shutdown again and boot it in qemu system
8 # emulation (not KVM, so it can be run in the autopkgtest architecture without
9 # hoping nested kvm works). Currently it only sets up qemu user networking
10 # which limits our ability to be clever. In the long run we should set up a
11 # tun and a bridge and specify the mac address of the NICs in the emulated
12 # system and run dnsmasq on it so we test ipv6 and can control which ips which
13 # nics get and so on -- but this is still better than nothing.
14
15 # TODO: Add a test case for classless static routes. This needs support in
16 # Qemu first. Following patch should be refreshed:
17 # https://lore.kernel.org/all/[email protected]/
18
19 SUPPORTED_FLAVOURS='amd64 arm64 armmp powerpc64le s390x generic'
20 ROOTDISK_QEMU_IF=virtio
21 ROOTDISK_LINUX_NAME="/dev/vda"
22 . debian/tests/test-common
23
24 cat >>"${CONFDIR}/initramfs.conf" <<EOF
25 MODULES=list
26 BUSYBOX=n
27 FSTYPE=ext2
28 EOF
29 cat >"${CONFDIR}/modules" <<EOF
30 ext2
31 virtio_pci
32 virtio_blk
33 virtio_net
34 EOF
35 install -m 755 debian/tests/hooks/drop-hostname "${CONFDIR}/hooks/drop-hostname"
36 install -m 755 debian/tests/hooks/persistent-net "${CONFDIR}/hooks/persistent-net"
37 build_initramfs
38
39 prepare_network_dumping_rootfs
40 build_rootfs_ext2
41
42 EXPECTED_DHCP_LAN0="
43 DEVICE='lan0'
44 PROTO='dhcp'
45 IPV4ADDR='10.0.3.15'
46 IPV4BROADCAST='10.0.3.255'
47 IPV4NETMASK='255.255.255.0'
48 IPV4GATEWAY='10.0.3.2'
49 IPV4DNS0='10.0.3.3'
50 HOSTNAME='pizza'
51 DNSDOMAIN='example.com'
52 ROOTSERVER='10.0.3.2'
53 filename='/path/to/bootfile2'
54 DOMAINSEARCH='test.'
55 "
56 EXPECTED_DHCP_LAN1="
57 DEVICE='lan1'
58 PROTO='dhcp'
59 IPV4ADDR='10.0.2.15'
60 IPV4BROADCAST='10.0.2.255'
61 IPV4NETMASK='255.255.255.0'
62 IPV4GATEWAY='10.0.2.2'
63 IPV4DNS0='10.0.2.3'
64 HOSTNAME='goulash'
65 DNSDOMAIN='test'
66 ROOTSERVER='10.0.2.2'
67 filename='/path/to/bootfile'
68 DOMAINSEARCH='example. example.net.'
69 "
70
71 run_qemu "ip=dhcp"
72 check_output "Begin: Waiting up to 180 secs for any network device to become available"
73 ./debian/tests/check-log "${OUTPUT}" has_no_running_processes \
74 has_hostname "goulash|pizza" \
75 has_interface_mtu "lan[01]" 1500 \
76 has_ipv4_addr "10\.0\.[23]\.15/24" "lan[01]" \
77 has_ipv4_default_route "10\.0\.[23]\.2" "lan[01]" \
78 has_net_conf 1 "/run/net-lan0.conf=${EXPECTED_DHCP_LAN0}" "/run/net-lan1.conf=${EXPECTED_DHCP_LAN1}"
79
80 # Test _set_netdev_from_ip_param
81 run_qemu "ip=:::::lan1:dhcp"
82 check_output "Begin: Waiting up to 180 secs for lan1 to become available"
83 ./debian/tests/check-log "${OUTPUT}" has_no_running_processes \
84 has_hostname "goulash" \
85 has_interface_mtu "lan1" 1500 \
86 has_ipv4_addr "10\.0\.2\.15/24" "lan1" \
87 has_ipv4_default_route "10\.0\.2\.2" "lan1" \
88 has_net_conf 1 "/run/net-lan1.conf=${EXPECTED_DHCP_LAN1}"
89
90 # Test setting the IP address manually
91 run_qemu "ip=10.0.2.100::10.0.2.2:255.0.0.0:lasagne:lan1:"
92 check_output "Begin: Waiting up to 180 secs for lan1 to become available"
93 ./debian/tests/check-log "${OUTPUT}" has_no_running_processes \
94 has_hostname "lasagne" \
95 has_interface_mtu "lan1" 1500 \
96 has_ipv4_addr "10\.0\.2\.100/8" "lan1" \
97 has_ipv4_default_route "10\.0\.2\.2" "lan1" \
98 has_net_conf 1 "/run/net-lan1.conf=DEVICE='lan1'
99 PROTO='none'
100 IPV4ADDR='10.0.2.100'
101 IPV4BROADCAST='10.255.255.255'
102 IPV4NETMASK='255.0.0.0'
103 IPV4GATEWAY='10.0.2.2'
104 IPV4DNS0='0.0.0.0'
105 HOSTNAME='lasagne'
106 DNSDOMAIN=''
107 ROOTSERVER='0.0.0.0'
108 filename=''
109 DOMAINSEARCH=''"
110
111 # Test DHCP configuration with BOOTIF specified
112 run_qemu "BOOTIF=01-52-54-00-12-34-56 ip=dhcp"
113 check_output "Begin: Waiting up to 180 secs for device with address 52:54:00:12:34:56 to become available"
114 ./debian/tests/check-log "${OUTPUT}" has_no_running_processes \
115 has_hostname "goulash" \
116 has_interface_mtu "lan1" 1500 \
117 has_ipv4_addr "10\.0\.2\.15/24" "lan1" \
118 has_ipv4_default_route "10\.0\.2\.2" "lan1" \
119 has_net_conf 1 "/run/net-lan1.conf=${EXPECTED_DHCP_LAN1}"
120
121 run_qemu "ip=on"
122 check_output "Begin: Waiting up to 180 secs for any network device to become available"
123 ./debian/tests/check-log "${OUTPUT}" has_no_running_processes \
124 has_hostname "goulash|pizza" \
125 has_interface_mtu "lan[01]" 1500 \
126 has_ipv4_addr "10\.0\.[23]\.15/24" "lan[01]" \
127 has_ipv4_default_route "10\.0\.[23]\.2" "lan[01]" \
128 has_net_conf 1 "/run/net-lan0.conf=${EXPECTED_DHCP_LAN0}" "/run/net-lan1.conf=${EXPECTED_DHCP_LAN1}"