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
diff --git a/debian/changelog b/debian/changelog
index 077d576..bed7055 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
1initramfs-tools (0.131ubuntu4~mwhudson1) UNRELEASED; urgency=medium
2
3 * Add some autopkgests.
4
5 -- Michael Hudson-Doyle <michael.hudson@ubuntu.com> Wed, 08 Aug 2018 12:33:21 +1200
6
1initramfs-tools (0.131ubuntu3) cosmic; urgency=medium7initramfs-tools (0.131ubuntu3) cosmic; urgency=medium
28
3 * Drop including mlx4 and mlx5 InfiniBand modules. Version 0.131 uses9 * Drop including mlx4 and mlx5 InfiniBand modules. Version 0.131 uses
diff --git a/debian/tests/check-results b/debian/tests/check-results
4new file mode 10075510new file mode 100755
index 0000000..9016baa
--- /dev/null
+++ b/debian/tests/check-results
@@ -0,0 +1,80 @@
1#!/usr/bin/python3
2
3import json
4import os
5import sys
6
7in_error = False
8
9def error(msg):
10 print(msg)
11 global in_error
12 in_error = True
13
14def has_link(name):
15 for l in links:
16 if l['ifname'] == name:
17 return
18 error("link {} not found".format(name))
19
20def has_an_ipv4_addr(name):
21 for l in addrs:
22 if l['ifname'] == name:
23 for addr in l['addr_info']:
24 if addr['family'] == 'inet' and addr['scope'] == 'global':
25 print("found addr {} for {}".format(addr, name))
26 return
27 error("{} appears to have no addresses".format(name))
28 return
29 error("link {} not found".format(name))
30
31def has_no_ipv4_addr(name):
32 for l in addrs:
33 if l['ifname'] == name:
34 for addr in l['addr_info']:
35 if addr['family'] == 'inet' and addr['scope'] == 'global':
36 error("found addr {} for {}".format(addr, name))
37 return
38 print("{} appears to have no addresses".format(name))
39 return
40 error("link {} not found".format(name))
41
42def has_ipv4_addr(name, wanted_addr):
43 for l in addrs:
44 if l['ifname'] == name:
45 for addr in l['addr_info']:
46 if addr['family'] == 'inet' and addr['scope'] == 'global':
47 if addr['local'] == wanted_addr:
48 print("found addr {} for {}".format(addr, name))
49 return
50 error("{} appears not to have address {}".format(name, wanted_addr))
51 return
52 error("link {} not found".format(name))
53
54result_dir = sys.argv[1]
55with open(os.path.join(result_dir, 'link.json')) as fp:
56 links = json.load(fp)
57with open(os.path.join(result_dir, 'addr.json')) as fp:
58 addrs = json.load(fp)
59
60i = 2
61while i < len(sys.argv):
62 a = sys.argv[i]
63 i += 1
64 if a == 'has_link':
65 has_link(sys.argv[i])
66 i += 1
67 elif a == 'has_an_ipv4_addr':
68 has_an_ipv4_addr(sys.argv[i])
69 i += 1
70 elif a == 'has_no_ipv4_addr':
71 has_no_ipv4_addr(sys.argv[i])
72 i += 1
73 elif a == 'has_ipv4_addr':
74 has_ipv4_addr(sys.argv[i], sys.argv[i+1])
75 i += 2
76 else:
77 error("unknown check {}".format(a))
78
79if in_error:
80 sys.exit(1)
diff --git a/debian/tests/control b/debian/tests/control
0new file mode 10064481new file mode 100644
index 0000000..656a1b8
--- /dev/null
+++ b/debian/tests/control
@@ -0,0 +1,3 @@
1Tests: net
2Depends: initramfs-tools, linux-image-generic, python3, qemu-system-x86
3Restrictions: needs-root, allow-stderr
diff --git a/debian/tests/net b/debian/tests/net
0new file mode 1007554new file mode 100755
index 0000000..ea6cfdc
--- /dev/null
+++ b/debian/tests/net
@@ -0,0 +1,43 @@
1#!/bin/bash
2
3set -eux
4
5# Some simple tests of the initramfs network configuration.
6
7# The basic idea is to make an image that has /sbin/init overwritten
8# to just gather some data and shutdown again and boot it in qemu
9# system emulation (not KVM, so it can be run in the autopkgtest
10# architecture without hoping nested kvm works). Currently it only
11# sets up qemu user networking which limits our ability to be
12# clever. In the long run we should set up a tun and a bridge and
13# specify the mac address of the NICs in the emuilated system and run
14# dnsmasq on it so we test ipv6 and can control which ips which nics
15# get and so on -- but this is still better than nothing.
16
17./debian/tests/prep-image image.img
18
19basecmdline="root=UUID=$(cat image.img-uuid) rw console=ttyS0"
20
21mkinitramfs -o myinitrd
22
23nicslot=5
24nicname=ens$nicslot
25
26run () {
27 ./debian/tests/run-image kernel="/boot/vmlinuz-$(uname -r)" initrd=myinitrd \
28 image=image.img cmdline="$basecmdline ${1-}" \
29 output=result nicslot=$nicslot
30}
31
32run ""
33./debian/tests/check-results result has_no_ipv4_addr $nicname
34
35run "ip=dhcp"
36./debian/tests/check-results result has_an_ipv4_addr $nicname
37
38run "ip=:::::$nicname:dhcp"
39./debian/tests/check-results result has_an_ipv4_addr $nicname
40
41run "ip=10.0.2.100::10.0.2.2:255.0.0.0::$nicname:"
42./debian/tests/check-results result has_ipv4_addr $nicname 10.0.2.100
43
diff --git a/debian/tests/prep-image b/debian/tests/prep-image
0new file mode 10075544new file mode 100755
index 0000000..92cf2ab
--- /dev/null
+++ b/debian/tests/prep-image
@@ -0,0 +1,49 @@
1#!/bin/bash
2
3# prep-image $IMAGE preps an image for the tests. Specifically it:
4#
5# 1. downloads a cloud image rootfs
6# 2. creates an image containing a single partition at $IMAGE,
7# 3. writes the UUID of the partition to $IMAGE-uuid,
8# 4. extracts the rootfs to the image, and
9# 5. overwrites /sbin/init with a script that gathers some data to
10# /result and shuts the machine down
11
12set -eux
13IMAGE="$1"
14series=$(lsb_release -sc)
15url=http://cloud-images.ubuntu.com/$series/current/$series-server-cloudimg-$(dpkg --print-architecture)-root.tar.xz
16filename=$(basename "$url")
17mkdir -p images
18[ -f images/"$filename" ] || (cd images; wget --progress=dot:giga "$url")
19rm -f "$IMAGE" "${IMAGE}-uuid"
20truncate -s 1G "$IMAGE"
21parted --script --align optimal "$IMAGE" -- mklabel gpt mkpart primary ext4 1MiB -2048s
22dev="$(losetup -Pf --show "$IMAGE")"
23mke2fs -q "${dev}p1"
24blkid --output=value "${dev}p1" | head -n1 > "${IMAGE}-uuid"
25mkdir -p mnt
26mount "${dev}p1" mnt
27tar --xattrs-include=* -C mnt -xf images/"$filename"
28rm -f mnt/sbin/init
29cat > mnt/sbin/init << \EOF
30#!/bin/sh
31set -x
32rm -rf /result
33mkdir /result
34# Run twice, once for the logs, once for the test harness
35ip addr
36ip link
37for file in /run/net-*.conf /run/net6-*.conf; do
38 [ -f $file ] || continue;
39 cat $file
40 cp $file /result
41done
42ip -json addr > /result/addr.json
43ip -json link > /result/link.json
44sync
45exec /lib/systemd/systemd-shutdown poweroff
46EOF
47chmod u+x mnt/sbin/init
48umount mnt
49losetup -d "$dev"
diff --git a/debian/tests/run-image b/debian/tests/run-image
0new file mode 10075550new file mode 100755
index 0000000..ee9e16e
--- /dev/null
+++ b/debian/tests/run-image
@@ -0,0 +1,46 @@
1#!/bin/bash
2
3set -eux
4
5NICSLOT=3
6
7while [ $# -gt 0 ]; do
8 case $1 in
9 kernel=*) KERNEL="${1#kernel=}" ;;
10 initrd=*) INITRD="${1#initrd=}" ;;
11 image=*) IMAGE="${1#image=}" ;;
12 cmdline=*) CMDLINE="${1#cmdline=}" ;;
13 output=*) OUTPUT="${1#output=}" ;;
14 nicslot=*) NICSLOT="${1#nicslot=}" ;;
15 esac
16 shift
17done
18
19archopts=()
20
21case $(uname -m) in
22i?86)
23 qemu="qemu-system-i386"
24 ;;
25ppc64*)
26 qemu="qemu-system-ppc64"
27 archopts=( -machine "pseries,usb=off" )
28 ;;
29*)
30 qemu=qemu-system-$(uname -m)
31esac
32
33timeout --foreground 10m \
34 "$qemu" "${archopts[@]}" -m 512m \
35 -kernel "$KERNEL" -initrd "$INITRD" \
36 -append "$CMDLINE" \
37 -drive file="$IMAGE",format=raw \
38 -nographic -monitor none \
39 -netdev user,id=net0 -device e1000,netdev=net0,bus=pci.0,addr="$NICSLOT"
40
41dev=$(losetup -Pf --show "$IMAGE")
42mount "${dev}p1" mnt
43rm -rf "$OUTPUT"
44cp -aT mnt/result "$OUTPUT"
45umount mnt
46losetup -d "$dev"

Subscribers

People subscribed via source and target branches