]> git.ipfire.org Git - thirdparty/lldpd.git/blob - tests/integration/test_interfaces.py
tests: replace integration test by py.test+namespace tests
[thirdparty/lldpd.git] / tests / integration / test_interfaces.py
1 import pytest
2 import pyroute2
3 import time
4
5
6 def test_simple_bridge(lldpd1, lldpd, lldpcli, namespaces, links):
7 links(namespaces(3), namespaces(2)) # Another link to setup a bridge
8 with namespaces(2):
9 links.bridge('br42', 'eth1', 'eth3')
10 lldpd()
11 with namespaces(1):
12 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
13 assert out['lldp.eth0.port.descr'] == 'eth1'
14 assert out['lldp.eth0.chassis.Bridge.enabled'] == 'on'
15
16
17 @pytest.mark.skipif('Dot1' not in pytest.config.lldpd.features,
18 reason="Dot1 not supported")
19 @pytest.mark.parametrize('when', ['before', 'after'])
20 def test_bridge_with_vlan(lldpd1, lldpd, lldpcli, namespaces, links, when):
21 links(namespaces(3), namespaces(2)) # Another link to setup a bridge
22 with namespaces(2):
23 if when == 'after':
24 lldpd()
25 links.bridge('br42', 'eth1', 'eth3')
26 links.vlan('vlan100', 100, 'br42')
27 links.vlan('vlan200', 200, 'br42')
28 links.vlan('vlan300', 300, 'br42')
29 if when == 'before':
30 lldpd()
31 else:
32 # IPv6 DAD may kick in
33 time.sleep(6)
34 with namespaces(1):
35 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
36 assert out['lldp.eth0.port.descr'] == 'eth1'
37 assert out['lldp.eth0.vlan'] == \
38 ['vlan100', 'vlan200', 'vlan300']
39 assert out['lldp.eth0.vlan.vlan-id'] == \
40 ['100', '200', '300']
41
42
43 @pytest.mark.skipif('Dot3' not in pytest.config.lldpd.features,
44 reason="Dot3 not supported")
45 @pytest.mark.parametrize('when', ['before', 'after'])
46 def test_bond(lldpd1, lldpd, lldpcli, namespaces, links, when):
47 links(namespaces(3), namespaces(2)) # Another link to setup a bond
48 with namespaces(2):
49 if when == 'after':
50 lldpd()
51 idx = links.bond('bond42', 'eth3', 'eth1')
52 ipr = pyroute2.IPRoute()
53 # The bond has the MAC of eth3
54 assert ipr.get_links(idx)[0].get_attr('IFLA_ADDRESS') == \
55 "00:00:00:00:00:04"
56 if when == 'before':
57 lldpd()
58 else:
59 # IPv6 DAD may kick in
60 time.sleep(6)
61 with namespaces(1):
62 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
63 assert out['lldp.eth0.port.descr'] == 'eth1'
64 assert out['lldp.eth0.port.aggregation'] == str(idx)
65 # lldpd should be able to retrieve the right MAC
66 assert out['lldp.eth0.port.mac'] == '00:00:00:00:00:02'
67
68
69 @pytest.mark.skipif('Dot3' not in pytest.config.lldpd.features,
70 reason="Dot3 not supported")
71 @pytest.mark.skipif('Dot1' not in pytest.config.lldpd.features,
72 reason="Dot1 not supported")
73 @pytest.mark.parametrize('when', ['before', 'after'])
74 def test_bond_with_vlan(lldpd1, lldpd, lldpcli, namespaces, links, when):
75 links(namespaces(3), namespaces(2)) # Another link to setup a bond
76 with namespaces(2):
77 if when == 'after':
78 lldpd()
79 links.bond('bond42', 'eth3', 'eth1')
80 links.vlan('vlan300', 300, 'bond42')
81 links.vlan('vlan301', 301, 'bond42')
82 links.vlan('vlan302', 302, 'bond42')
83 links.vlan('vlan303', 303, 'bond42')
84 if when == 'before':
85 lldpd()
86 else:
87 # IPv6 DAD may kick in
88 time.sleep(6)
89 with namespaces(1):
90 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
91 assert out['lldp.eth0.port.descr'] == 'eth1'
92 assert out['lldp.eth0.vlan'] == \
93 ['vlan300', 'vlan301', 'vlan302', 'vlan303']
94 assert out['lldp.eth0.vlan.vlan-id'] == \
95 ['300', '301', '302', '303']
96
97
98 @pytest.mark.skipif('Dot1' not in pytest.config.lldpd.features,
99 reason="Dot1 not supported")
100 @pytest.mark.parametrize('when', ['before', 'after'])
101 def test_just_vlan(lldpd1, lldpd, lldpcli, namespaces, links, when):
102 with namespaces(2):
103 if when == 'after':
104 lldpd()
105 links.vlan('vlan300', 300, 'eth1')
106 links.vlan('vlan400', 400, 'eth1')
107 if when == 'before':
108 lldpd()
109 else:
110 time.sleep(6)
111 with namespaces(1):
112 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
113 assert out['lldp.eth0.port.descr'] == 'eth1'
114 assert out['lldp.eth0.vlan'] == ['vlan300', 'vlan400']
115 assert out['lldp.eth0.vlan.vlan-id'] == ['300', '400']
116
117
118 @pytest.mark.skipif('Dot1' not in pytest.config.lldpd.features,
119 reason="Dot1 not supported")
120 @pytest.mark.parametrize('kind', ['plain', 'bridge', 'bond'])
121 def test_remove_vlan(lldpd1, lldpd, lldpcli, namespaces, links, kind):
122 with namespaces(2):
123 if kind == 'bond':
124 iface = 'bond42'
125 links.bond(iface, 'eth1')
126 elif kind == 'bridge':
127 iface = 'bridge42'
128 links.bridge(iface, 'eth1')
129 else:
130 assert kind == 'plain'
131 iface = 'eth1'
132 links.vlan('vlan300', 300, iface)
133 links.vlan('vlan400', 400, iface)
134 links.vlan('vlan500', 500, iface)
135 lldpd()
136 links.remove('vlan300')
137 time.sleep(4)
138 with namespaces(1):
139 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
140 assert out['lldp.eth0.port.descr'] == 'eth1'
141 assert out['lldp.eth0.vlan'] == ['vlan400', 'vlan500']
142 assert out['lldp.eth0.vlan.vlan-id'] == ['400', '500']
143
144
145 @pytest.mark.skipif('Dot3' not in pytest.config.lldpd.features,
146 reason="Dot3 not supported")
147 def test_unenslave_bond(lldpd1, lldpd, lldpcli, namespaces, links):
148 with namespaces(2):
149 links.bond('bond42', 'eth1')
150 lldpd()
151 links.remove('bond42')
152 links.up('eth1')
153 time.sleep(4)
154 with namespaces(1):
155 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
156 assert out['lldp.eth0.port.descr'] == 'eth1'
157 assert 'lldp.eth0.port.aggregation' not in out
158
159
160 @pytest.mark.skipif('Dot1' not in pytest.config.lldpd.features,
161 reason="Dot1 not supported")
162 def test_unenslave_bond_with_vlan(lldpd1, lldpd, lldpcli, namespaces, links):
163 with namespaces(2):
164 links.bond('bond42', 'eth1')
165 links.vlan('vlan300', 300, 'bond42')
166 links.vlan('vlan400', 400, 'eth1')
167 lldpd()
168 links.remove('bond42')
169 links.up('eth1')
170 time.sleep(4)
171 with namespaces(1):
172 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
173 assert out['lldp.eth0.port.descr'] == 'eth1'
174 assert out['lldp.eth0.vlan'] == 'vlan400'
175 assert out['lldp.eth0.vlan.vlan-id'] == '400'
176
177
178 def test_down_then_up(lldpd1, lldpd, lldpcli, namespaces, links):
179 with namespaces(2):
180 links.down('eth1')
181 lldpd()
182 with namespaces(1):
183 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
184 assert out == {}
185 with namespaces(2):
186 links.up('eth1')
187 time.sleep(2)
188 with namespaces(1):
189 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
190 assert out['lldp.eth0.port.descr'] == 'eth1'
191
192
193 def test_down_then_up_with_vlan(lldpd1, lldpd, lldpcli, namespaces, links):
194 with namespaces(2):
195 links.vlan('vlan300', 300, 'eth1')
196 links.vlan('vlan400', 400, 'eth1')
197 links.down('eth1')
198 lldpd()
199 links.up('eth1')
200 time.sleep(2)
201 with namespaces(1):
202 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
203 assert out['lldp.eth0.port.descr'] == 'eth1'
204 assert out['lldp.eth0.vlan'] == ['vlan300', 'vlan400']
205 assert out['lldp.eth0.vlan.vlan-id'] == ['300', '400']
206
207
208 def test_new_interface(lldpd1, lldpd, lldpcli, namespaces, links):
209 with namespaces(2):
210 lldpd()
211 links(namespaces(1), namespaces(2))
212 time.sleep(2)
213 with namespaces(1):
214 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
215 assert out['lldp.eth0.port.descr'] == 'eth1'
216 assert out['lldp.eth2.port.descr'] == 'eth3'
217 assert out['lldp.eth0.rid'] == out['lldp.eth2.rid'] # Same chassis