[pve-devel] [PATCH v3 pve-common 3/5] Inotify : add check_bond

Alexandre Derumier aderumier at odiso.com
Thu Jul 5 02:56:32 CEST 2018


verify than bond slaves exist && type is eth
---
 src/PVE/INotify.pm                              | 15 ++++++++++
 test/etc_network_interfaces/t.create_network.pl | 38 +++++++++++++++++++++++++
 2 files changed, 53 insertions(+)

diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
index 186df62..f4a5945 100644
--- a/src/PVE/INotify.pm
+++ b/src/PVE/INotify.pm
@@ -1319,6 +1319,21 @@ sub __write_etc_network_interfaces {
 	}
     }
 
+    # check bond
+    foreach my $iface (keys %$ifaces) {
+	my $d = $ifaces->{$iface};
+	if ($d->{type} eq 'bond' && $d->{slaves}) {
+	    foreach my $p (split (/\s+/, $d->{slaves})) {
+		my $n = $ifaces->{$p};
+
+		die "bond '$iface' - unable to find slave '$p'\n"
+		    if !$n;
+		die "bond '$iface' - wrong interface type on slave '$p' " .
+		    "('$n->{type}' != 'eth')\n" if $n->{type} ne 'eth';
+	    }
+	}
+    }
+
     # check vxlan
     my $vxlans = {};
     foreach my $iface (keys %$ifaces) {
diff --git a/test/etc_network_interfaces/t.create_network.pl b/test/etc_network_interfaces/t.create_network.pl
index 3503797..da47999 100644
--- a/test/etc_network_interfaces/t.create_network.pl
+++ b/test/etc_network_interfaces/t.create_network.pl
@@ -24,6 +24,31 @@ $config->{ifaces}->{eth1} = {
     autostart => 1
 };
 
+$config->{ifaces}->{eth2} = {
+    type => 'eth',
+    method => 'manual',
+    families => ['inet'],
+    autostart => 1
+};
+
+$config->{ifaces}->{eth3} = {
+    type => 'eth',
+    method => 'manual',
+    families => ['inet'],
+    autostart => 1
+};
+
+$config->{ifaces}->{bond0} = {
+    type => 'bond',
+    slaves => 'eth2 eth3',
+    bond_mode => '802.3ad',
+    bond_xmit_hash_policy => 'layer3+4',
+    bond_miimon => 100,
+    method => 'manual',
+    families => ['inet'],
+    autostart => 1
+};
+
 $config->{ifaces}->{vmbr1} = {
     type => 'bridge',
     method => 'manual',
@@ -103,6 +128,19 @@ iface eth1 inet static
 	netmask  $nm
 	gateway  $gw
 
+auto eth2
+iface eth2 inet manual
+
+auto eth3
+iface eth3 inet manual
+
+auto bond0
+iface bond0 inet manual
+	bond-slaves eth2 eth3
+	bond-miimon 100
+	bond-mode 802.3ad
+	bond-xmit-hash-policy layer3+4
+
 auto vmbr0
 iface vmbr0 inet static
 	address  10.0.0.2
-- 
2.11.0




More information about the pve-devel mailing list