tests: list/create/update network interfaces

This commit is contained in:
Wolfgang Bumiller 2015-06-25 11:54:34 +02:00 committed by Dietmar Maurer
parent 562fad0bab
commit c7c4208a33
4 changed files with 342 additions and 0 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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;