]> git.ipfire.org Git - thirdparty/lldpd.git/blob - tests/integration/test_interfaces.py
tests: enable test for team device
[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 time.sleep(6)
33 with namespaces(1):
34 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
35 assert out['lldp.eth0.port.descr'] == 'eth1'
36 assert out['lldp.eth0.vlan'] == \
37 ['vlan100', 'vlan200', 'vlan300']
38 assert out['lldp.eth0.vlan.vlan-id'] == \
39 ['100', '200', '300']
40
41
42 @pytest.mark.skipif('Dot3' not in pytest.config.lldpd.features,
43 reason="Dot3 not supported")
44 @pytest.mark.parametrize('when', ['before', 'after'])
45 def test_bond(lldpd1, lldpd, lldpcli, namespaces, links, when):
46 links(namespaces(3), namespaces(2)) # Another link to setup a bond
47 with namespaces(2):
48 if when == 'after':
49 lldpd()
50 idx = links.bond('bond42', 'eth3', 'eth1')
51 ipr = pyroute2.IPRoute()
52 # The bond has the MAC of eth3
53 assert ipr.get_links(idx)[0].get_attr('IFLA_ADDRESS') == \
54 "00:00:00:00:00:04"
55 if when == 'before':
56 lldpd()
57 else:
58 time.sleep(6)
59 with namespaces(1):
60 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
61 assert out['lldp.eth0.port.descr'] == 'eth1'
62 assert out['lldp.eth0.port.aggregation'] == str(idx)
63 # lldpd should be able to retrieve the right MAC
64 assert out['lldp.eth0.port.mac'] == '00:00:00:00:00:02'
65
66
67 @pytest.mark.skipif('Dot3' not in pytest.config.lldpd.features,
68 reason="Dot3 not supported")
69 @pytest.mark.parametrize('when', ['before', 'after'])
70 def test_team(lldpd1, lldpd, lldpcli, namespaces, links, when):
71 links(namespaces(3), namespaces(2)) # Another link to setup a bond
72 with namespaces(2):
73 if when == 'after':
74 lldpd()
75 idx = links.team('team42', 'eth3', 'eth1')
76 if when == 'before':
77 lldpd()
78 else:
79 time.sleep(6)
80 with namespaces(1):
81 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
82 assert out['lldp.eth0.port.descr'] == 'eth1'
83 assert out['lldp.eth0.port.aggregation'] == str(idx)
84 # Unfortunately, we cannot get the right MAC currently... So,
85 # this bit will succeed by chance.
86 assert out['lldp.eth0.port.mac'] == '00:00:00:00:00:02'
87
88
89 @pytest.mark.skipif('Dot3' not in pytest.config.lldpd.features,
90 reason="Dot3 not supported")
91 @pytest.mark.skipif('Dot1' not in pytest.config.lldpd.features,
92 reason="Dot1 not supported")
93 @pytest.mark.parametrize('when', ['before', 'after'])
94 def test_bond_with_vlan(lldpd1, lldpd, lldpcli, namespaces, links, when):
95 links(namespaces(3), namespaces(2)) # Another link to setup a bond
96 with namespaces(2):
97 if when == 'after':
98 lldpd()
99 links.bond('bond42', 'eth3', 'eth1')
100 links.vlan('vlan300', 300, 'bond42')
101 links.vlan('vlan301', 301, 'bond42')
102 links.vlan('vlan302', 302, 'bond42')
103 links.vlan('vlan303', 303, 'bond42')
104 if when == 'before':
105 lldpd()
106 else:
107 time.sleep(6)
108 with namespaces(1):
109 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
110 assert out['lldp.eth0.port.descr'] == 'eth1'
111 assert out['lldp.eth0.vlan'] == \
112 ['vlan300', 'vlan301', 'vlan302', 'vlan303']
113 assert out['lldp.eth0.vlan.vlan-id'] == \
114 ['300', '301', '302', '303']
115
116
117 @pytest.mark.skipif('Dot1' not in pytest.config.lldpd.features,
118 reason="Dot1 not supported")
119 @pytest.mark.parametrize('when', ['before', 'after'])
120 def test_just_vlan(lldpd1, lldpd, lldpcli, namespaces, links, when):
121 with namespaces(2):
122 if when == 'after':
123 lldpd()
124 links.vlan('vlan300', 300, 'eth1')
125 links.vlan('vlan400', 400, 'eth1')
126 if when == 'before':
127 lldpd()
128 else:
129 time.sleep(6)
130 with namespaces(1):
131 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
132 assert out['lldp.eth0.port.descr'] == 'eth1'
133 assert out['lldp.eth0.vlan'] == ['vlan300', 'vlan400']
134 assert out['lldp.eth0.vlan.vlan-id'] == ['300', '400']
135
136
137 @pytest.mark.skipif('Dot1' not in pytest.config.lldpd.features,
138 reason="Dot1 not supported")
139 @pytest.mark.parametrize('kind', ['plain', 'bridge', 'bond'])
140 def test_remove_vlan(lldpd1, lldpd, lldpcli, namespaces, links, kind):
141 with namespaces(2):
142 if kind == 'bond':
143 iface = 'bond42'
144 links.bond(iface, 'eth1')
145 elif kind == 'bridge':
146 iface = 'bridge42'
147 links.bridge(iface, 'eth1')
148 else:
149 assert kind == 'plain'
150 iface = 'eth1'
151 links.vlan('vlan300', 300, iface)
152 links.vlan('vlan400', 400, iface)
153 links.vlan('vlan500', 500, iface)
154 lldpd()
155 links.remove('vlan300')
156 time.sleep(6)
157 with namespaces(1):
158 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
159 assert out['lldp.eth0.port.descr'] == 'eth1'
160 assert out['lldp.eth0.vlan'] == ['vlan400', 'vlan500']
161 assert out['lldp.eth0.vlan.vlan-id'] == ['400', '500']
162
163
164 @pytest.mark.skipif('Dot3' not in pytest.config.lldpd.features,
165 reason="Dot3 not supported")
166 def test_unenslave_bond(lldpd1, lldpd, lldpcli, namespaces, links):
167 with namespaces(2):
168 links.bond('bond42', 'eth1')
169 lldpd()
170 links.remove('bond42')
171 links.up('eth1')
172 time.sleep(6)
173 with namespaces(1):
174 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
175 assert out['lldp.eth0.port.descr'] == 'eth1'
176 assert 'lldp.eth0.port.aggregation' not in out
177
178
179 @pytest.mark.skipif('Dot1' not in pytest.config.lldpd.features,
180 reason="Dot1 not supported")
181 def test_unenslave_bond_with_vlan(lldpd1, lldpd, lldpcli, namespaces, links):
182 with namespaces(2):
183 links.bond('bond42', 'eth1')
184 links.vlan('vlan300', 300, 'bond42')
185 links.vlan('vlan400', 400, 'eth1')
186 lldpd()
187 links.remove('bond42')
188 links.up('eth1')
189 time.sleep(6)
190 with namespaces(1):
191 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
192 assert out['lldp.eth0.port.descr'] == 'eth1'
193 assert out['lldp.eth0.vlan'] == 'vlan400'
194 assert out['lldp.eth0.vlan.vlan-id'] == '400'
195
196
197 def test_down_then_up(lldpd1, lldpd, lldpcli, namespaces, links):
198 with namespaces(2):
199 links.down('eth1')
200 lldpd()
201 with namespaces(1):
202 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
203 assert out == {}
204 with namespaces(2):
205 links.up('eth1')
206 time.sleep(6)
207 with namespaces(1):
208 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
209 assert out['lldp.eth0.port.descr'] == 'eth1'
210
211
212 @pytest.mark.skipif('Dot1' not in pytest.config.lldpd.features,
213 reason="Dot1 not supported")
214 def test_down_then_up_with_vlan(lldpd1, lldpd, lldpcli, namespaces, links):
215 with namespaces(2):
216 links.vlan('vlan300', 300, 'eth1')
217 links.vlan('vlan400', 400, 'eth1')
218 links.down('eth1')
219 lldpd()
220 links.up('eth1')
221 time.sleep(6)
222 with namespaces(1):
223 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
224 assert out['lldp.eth0.port.descr'] == 'eth1'
225 assert out['lldp.eth0.vlan'] == ['vlan300', 'vlan400']
226 assert out['lldp.eth0.vlan.vlan-id'] == ['300', '400']
227
228
229 def test_new_interface(lldpd1, lldpd, lldpcli, namespaces, links):
230 with namespaces(2):
231 lldpd()
232 links(namespaces(1), namespaces(2), 4)
233 time.sleep(6)
234 with namespaces(1):
235 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
236 assert out['lldp.eth0.port.descr'] == 'eth1'
237 assert out['lldp.eth2.port.descr'] == 'eth3'
238 assert out['lldp.eth0.rid'] == out['lldp.eth2.rid'] # Same chassis