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