]> git.proxmox.com Git - pve-common.git/blame - test/etc_network_interfaces/t.list-interfaces.pl
test: list ifaces: fix indentation of expected structure
[pve-common.git] / test / etc_network_interfaces / t.list-interfaces.pl
CommitLineData
c7c4208a
WB
1# Assuming eth0..3 and eth100
2# eth0 is part of vmbr0, eth100 is part of the OVS bridge vmbr1
3# vmbr0 has ipv4 and ipv6, OVS only ipv4
4#
5# eth1..3 are completely un-configured as if the cards had just been physically
6# plugged in.
7# The expected behavior is to notice their existance and treat them as manually
8# configured interfaces.
9# Saving the file after reading would add the corresponding 'manual' lines.
10save('proc_net_dev', <<'/proc/net/dev');
11eth0:
12eth1:
13eth2:
14eth3:
15eth100:
16/proc/net/dev
17
18my %wanted = (
f110671d
TL
19 vmbr0 => {
20 address => '192.168.1.2/24',
21 gateway => '192.168.1.1',
22 address6 => 'fc05::1:1/112',
23 },
24 vmbr1 => {
25 address => '10.0.0.5/24',
26 },
c7c4208a
WB
27);
28
29save('interfaces', <<"/etc/network/interfaces");
30auto lo
31iface lo inet loopback
32
33source-directory interfaces.d
34
35iface eth0 inet manual
36
37allow-vmbr1 eth100
38iface eth100 inet manual
39 ovs_type OVSPort
40 ovs_bridge vmbr1
41
42auto vmbr0
43iface vmbr0 inet static
378c6656
AD
44 address 192.168.1.2
45 netmask 24
c7c4208a
WB
46 gateway $wanted{vmbr0}->{gateway}
47 bridge_ports eth0
48 bridge_stp off
49 bridge_fd 0
50
51iface vmbr0 inet6 static
378c6656
AD
52 address fc05::1:1
53 netmask 112
c7c4208a
WB
54
55source-directory before-ovs.d
56
4ac94c72 57allow-ovs vmbr1
c7c4208a 58iface vmbr1 inet static
378c6656
AD
59 address 10.0.0.5
60 netmask 255.255.255.0
c7c4208a
WB
61 ovs_type OVSBridge
62 ovs_ports eth100
63
64source after-ovs
65
66/etc/network/interfaces
67
68r(load('interfaces'));
69save('2', w());
70
71my $ifaces = $config->{ifaces};
72
73# check defined interfaces
74defined($ifaces->{"eth$_"})
75 or die "missing interface: eth$_\n" foreach (0, 1, 2, 3, 100);
76
77# check configuration
78foreach my $ifname (keys %wanted) {
79 my $if = $wanted{$ifname};
80 $ifaces->{$ifname}->{$_} eq $if->{$_}
81 or die "unexpected $_ for interface $ifname: \""
82 . $ifaces->{$ifname}->{$_}
83 . "\", expected: \"$if->{$_}\"\n"
84 foreach (keys %$if);
85}
86
87my $ck = sub {
88 my ($i, $v, $e) = @_;
89 $ifaces->{$i}->{$v} eq $e
90 or die "$i variable $v: got \"$ifaces->{$i}->{$v}\", expected: $e\n";
91};
92$ck->('vmbr0', type => 'bridge');
93$ck->('vmbr1', type => 'OVSBridge');
94$ck->('vmbr1', ovs_type => 'OVSBridge');
95$ck->('vmbr1', ovs_ports => 'eth100');
96$ck->("eth$_", type => 'eth') foreach (0, 1, 2, 3);
97$ck->('eth100', type => 'OVSPort');
98$ck->('eth100', ovs_type => 'OVSPort');
99$ck->('eth100', ovs_bridge => 'vmbr1');
100
1801bdaa 101my @f100 = sort @{$ifaces->{vmbr0}->{families}};
c7c4208a 102
1801bdaa
DM
103die "invalid families defined for vmbr0"
104 if (scalar(@f100) != 2) || ($f100[0] ne 'inet') || ($f100[1] ne 'inet6');
105
c7c4208a
WB
106# idempotency
107r(w());
108expect load('2');
109
1101;