Package: autopkgtest
Version: 3.17.2
Severity: normal
Tags: patch

Dear Maintainer,

adt-setup-vm tries to use the host's network interface name when called
from e.g. vmdebootstrap. Especially if the recommended command in the
man page of adt-virt-qemu is used, this is problematic.

Offending lines in adt-setup-vm:

if OUT="$(cd /sys/class/net; ls -d e* 2>/dev/null)"; then
  IFACE="${OUT# *}"
  ...
fi

/sys/class/net is here that of the host, because the VM isn't booted
yet.

I've attached a patch that does the following:

 - if $root is /, so this is run inside a VM, keep the old code
 - otherwise, assume it's eth0. This is fine up to Jessie inside the
   VM, but newer udev versions will use "predictable names", which in
   case of VMs I'm not completely sure are that predictable. (In my
   case it's always ens3 for adt-virt-qemu, but I'm not sure how stable
   that is across QEMU impolementations.) Therefore, do the same thing
   here that autopkgtest does if called with --enable-dhcp, i.e. mask
   80-net-setup-link.rules to keep the kernel names.

Note that after masking any udev rule, one needs to update the
initramfs, but vmdebootstrap at least does that after calling the
customization script, so we don't do that here. (If run inside a VM, we
don't mask the udev rule, so we don't need this.)

Regards,
Christian
From 9bae85a5066c1b69032f3734d3e4cd087ca1bb49 Mon Sep 17 00:00:00 2001
From: Christian Seiler <christ...@iwakd.de>
Date: Wed, 7 Oct 2015 14:59:15 +0200
Subject: [PATCH] adt-setup-vm: Don't use host interface name in a VM

Don't use the host's interface name when configuring a chroot (when
called from e.g. vmdebootstrap), only do that when called from within a
VM. Use eth0 instead, and then mask udev interface renaming to keep
the kernel name. Also, don't touch network configuration at all if some
(apart from lo) already exists.
---
 tools/adt-setup-vm | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/tools/adt-setup-vm b/tools/adt-setup-vm
index 8e2300c..7ceae0f 100755
--- a/tools/adt-setup-vm
+++ b/tools/adt-setup-vm
@@ -95,12 +95,30 @@ if ! grep -q 'source.*interfaces.d' "$root/etc/network/interfaces"; then
 fi
 
 # set up networking
-if OUT="$(cd /sys/class/net; ls -d e* 2>/dev/null)"; then
-    IFACE="${OUT# *}"
-    if ! grep -qr $IFACE "$root/etc/network/interfaces" "$root/etc/network/interfaces.d/"; then
-        mkdir -p "$root/etc/network/interfaces.d"
+IFACE=""
+if [ "$root" = / ] ; then
+    # we are already in a VM, so figure out our network
+    # device
+    if OUT="$(cd /sys/class/net; ls -d e* 2>/dev/null)"; then
+        IFACE="${OUT# *}"
+    fi
+else
+    # the kernel will choose eth0 as the interface name, so
+    # keep that (and tell udev to not rename the interface,
+    # we won't know how it will be called)
+    IFACE="eth0"
+    if ! [ -e $root/etc/udev/rules.d/80-net-setup-link.rules ] ; then
+        ln -s /dev/null $root/etc/udev/rules.d/80-net-setup-link.rules
+    fi
+fi
+if [ -n "$IFACE" ] ; then
+    mkdir -p "$root/etc/network/interfaces.d"
+    files="$root/etc/network/interfaces $(chroot "$root" run-parts --list /etc/network/interfaces.d)"
+    grep -v 'auto lo' $files > $root/tmp/old-network-config || :
+    if ! grep -q -E '^[[:space:]]*auto' $root/tmp/old-network-config ; then
         printf "auto $IFACE\niface $IFACE inet dhcp\n" >> "$root/etc/network/interfaces.d/$IFACE"
     fi
+    rm -f $root/tmp/old-network-config
 fi
 
 # go-faster apt/dpkg
-- 
2.1.4

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to