[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[OSSTEST PATCH 14/36] preseed_base, ts-host-install: Change NIC NamePolicy to "mac"



On "italia?" machine, the two network interfaces are competing to have
"eno1", base on the "onboard" naming policy. So the name of the
network interface can change between "eno1" and "eth0".

Switching to "mac" should avoid the unpredictable name based on
"onboard" or "slot" policy.

The "mac" naming policy break `vif-bridge` for the "vif*.*" network
interfaces. So we will avoid the "mac" policy if the driver is "vif".
This also have an impact on guest created with ./ts-debian-install, as
they use the initrd from dom0, so the interface in the guest will be
renamed according to default policy (which rename eth0 to enX0).

Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
---
 Osstest/Debian.pm | 22 ++++++++++++++++++++++
 ts-host-install   | 16 ++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/Osstest/Debian.pm b/Osstest/Debian.pm
index 102b0246..31d32d6f 100644
--- a/Osstest/Debian.pm
+++ b/Osstest/Debian.pm
@@ -962,6 +962,28 @@ cp /$RULESDIR/70-persistent-*.rules /target/$RULESDIR 
2>/dev/null || true
 
 END
 
+    if ($ho->{Suite} !~ m/lenny|squeeze|wheezy|jessie|stretch|buster/) {
+        # Always use MAC address in network interface names.
+        #
+        # But keep the default policy if the driver is "vif", which match the
+        # "vif$domid.$idx" interface in dom0, and the interface in domU. This 
file
+        # is going to be added to dom0's initrd, which is used by some guests
+        # (created with ts-debian-install).
+        preseed_hook_installscript($ho, $sfx,
+            '/usr/lib/base-installer.d/', '05ifnamepolicy', <<'END');
+#!/bin/sh -e
+linkfile=/target/etc/systemd/network/90-eth-mac-policy.link
+mkdir -p `dirname $linkfile`
+cat > $linkfile <<EOF
+[Match]
+Type=ether
+Driver=!vif
+[Link]
+NamePolicy=mac
+EOF
+END
+    }
+
     debian_overlays($ho, sub {
        my ($srcdir, $tfilename) = @_;
        preseed_hook_overlay($ho, $sfx, $srcdir, $tfilename);
diff --git a/ts-host-install b/ts-host-install
index 88481038..0b6aaeea 100755
--- a/ts-host-install
+++ b/ts-host-install
@@ -248,6 +248,22 @@ END
     print CANARY "\n# - canary - came via initramfs\n" or die $!;
     close CANARY or die $!;
 
+    if ($ho->{Suite} !~ m/lenny|squeeze|wheezy|jessie|stretch|buster/) {
+        # Switch to more predictale nic name based on mac address, instead of 
the
+        # policy "onboard" which can try to set the same name ("eno1") to two
+        # differents nic, or "slot". New names are "enx$mac".
+        system_checked(qw(mkdir -p --), 
"$initrd_overlay.d/lib/systemd/network");
+        file_simple_write_contents
+            ("$initrd_overlay.d/lib/systemd/network/90-eth-mac-policy.link",
+                <<END);
+[Match]
+Type=ether
+Driver=!vif
+[Link]
+NamePolicy=mac
+END
+    }
+
     my %xopts;
 
     di_special_kernel($ho, sub {
-- 
Anthony PERARD




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.