]> git.proxmox.com Git - pve-common.git/blame - test/etc_network_interfaces/t.list-interfaces.pl
inotify/interfaces: ensure cidr, address and netmask are set correctly
[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 19 vmbr0 => {
fa6e6946
TL
20 address => '192.168.1.2',
21 netmask => '24',
22 cidr => '192.168.1.2/24',
f110671d 23 gateway => '192.168.1.1',
fa6e6946
TL
24 address6 => 'fc05::1:1',
25 netmask6 => '112',
26 cidr6 => 'fc05::1:1/112',
f110671d
TL
27 },
28 vmbr1 => {
fa6e6946
TL
29 address => '10.0.0.5',
30 netmask => '24',
31 cidr => '10.0.0.5/24',
f110671d 32 },
c7c4208a
WB
33);
34
35save('interfaces', <<"/etc/network/interfaces");
36auto lo
37iface lo inet loopback
38
39source-directory interfaces.d
40
41iface eth0 inet manual
42
43allow-vmbr1 eth100
44iface eth100 inet manual
45 ovs_type OVSPort
46 ovs_bridge vmbr1
47
48auto vmbr0
49iface vmbr0 inet static
378c6656
AD
50 address 192.168.1.2
51 netmask 24
c7c4208a
WB
52 gateway $wanted{vmbr0}->{gateway}
53 bridge_ports eth0
54 bridge_stp off
55 bridge_fd 0
56
57iface vmbr0 inet6 static
378c6656
AD
58 address fc05::1:1
59 netmask 112
c7c4208a
WB
60
61source-directory before-ovs.d
62
4ac94c72 63allow-ovs vmbr1
c7c4208a 64iface vmbr1 inet static
378c6656
AD
65 address 10.0.0.5
66 netmask 255.255.255.0
c7c4208a
WB
67 ovs_type OVSBridge
68 ovs_ports eth100
69
70source after-ovs
71
72/etc/network/interfaces
73
74r(load('interfaces'));
75save('2', w());
76
77my $ifaces = $config->{ifaces};
78
79# check defined interfaces
80defined($ifaces->{"eth$_"})
81 or die "missing interface: eth$_\n" foreach (0, 1, 2, 3, 100);
82
83# check configuration
84foreach my $ifname (keys %wanted) {
85 my $if = $wanted{$ifname};
86 $ifaces->{$ifname}->{$_} eq $if->{$_}
87 or die "unexpected $_ for interface $ifname: \""
88 . $ifaces->{$ifname}->{$_}
89 . "\", expected: \"$if->{$_}\"\n"
90 foreach (keys %$if);
91}
92
93my $ck = sub {
94 my ($i, $v, $e) = @_;
95 $ifaces->{$i}->{$v} eq $e
96 or die "$i variable $v: got \"$ifaces->{$i}->{$v}\", expected: $e\n";
97};
98$ck->('vmbr0', type => 'bridge');
99$ck->('vmbr1', type => 'OVSBridge');
100$ck->('vmbr1', ovs_type => 'OVSBridge');
101$ck->('vmbr1', ovs_ports => 'eth100');
102$ck->("eth$_", type => 'eth') foreach (0, 1, 2, 3);
103$ck->('eth100', type => 'OVSPort');
104$ck->('eth100', ovs_type => 'OVSPort');
105$ck->('eth100', ovs_bridge => 'vmbr1');
106
1801bdaa 107my @f100 = sort @{$ifaces->{vmbr0}->{families}};
c7c4208a 108
1801bdaa
DM
109die "invalid families defined for vmbr0"
110 if (scalar(@f100) != 2) || ($f100[0] ne 'inet') || ($f100[1] ne 'inet6');
111
c7c4208a
WB
112# idempotency
113r(w());
114expect load('2');
115
1161;