]> git.proxmox.com Git - pve-common.git/blame - test/etc_network_interfaces/t.list-interfaces.pl
Tools: add unshare system call
[pve-common.git] / test / etc_network_interfaces / t.list-interfaces.pl
CommitLineData
c7c4208a
WB
1no 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.
12save('proc_net_dev', <<'/proc/net/dev');
13eth0:
14eth1:
15eth2:
16eth3:
17eth100:
18/proc/net/dev
19
20my %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
30save('interfaces', <<"/etc/network/interfaces");
31auto lo
32iface lo inet loopback
33
34source-directory interfaces.d
35
36iface eth0 inet manual
37
38allow-vmbr1 eth100
39iface eth100 inet manual
40 ovs_type OVSPort
41 ovs_bridge vmbr1
42
43auto vmbr0
44iface 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
52iface vmbr0 inet6 static
53 address $wanted{vmbr0}->{address6}
54 netmask $wanted{vmbr0}->{netmask6}
55
56source-directory before-ovs.d
57
58auto vmbr1
59iface vmbr1 inet static
60 address $wanted{vmbr1}->{address}
61 netmask $wanted{vmbr1}->{netmask}
62 ovs_type OVSBridge
63 ovs_ports eth100
64
65source after-ovs
66
67/etc/network/interfaces
68
69r(load('interfaces'));
70save('2', w());
71
72my $ifaces = $config->{ifaces};
73
74# check defined interfaces
75defined($ifaces->{"eth$_"})
76 or die "missing interface: eth$_\n" foreach (0, 1, 2, 3, 100);
77
78# check configuration
79foreach 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
88my $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
102my $f100 = $ifaces->{vmbr0}->{families};
103die "invalid families defined for vmbr0: @$f100\n" unless [sort(@$f100)] ~~ ['inet', 'inet6'];
104
105# idempotency
106r(w());
107expect load('2');
108
1091;