[pve-devel] [PATCH 16/16] tests: list/create/update network interfaces
Wolfgang Bumiller
w.bumiller at proxmox.com
Wed Jun 24 14:33:30 CEST 2015
---
test/etc_network_interfaces/brbase | 26 +++++
test/etc_network_interfaces/t.create_network.pl | 91 ++++++++++++++++++
test/etc_network_interfaces/t.list-interfaces.pl | 109 +++++++++++++++++++++
test/etc_network_interfaces/t.update_network.pl | 116 +++++++++++++++++++++++
4 files changed, 342 insertions(+)
create mode 100644 test/etc_network_interfaces/brbase
create mode 100644 test/etc_network_interfaces/t.create_network.pl
create mode 100644 test/etc_network_interfaces/t.list-interfaces.pl
create mode 100644 test/etc_network_interfaces/t.update_network.pl
diff --git a/test/etc_network_interfaces/brbase b/test/etc_network_interfaces/brbase
new file mode 100644
index 0000000..63e18c8
--- /dev/null
+++ b/test/etc_network_interfaces/brbase
@@ -0,0 +1,26 @@
+# network interface settings; autogenerated
+# Please do NOT modify this file directly, unless you know what
+# you're doing.
+#
+# If you want to manage part of the network configuration manually,
+# please utilize the 'source' or 'source-directory' directives to do
+# so.
+# PVE will preserve these directives, but will NOT its network
+# configuration from sourced files, so do not attempt to move any of
+# the PVE managed interfaces into external files!
+
+auto lo
+iface lo inet loopback
+
+source-directory interfaces.d
+
+iface eth0 inet manual
+
+auto vmbr0
+iface vmbr0 inet static
+ address 10.0.0.2
+ netmask 255.255.255.0
+ gateway 10.0.0.1
+ bridge_ports eth0
+ bridge_stp off
+ bridge_fd 0
diff --git a/test/etc_network_interfaces/t.create_network.pl b/test/etc_network_interfaces/t.create_network.pl
new file mode 100644
index 0000000..22d6c85
--- /dev/null
+++ b/test/etc_network_interfaces/t.create_network.pl
@@ -0,0 +1,91 @@
+save('proc_net_dev', <<'/proc/net/dev');
+eth0:
+eth1:
+/proc/net/dev
+
+r(load('brbase'));
+
+my $ip = '192.168.0.2';
+my $nm = '255.255.255.0';
+my $gw = '192.168.0.1';
+
+$config->{ifaces}->{eth1} = {
+ type => 'eth',
+ method => 'static',
+ address => $ip,
+ netmask => $nm,
+ gateway => $gw,
+ families => ['inet'],
+ autostart => 1
+};
+
+expect load('loopback') . <<"CHECK";
+source-directory interfaces.d
+
+iface eth0 inet manual
+
+auto eth1
+iface eth1 inet static
+ address $ip
+ netmask $nm
+ gateway $gw
+
+auto vmbr0
+iface vmbr0 inet static
+ address 10.0.0.2
+ netmask 255.255.255.0
+ gateway 10.0.0.1
+ bridge_ports eth0
+ bridge_stp off
+ bridge_fd 0
+
+CHECK
+
+save('if', w());
+r(load('if'));
+expect load('if');
+
+r(load('brbase'));
+
+my $ip = 'fc05::2';
+my $nm = '112';
+my $gw = 'fc05::1';
+
+$config->{ifaces}->{eth1} = {
+ type => 'eth',
+ method6 => 'static',
+ address6 => $ip,
+ netmask6 => $nm,
+ gateway6 => $gw,
+ families => ['inet6'],
+ autostart => 1
+};
+
+
+expect load('loopback') . <<"CHECK";
+source-directory interfaces.d
+
+iface eth0 inet manual
+
+auto eth1
+iface eth1 inet6 static
+ address $ip
+ netmask $nm
+ gateway $gw
+
+auto vmbr0
+iface vmbr0 inet static
+ address 10.0.0.2
+ netmask 255.255.255.0
+ gateway 10.0.0.1
+ bridge_ports eth0
+ bridge_stp off
+ bridge_fd 0
+
+CHECK
+
+save('if', w());
+r(load('if'));
+expect load('if');
+
+1;
diff --git a/test/etc_network_interfaces/t.list-interfaces.pl b/test/etc_network_interfaces/t.list-interfaces.pl
new file mode 100644
index 0000000..caffe88
--- /dev/null
+++ b/test/etc_network_interfaces/t.list-interfaces.pl
@@ -0,0 +1,109 @@
+no warnings 'experimental::smartmatch';
+
+# Assuming eth0..3 and eth100
+# eth0 is part of vmbr0, eth100 is part of the OVS bridge vmbr1
+# vmbr0 has ipv4 and ipv6, OVS only ipv4
+#
+# eth1..3 are completely un-configured as if the cards had just been physically
+# plugged in.
+# The expected behavior is to notice their existance and treat them as manually
+# configured interfaces.
+# Saving the file after reading would add the corresponding 'manual' lines.
+save('proc_net_dev', <<'/proc/net/dev');
+eth0:
+eth1:
+eth2:
+eth3:
+eth100:
+/proc/net/dev
+
+my %wanted = (
+ vmbr0 => { address => '192.168.1.2',
+ netmask => '255.255.255.0',
+ gateway => '192.168.1.1',
+ address6 => 'fc05::1:1',
+ netmask6 => '112' },
+ vmbr1 => { address => '10.0.0.5',
+ netmask => '255.255.255.0' }
+);
+
+save('interfaces', <<"/etc/network/interfaces");
+auto lo
+iface lo inet loopback
+
+source-directory interfaces.d
+
+iface eth0 inet manual
+
+allow-vmbr1 eth100
+iface eth100 inet manual
+ ovs_type OVSPort
+ ovs_bridge vmbr1
+
+auto vmbr0
+iface vmbr0 inet static
+ address $wanted{vmbr0}->{address}
+ netmask $wanted{vmbr0}->{netmask}
+ gateway $wanted{vmbr0}->{gateway}
+ bridge_ports eth0
+ bridge_stp off
+ bridge_fd 0
+
+iface vmbr0 inet6 static
+ address $wanted{vmbr0}->{address6}
+ netmask $wanted{vmbr0}->{netmask6}
+
+source-directory before-ovs.d
+
+auto vmbr1
+iface vmbr1 inet static
+ address $wanted{vmbr1}->{address}
+ netmask $wanted{vmbr1}->{netmask}
+ ovs_type OVSBridge
+ ovs_ports eth100
+
+source after-ovs
+
+/etc/network/interfaces
+
+r(load('interfaces'));
+save('2', w());
+
+my $ifaces = $config->{ifaces};
+
+# check defined interfaces
+defined($ifaces->{"eth$_"})
+ or die "missing interface: eth$_\n" foreach (0, 1, 2, 3, 100);
+
+# check configuration
+foreach my $ifname (keys %wanted) {
+ my $if = $wanted{$ifname};
+ $ifaces->{$ifname}->{$_} eq $if->{$_}
+ or die "unexpected $_ for interface $ifname: \""
+ . $ifaces->{$ifname}->{$_}
+ . "\", expected: \"$if->{$_}\"\n"
+ foreach (keys %$if);
+}
+
+my $ck = sub {
+ my ($i, $v, $e) = @_;
+ $ifaces->{$i}->{$v} eq $e
+ or die "$i variable $v: got \"$ifaces->{$i}->{$v}\", expected: $e\n";
+};
+$ck->('vmbr0', type => 'bridge');
+$ck->('vmbr1', type => 'OVSBridge');
+$ck->('vmbr1', ovs_type => 'OVSBridge');
+$ck->('vmbr1', ovs_ports => 'eth100');
+$ck->("eth$_", type => 'eth') foreach (0, 1, 2, 3);
+$ck->('eth100', type => 'OVSPort');
+$ck->('eth100', ovs_type => 'OVSPort');
+$ck->('eth100', ovs_bridge => 'vmbr1');
+
+my $f100 = $ifaces->{vmbr0}->{families};
+die "invalid families defined for vmbr0: @$f100\n" unless [sort(@$f100)] ~~ ['inet', 'inet6'];
+
+# idempotency
+r(w());
+expect load('2');
+
+1;
diff --git a/test/etc_network_interfaces/t.update_network.pl b/test/etc_network_interfaces/t.update_network.pl
new file mode 100644
index 0000000..40fc12a
--- /dev/null
+++ b/test/etc_network_interfaces/t.update_network.pl
@@ -0,0 +1,116 @@
+save('proc_net_dev', <<'/proc/net/dev');
+eth0:
+eth1:
+/proc/net/dev
+
+my $ip = '192.168.0.2';
+my $nm = '255.255.255.0';
+my $gw = '192.168.0.1';
+my $ip6 = 'fc05::2';
+my $nm6 = '112';
+my $gw6 = 'fc05::1';
+
+# Load
+r(load('brbase'));
+
+# Create eth1
+$config->{ifaces}->{eth1} = {
+ type => 'eth',
+ method => 'static',
+ address => $ip,
+ netmask => $nm,
+ gateway => $gw,
+ families => ['inet'],
+ autostart => 1
+};
+
+# Check
+expect load('loopback') . <<"CHECK";
+source-directory interfaces.d
+
+iface eth0 inet manual
+
+auto eth1
+iface eth1 inet static
+ address $ip
+ netmask $nm
+ gateway $gw
+
+auto vmbr0
+iface vmbr0 inet static
+ address 10.0.0.2
+ netmask 255.255.255.0
+ gateway 10.0.0.1
+ bridge_ports eth0
+ bridge_stp off
+ bridge_fd 0
+
+CHECK
+
+# Reload then modify
+save('ipv4', w());
+r(load('ipv4'));
+expect load('ipv4');
+
+$config->{ifaces}->{eth1}->{$_->[0]} = $_->[1] foreach (
+ [ method6 => 'static' ],
+ [ address6 => $ip6 ],
+ [ netmask6 => $nm6 ],
+ [ gateway6 => $gw6 ],
+ [ families => ['inet', 'inet6'] ]
+);
+
+# Check
+my $final = load('loopback') . <<"CHECK";
+source-directory interfaces.d
+
+iface eth0 inet manual
+
+auto eth1
+iface eth1 inet static
+ address $ip
+ netmask $nm
+ gateway $gw
+
+iface eth1 inet6 static
+ address $ip6
+ netmask $nm6
+ gateway $gw6
+
+auto vmbr0
+iface vmbr0 inet static
+ address 10.0.0.2
+ netmask 255.255.255.0
+ gateway 10.0.0.1
+ bridge_ports eth0
+ bridge_stp off
+ bridge_fd 0
+
+CHECK
+expect $final;
+
+save('both', w());
+r(load('both'));
+expect load('both');
+
+# Reload ipv4 and replace instead of modifying
+r(load('ipv4'));
+
+$config->{ifaces}->{eth1} = {
+ type => 'eth',
+ method => 'static',
+ address => $ip,
+ netmask => $nm,
+ gateway => $gw,
+ method6 => 'static',
+ address6 => $ip6,
+ netmask6 => $nm6,
+ gateway6 => $gw6,
+ families => ['inet', 'inet6'],
+ autostart => 1
+};
+expect $final;
+r(w());
+expect $final;
+
+1;
--
2.1.4
More information about the pve-devel
mailing list