Merge ~mwhudson/ubuntu/+source/initramfs-tools:autopkgtests into ubuntu/+source/initramfs-tools:ubuntu/devel

Proposed by Michael Hudson-Doyle
Status: Merged
Merge reported by: Michael Hudson-Doyle
Merged at revision: a6612c0eab1896e3a9fc4d38f4c9e67e932474d6
Proposed branch: ~mwhudson/ubuntu/+source/initramfs-tools:autopkgtests
Merge into: ubuntu/+source/initramfs-tools:ubuntu/devel
Diff against target: 265 lines (+227/-0)
6 files modified
debian/changelog (+6/-0)
debian/tests/check-results (+80/-0)
debian/tests/control (+3/-0)
debian/tests/net (+43/-0)
debian/tests/prep-image (+49/-0)
debian/tests/run-image (+46/-0)
Reviewer Review Type Date Requested Status
Ubuntu Foundations Team Pending
Review via email: mp+352726@code.launchpad.net

Commit message

Add some basic autopkgtests

To post a comment you must log in.
349a768... by Michael Hudson-Doyle

attempt to make work on other architectures

1cf3a14... by Michael Hudson-Doyle

i read about predictable device names

aff3cbb... by Michael Hudson-Doyle

dump / save the /run/net*.conf files

a6612c0... by Michael Hudson-Doyle

refactor a bit

Revision history for this message
Dimitri John Ledkov (xnox) wrote :

This got merged, i think? Please close the merge proposal?

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index 077d576..bed7055 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,9 @@
6+initramfs-tools (0.131ubuntu4~mwhudson1) UNRELEASED; urgency=medium
7+
8+ * Add some autopkgests.
9+
10+ -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Wed, 08 Aug 2018 12:33:21 +1200
11+
12 initramfs-tools (0.131ubuntu3) cosmic; urgency=medium
13
14 * Drop including mlx4 and mlx5 InfiniBand modules. Version 0.131 uses
15diff --git a/debian/tests/check-results b/debian/tests/check-results
16new file mode 100755
17index 0000000..9016baa
18--- /dev/null
19+++ b/debian/tests/check-results
20@@ -0,0 +1,80 @@
21+#!/usr/bin/python3
22+
23+import json
24+import os
25+import sys
26+
27+in_error = False
28+
29+def error(msg):
30+ print(msg)
31+ global in_error
32+ in_error = True
33+
34+def has_link(name):
35+ for l in links:
36+ if l['ifname'] == name:
37+ return
38+ error("link {} not found".format(name))
39+
40+def has_an_ipv4_addr(name):
41+ for l in addrs:
42+ if l['ifname'] == name:
43+ for addr in l['addr_info']:
44+ if addr['family'] == 'inet' and addr['scope'] == 'global':
45+ print("found addr {} for {}".format(addr, name))
46+ return
47+ error("{} appears to have no addresses".format(name))
48+ return
49+ error("link {} not found".format(name))
50+
51+def has_no_ipv4_addr(name):
52+ for l in addrs:
53+ if l['ifname'] == name:
54+ for addr in l['addr_info']:
55+ if addr['family'] == 'inet' and addr['scope'] == 'global':
56+ error("found addr {} for {}".format(addr, name))
57+ return
58+ print("{} appears to have no addresses".format(name))
59+ return
60+ error("link {} not found".format(name))
61+
62+def has_ipv4_addr(name, wanted_addr):
63+ for l in addrs:
64+ if l['ifname'] == name:
65+ for addr in l['addr_info']:
66+ if addr['family'] == 'inet' and addr['scope'] == 'global':
67+ if addr['local'] == wanted_addr:
68+ print("found addr {} for {}".format(addr, name))
69+ return
70+ error("{} appears not to have address {}".format(name, wanted_addr))
71+ return
72+ error("link {} not found".format(name))
73+
74+result_dir = sys.argv[1]
75+with open(os.path.join(result_dir, 'link.json')) as fp:
76+ links = json.load(fp)
77+with open(os.path.join(result_dir, 'addr.json')) as fp:
78+ addrs = json.load(fp)
79+
80+i = 2
81+while i < len(sys.argv):
82+ a = sys.argv[i]
83+ i += 1
84+ if a == 'has_link':
85+ has_link(sys.argv[i])
86+ i += 1
87+ elif a == 'has_an_ipv4_addr':
88+ has_an_ipv4_addr(sys.argv[i])
89+ i += 1
90+ elif a == 'has_no_ipv4_addr':
91+ has_no_ipv4_addr(sys.argv[i])
92+ i += 1
93+ elif a == 'has_ipv4_addr':
94+ has_ipv4_addr(sys.argv[i], sys.argv[i+1])
95+ i += 2
96+ else:
97+ error("unknown check {}".format(a))
98+
99+if in_error:
100+ sys.exit(1)
101diff --git a/debian/tests/control b/debian/tests/control
102new file mode 100644
103index 0000000..656a1b8
104--- /dev/null
105+++ b/debian/tests/control
106@@ -0,0 +1,3 @@
107+Tests: net
108+Depends: initramfs-tools, linux-image-generic, python3, qemu-system-x86
109+Restrictions: needs-root, allow-stderr
110diff --git a/debian/tests/net b/debian/tests/net
111new file mode 100755
112index 0000000..ea6cfdc
113--- /dev/null
114+++ b/debian/tests/net
115@@ -0,0 +1,43 @@
116+#!/bin/bash
117+
118+set -eux
119+
120+# Some simple tests of the initramfs network configuration.
121+
122+# The basic idea is to make an image that has /sbin/init overwritten
123+# to just gather some data and shutdown again and boot it in qemu
124+# system emulation (not KVM, so it can be run in the autopkgtest
125+# architecture without hoping nested kvm works). Currently it only
126+# sets up qemu user networking which limits our ability to be
127+# clever. In the long run we should set up a tun and a bridge and
128+# specify the mac address of the NICs in the emuilated system and run
129+# dnsmasq on it so we test ipv6 and can control which ips which nics
130+# get and so on -- but this is still better than nothing.
131+
132+./debian/tests/prep-image image.img
133+
134+basecmdline="root=UUID=$(cat image.img-uuid) rw console=ttyS0"
135+
136+mkinitramfs -o myinitrd
137+
138+nicslot=5
139+nicname=ens$nicslot
140+
141+run () {
142+ ./debian/tests/run-image kernel="/boot/vmlinuz-$(uname -r)" initrd=myinitrd \
143+ image=image.img cmdline="$basecmdline ${1-}" \
144+ output=result nicslot=$nicslot
145+}
146+
147+run ""
148+./debian/tests/check-results result has_no_ipv4_addr $nicname
149+
150+run "ip=dhcp"
151+./debian/tests/check-results result has_an_ipv4_addr $nicname
152+
153+run "ip=:::::$nicname:dhcp"
154+./debian/tests/check-results result has_an_ipv4_addr $nicname
155+
156+run "ip=10.0.2.100::10.0.2.2:255.0.0.0::$nicname:"
157+./debian/tests/check-results result has_ipv4_addr $nicname 10.0.2.100
158+
159diff --git a/debian/tests/prep-image b/debian/tests/prep-image
160new file mode 100755
161index 0000000..92cf2ab
162--- /dev/null
163+++ b/debian/tests/prep-image
164@@ -0,0 +1,49 @@
165+#!/bin/bash
166+
167+# prep-image $IMAGE preps an image for the tests. Specifically it:
168+#
169+# 1. downloads a cloud image rootfs
170+# 2. creates an image containing a single partition at $IMAGE,
171+# 3. writes the UUID of the partition to $IMAGE-uuid,
172+# 4. extracts the rootfs to the image, and
173+# 5. overwrites /sbin/init with a script that gathers some data to
174+# /result and shuts the machine down
175+
176+set -eux
177+IMAGE="$1"
178+series=$(lsb_release -sc)
179+url=http://cloud-images.ubuntu.com/$series/current/$series-server-cloudimg-$(dpkg --print-architecture)-root.tar.xz
180+filename=$(basename "$url")
181+mkdir -p images
182+[ -f images/"$filename" ] || (cd images; wget --progress=dot:giga "$url")
183+rm -f "$IMAGE" "${IMAGE}-uuid"
184+truncate -s 1G "$IMAGE"
185+parted --script --align optimal "$IMAGE" -- mklabel gpt mkpart primary ext4 1MiB -2048s
186+dev="$(losetup -Pf --show "$IMAGE")"
187+mke2fs -q "${dev}p1"
188+blkid --output=value "${dev}p1" | head -n1 > "${IMAGE}-uuid"
189+mkdir -p mnt
190+mount "${dev}p1" mnt
191+tar --xattrs-include=* -C mnt -xf images/"$filename"
192+rm -f mnt/sbin/init
193+cat > mnt/sbin/init << \EOF
194+#!/bin/sh
195+set -x
196+rm -rf /result
197+mkdir /result
198+# Run twice, once for the logs, once for the test harness
199+ip addr
200+ip link
201+for file in /run/net-*.conf /run/net6-*.conf; do
202+ [ -f $file ] || continue;
203+ cat $file
204+ cp $file /result
205+done
206+ip -json addr > /result/addr.json
207+ip -json link > /result/link.json
208+sync
209+exec /lib/systemd/systemd-shutdown poweroff
210+EOF
211+chmod u+x mnt/sbin/init
212+umount mnt
213+losetup -d "$dev"
214diff --git a/debian/tests/run-image b/debian/tests/run-image
215new file mode 100755
216index 0000000..ee9e16e
217--- /dev/null
218+++ b/debian/tests/run-image
219@@ -0,0 +1,46 @@
220+#!/bin/bash
221+
222+set -eux
223+
224+NICSLOT=3
225+
226+while [ $# -gt 0 ]; do
227+ case $1 in
228+ kernel=*) KERNEL="${1#kernel=}" ;;
229+ initrd=*) INITRD="${1#initrd=}" ;;
230+ image=*) IMAGE="${1#image=}" ;;
231+ cmdline=*) CMDLINE="${1#cmdline=}" ;;
232+ output=*) OUTPUT="${1#output=}" ;;
233+ nicslot=*) NICSLOT="${1#nicslot=}" ;;
234+ esac
235+ shift
236+done
237+
238+archopts=()
239+
240+case $(uname -m) in
241+i?86)
242+ qemu="qemu-system-i386"
243+ ;;
244+ppc64*)
245+ qemu="qemu-system-ppc64"
246+ archopts=( -machine "pseries,usb=off" )
247+ ;;
248+*)
249+ qemu=qemu-system-$(uname -m)
250+esac
251+
252+timeout --foreground 10m \
253+ "$qemu" "${archopts[@]}" -m 512m \
254+ -kernel "$KERNEL" -initrd "$INITRD" \
255+ -append "$CMDLINE" \
256+ -drive file="$IMAGE",format=raw \
257+ -nographic -monitor none \
258+ -netdev user,id=net0 -device e1000,netdev=net0,bus=pci.0,addr="$NICSLOT"
259+
260+dev=$(losetup -Pf --show "$IMAGE")
261+mount "${dev}p1" mnt
262+rm -rf "$OUTPUT"
263+cp -aT mnt/result "$OUTPUT"
264+umount mnt
265+losetup -d "$dev"

Subscribers

People subscribed via source and target branches