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