]> git.ipfire.org Git - thirdparty/lldpd.git/blame - tests/integration/test_basic.py
test: add test for new portdescription setting
[thirdparty/lldpd.git] / tests / integration / test_basic.py
CommitLineData
e0a84778
VB
1import time
2import pytest
3import pyroute2
4
5
6def test_one_neighbor(lldpd1, lldpd, lldpcli, namespaces):
7 with namespaces(2):
8 lldpd()
9 with namespaces(1):
10 out = lldpcli("-f", "keyvalue", "show", "neighbors")
11 assert out['lldp.eth0.age'].startswith('0 day, 00:00:')
12 assert out['lldp.eth0.chassis.descr'].startswith(
13 "Spectacular GNU/Linux 2016 Linux")
14 assert 'lldp.eth0.chassis.Router.enabled' in out
15 assert 'lldp.eth0.chassis.Station.enabled' in out
16 del out['lldp.eth0.age']
17 del out['lldp.eth0.chassis.descr']
18 del out['lldp.eth0.chassis.Router.enabled']
19 del out['lldp.eth0.chassis.Station.enabled']
20 assert out == {"lldp.eth0.via": "LLDP",
21 "lldp.eth0.rid": "1",
22 "lldp.eth0.chassis.mac": "00:00:00:00:00:02",
23 "lldp.eth0.chassis.name": "ns-2.example.com",
24 "lldp.eth0.chassis.mgmt-ip": "fe80::200:ff:fe00:2",
25 "lldp.eth0.chassis.Bridge.enabled": "off",
26 "lldp.eth0.chassis.Wlan.enabled": "off",
27 "lldp.eth0.port.mac": "00:00:00:00:00:02",
78346c89
VB
28 "lldp.eth0.port.descr": "eth1",
29 "lldp.eth0.port.ttl": "120"}
e0a84778
VB
30
31
dd0d1674 32@pytest.mark.parametrize("neighbors", (5, 10, 20))
e0a84778
VB
33def test_several_neighbors(lldpd, lldpcli, links, namespaces, neighbors):
34 for i in range(2, neighbors + 1):
35 links(namespaces(1), namespaces(i))
36 for i in range(1, neighbors + 1):
37 with namespaces(i):
38 lldpd(sleep=(i == 1 and 2 or 0),
39 silent=True)
f9452218 40 time.sleep(10)
e0a84778
VB
41 with namespaces(1):
42 out = lldpcli("-f", "keyvalue", "show", "neighbors")
43 for i in range(2, neighbors + 1):
44 assert out['lldp.eth{}.chassis.name'.format((i - 2)*2)] == \
45 'ns-{}.example.com'.format(i)
46
47
a54f6012
SW
48def test_one_interface(lldpd1, lldpd, lldpcli, namespaces):
49 with namespaces(2):
50 lldpd()
51 with namespaces(1):
52 out = lldpcli("-f", "keyvalue", "show", "interfaces")
53 assert out['lldp.eth0.chassis.descr'].startswith(
54 "Spectacular GNU/Linux 2016 Linux")
55 assert 'lldp.eth0.age' in out
56 assert 'lldp.eth0.chassis.Router.enabled' in out
57 assert 'lldp.eth0.chassis.Station.enabled' in out
58 del out['lldp.eth0.age']
59 del out['lldp.eth0.chassis.descr']
60 del out['lldp.eth0.chassis.Router.enabled']
61 del out['lldp.eth0.chassis.Station.enabled']
62 assert out == {"lldp.eth0.via": "unknown",
63 "lldp.eth0.chassis.mac": "00:00:00:00:00:01",
64 "lldp.eth0.chassis.name": "ns-1.example.com",
65 "lldp.eth0.chassis.mgmt-ip": "fe80::200:ff:fe00:1",
66 "lldp.eth0.chassis.Bridge.enabled": "off",
67 "lldp.eth0.chassis.Wlan.enabled": "off",
68 "lldp.eth0.port.mac": "00:00:00:00:00:01",
69 "lldp.eth0.port.descr": "eth0",
70 "lldp.eth0.ttl.ttl": "120"}
71
72@pytest.mark.parametrize("interfaces", (5, 10, 20))
73def test_several_interfaces(lldpd, lldpcli, links, namespaces, interfaces):
74 for i in range(2, interfaces + 1):
75 links(namespaces(1), namespaces(i))
76 for i in range(1, interfaces + 1):
77 with namespaces(i):
78 lldpd()
79 with namespaces(1):
80 out = lldpcli("-f", "keyvalue", "show", "interfaces")
81 for i in range(2, interfaces + 1):
82 assert out['lldp.eth{}.chassis.mac'.format((i - 2)*2)] == \
83 '00:00:00:00:00:01'
84 assert out['lldp.eth{}.port.mac'.format((i - 2)*2)] == \
85 '00:00:00:00:00:{num:02x}'.format(num=(i - 2)*2 + 1)
86
87
e0a84778
VB
88def test_overrided_description(lldpd1, lldpd, lldpcli, namespaces):
89 with namespaces(2):
90 lldpd("-S", "Modified description")
91 with namespaces(1):
92 out = lldpcli("-f", "keyvalue", "show", "neighbors")
93 assert out['lldp.eth0.chassis.descr'] == "Modified description"
94
95
e6f64ed9
VB
96def test_overrided_description2(lldpd1, lldpd, lldpcli, namespaces):
97 with namespaces(2):
98 lldpd()
99 lldpcli("configure", "system", "description", "Modified description")
100 lldpcli("update")
101 time.sleep(1)
102 with namespaces(1):
103 out = lldpcli("-f", "keyvalue", "show", "neighbors")
104 assert out['lldp.eth0.chassis.descr'] == "Modified description"
105
106
8481f490
VB
107def test_overrided_chassisid(lldpd1, lldpd, lldpcli, namespaces):
108 with namespaces(2):
109 lldpd()
110 lldpcli("configure", "system", "chassisid", "Modified chassis ID")
111 lldpcli("update")
112 time.sleep(1)
113 with namespaces(1):
114 out = lldpcli("-f", "keyvalue", "show", "neighbors")
115 assert out['lldp.eth0.chassis.local'] == "Modified chassis ID"
116
117
118def test_overrided_chassisid_reverse(lldpd1, lldpd, lldpcli, namespaces):
119 with namespaces(2):
120 lldpd()
121 lldpcli("configure", "system", "chassisid", "Modified chassis ID")
122 lldpcli("unconfigure", "system", "chassisid")
123 lldpcli("update")
124 time.sleep(1)
125 with namespaces(1):
126 out = lldpcli("-f", "keyvalue", "show", "neighbors")
127 assert out['lldp.eth0.chassis.mac'] == "00:00:00:00:00:02"
128
129
e0a84778
VB
130def test_hide_kernel(lldpd1, lldpd, lldpcli, namespaces):
131 with namespaces(2):
132 lldpd("-k")
133 with namespaces(1):
134 out = lldpcli("-f", "keyvalue", "show", "neighbors")
135 assert out["lldp.eth0.chassis.descr"] == \
136 "Spectacular GNU/Linux 2016"
137
138
139def test_listen_only(lldpd1, lldpd, lldpcli, namespaces):
140 with namespaces(2):
141 lldpd("-r")
142 with namespaces(1):
143 out = lldpcli("-f", "keyvalue", "show", "neighbors")
144 assert out == {}
145
146
147def test_forced_management_address(lldpd1, lldpd, lldpcli, namespaces):
148 with namespaces(2):
149 lldpd("-m", "2001:db8::47")
150 with namespaces(1):
151 out = lldpcli("-f", "keyvalue", "show", "neighbors")
152 assert out["lldp.eth0.chassis.mgmt-ip"] == "2001:db8::47"
153
154
155def test_management_address(lldpd1, lldpd, lldpcli, links, namespaces):
156 with namespaces(2):
157 ipr = pyroute2.IPRoute()
158 idx = ipr.link_lookup(ifname="eth1")[0]
159 ipr.addr('add', index=idx, address="192.168.14.2", mask=24)
160 ipr.addr('add', index=idx, address="172.25.21.47", mask=24)
161 lldpd("-m", "172.25.*")
162 with namespaces(1):
163 out = lldpcli("-f", "keyvalue", "show", "neighbors")
164 assert out["lldp.eth0.chassis.mgmt-ip"] == "172.25.21.47"
e1717397
VB
165
166
878441b2
VB
167def test_change_management_address(lldpd1, lldpd, lldpcli, links, namespaces):
168 with namespaces(2):
169 ipr = pyroute2.IPRoute()
170 idx = ipr.link_lookup(ifname="eth1")[0]
171 ipr.addr('add', index=idx, address="192.168.14.2", mask=24)
172 lldpd("-m", "192.168.*")
173 # We need a short TX interval as updating the IP address
174 # doesn't trigger a resend.
175 lldpcli("configure", "lldp", "tx-interval", "2")
176 with namespaces(1):
177 out = lldpcli("-f", "keyvalue", "show", "neighbors")
178 assert out["lldp.eth0.chassis.mgmt-ip"] == "192.168.14.2"
179 with namespaces(2):
180 ipr.addr('del', index=idx, address="192.168.14.2", mask=24)
181 ipr.addr('add', index=idx, address="192.168.14.5", mask=24)
182 time.sleep(5)
183 with namespaces(1):
184 out = lldpcli("-f", "keyvalue", "show", "neighbors")
185 assert out["lldp.eth0.chassis.mgmt-ip"] == "192.168.14.5"
186
187
e1717397
VB
188def test_portid_subtype_ifname(lldpd1, lldpd, lldpcli, namespaces):
189 with namespaces(2):
190 lldpd()
8fe53e87 191 lldpcli("configure", "lldp", "portidsubtype", "ifname")
e1717397
VB
192 time.sleep(3)
193 with namespaces(1):
194 out = lldpcli("-f", "keyvalue", "show", "neighbors")
195 assert out["lldp.eth0.port.ifname"] == "eth1"
196 assert out["lldp.eth0.port.descr"] == "eth1"
197
198
199def test_portid_subtype_with_alias(lldpd1, lldpd, lldpcli, links, namespaces):
200 with namespaces(2):
201 ipr = pyroute2.IPRoute()
202 idx = ipr.link_lookup(ifname="eth1")[0]
203 ipr.link('set', index=idx, ifalias="alias of eth1")
204 lldpd()
205 with namespaces(1):
206 out = lldpcli("-f", "keyvalue", "show", "neighbors")
207 assert out["lldp.eth0.port.ifname"] == "eth1"
208 assert out["lldp.eth0.port.descr"] == "alias of eth1"
209
210
211def test_portid_subtype_macaddress(lldpd1, lldpd, lldpcli, links, namespaces):
212 with namespaces(2):
213 ipr = pyroute2.IPRoute()
214 idx = ipr.link_lookup(ifname="eth1")[0]
215 ipr.link('set', index=idx, ifalias="alias of eth1")
216 lldpd()
8fe53e87 217 lldpcli("configure", "lldp", "portidsubtype", "macaddress")
e1717397
VB
218 time.sleep(3)
219 with namespaces(1):
220 out = lldpcli("-f", "keyvalue", "show", "neighbors")
221 assert out["lldp.eth0.port.mac"] == "00:00:00:00:00:02"
222 assert out["lldp.eth0.port.descr"] == "eth1"
223
224
225def test_portid_subtype_local(lldpd1, lldpd, lldpcli, namespaces):
226 with namespaces(2):
227 lldpd()
8fe53e87 228 lldpcli("configure", "lldp", "portidsubtype", "local", "localname")
e1717397
VB
229 time.sleep(3)
230 with namespaces(1):
231 out = lldpcli("-f", "keyvalue", "show", "neighbors")
232 assert out["lldp.eth0.port.local"] == "localname"
233 assert out["lldp.eth0.port.descr"] == "eth1"
234
235
236def test_portid_subtype_local_with_description(lldpd1, lldpd, lldpcli, namespaces):
237 with namespaces(2):
238 lldpd()
8fe53e87 239 lldpcli("configure", "lldp", "portidsubtype", "local", "localname", "description", "localdescription")
e1717397
VB
240 time.sleep(3)
241 with namespaces(1):
242 out = lldpcli("-f", "keyvalue", "show", "neighbors")
243 assert out["lldp.eth0.port.local"] == "localname"
244 assert out["lldp.eth0.port.descr"] == "localdescription"
245
246
5dd953f4
VB
247def test_portdescription(lldpd1, lldpd, lldpcli, namespaces):
248 with namespaces(2):
249 lldpd()
250 lldpcli("configure", "lldp", "portdescription", "localdescription")
251 time.sleep(3)
252 with namespaces(1):
253 out = lldpcli("-f", "keyvalue", "show", "neighbors")
254 assert out["lldp.eth0.port.descr"] == "localdescription"
255
256
e1717397
VB
257def test_portid_subtype_local_with_alias(lldpd1, lldpd, lldpcli, namespaces):
258 with namespaces(2):
259 ipr = pyroute2.IPRoute()
260 idx = ipr.link_lookup(ifname="eth1")[0]
261 ipr.link('set', index=idx, ifalias="alias of eth1")
262 lldpd()
263 lldpd()
8fe53e87 264 lldpcli("configure", "lldp", "portidsubtype", "local", "localname")
e1717397
VB
265 time.sleep(3)
266 with namespaces(1):
267 out = lldpcli("-f", "keyvalue", "show", "neighbors")
268 assert out["lldp.eth0.port.local"] == "localname"
269 assert out["lldp.eth0.port.descr"] == "alias of eth1"
6934b73d
VB
270
271
272def test_port_status_txonly(lldpd, lldpcli, namespaces, links):
273 links(namespaces(1), namespaces(2))
274 with namespaces(1):
275 lldpd()
276 lldpcli("configure", "lldp", "status", "tx-only")
277 with namespaces(2):
278 lldpd()
279 with namespaces(1):
280 out = lldpcli("-f", "keyvalue", "show", "neighbors")
281 assert out == {}
282 lldpcli("update")
283 with namespaces(2):
284 out = lldpcli("-f", "keyvalue", "show", "neighbors")
285 assert out["lldp.eth1.chassis.mac"] == "00:00:00:00:00:01"
286
287
288def test_port_status_rxonly(lldpd, lldpcli, namespaces, links):
289 links(namespaces(1), namespaces(2))
290 with namespaces(1):
291 lldpd()
292 lldpcli("configure", "lldp", "status", "rx-only")
293 with namespaces(2):
294 lldpd()
295 with namespaces(1):
296 out = lldpcli("-f", "keyvalue", "show", "neighbors")
297 assert out["lldp.eth0.chassis.mac"] == "00:00:00:00:00:02"
298 lldpcli("update")
299 with namespaces(2):
300 out = lldpcli("-f", "keyvalue", "show", "neighbors")
301 assert out == {}
302
303
304def test_port_status_rxandtx(lldpd, lldpcli, namespaces, links):
305 links(namespaces(1), namespaces(2))
306 with namespaces(1):
307 lldpd()
308 lldpcli("configure", "lldp", "status", "rx-and-tx") # noop
309 with namespaces(2):
310 lldpd()
311 with namespaces(1):
312 out = lldpcli("-f", "keyvalue", "show", "neighbors")
313 assert out["lldp.eth0.chassis.mac"] == "00:00:00:00:00:02"
314 lldpcli("update")
315 with namespaces(2):
316 out = lldpcli("-f", "keyvalue", "show", "neighbors")
317 assert out["lldp.eth1.chassis.mac"] == "00:00:00:00:00:01"
318
319
320def test_port_status_disabled(lldpd, lldpcli, namespaces, links):
321 links(namespaces(1), namespaces(2))
322 with namespaces(1):
323 lldpd()
324 lldpcli("configure", "lldp", "status", "disabled")
325 with namespaces(2):
326 lldpd()
327 with namespaces(1):
328 out = lldpcli("-f", "keyvalue", "show", "neighbors")
329 assert out == {}
330 lldpcli("update")
331 with namespaces(2):
332 out = lldpcli("-f", "keyvalue", "show", "neighbors")
333 assert out == {}
334
335