]> git.ipfire.org Git - thirdparty/lldpd.git/blame - tests/integration/test_basic.py
daemon: ensure chassis-related changes are updated immediately
[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
e0a84778
VB
107def test_hide_kernel(lldpd1, lldpd, lldpcli, namespaces):
108 with namespaces(2):
109 lldpd("-k")
110 with namespaces(1):
111 out = lldpcli("-f", "keyvalue", "show", "neighbors")
112 assert out["lldp.eth0.chassis.descr"] == \
113 "Spectacular GNU/Linux 2016"
114
115
116def test_listen_only(lldpd1, lldpd, lldpcli, namespaces):
117 with namespaces(2):
118 lldpd("-r")
119 with namespaces(1):
120 out = lldpcli("-f", "keyvalue", "show", "neighbors")
121 assert out == {}
122
123
124def test_forced_management_address(lldpd1, lldpd, lldpcli, namespaces):
125 with namespaces(2):
126 lldpd("-m", "2001:db8::47")
127 with namespaces(1):
128 out = lldpcli("-f", "keyvalue", "show", "neighbors")
129 assert out["lldp.eth0.chassis.mgmt-ip"] == "2001:db8::47"
130
131
132def test_management_address(lldpd1, lldpd, lldpcli, links, namespaces):
133 with namespaces(2):
134 ipr = pyroute2.IPRoute()
135 idx = ipr.link_lookup(ifname="eth1")[0]
136 ipr.addr('add', index=idx, address="192.168.14.2", mask=24)
137 ipr.addr('add', index=idx, address="172.25.21.47", mask=24)
138 lldpd("-m", "172.25.*")
139 with namespaces(1):
140 out = lldpcli("-f", "keyvalue", "show", "neighbors")
141 assert out["lldp.eth0.chassis.mgmt-ip"] == "172.25.21.47"
e1717397
VB
142
143
144def test_portid_subtype_ifname(lldpd1, lldpd, lldpcli, namespaces):
145 with namespaces(2):
146 lldpd()
8fe53e87 147 lldpcli("configure", "lldp", "portidsubtype", "ifname")
e1717397
VB
148 time.sleep(3)
149 with namespaces(1):
150 out = lldpcli("-f", "keyvalue", "show", "neighbors")
151 assert out["lldp.eth0.port.ifname"] == "eth1"
152 assert out["lldp.eth0.port.descr"] == "eth1"
153
154
155def test_portid_subtype_with_alias(lldpd1, lldpd, lldpcli, links, namespaces):
156 with namespaces(2):
157 ipr = pyroute2.IPRoute()
158 idx = ipr.link_lookup(ifname="eth1")[0]
159 ipr.link('set', index=idx, ifalias="alias of eth1")
160 lldpd()
161 with namespaces(1):
162 out = lldpcli("-f", "keyvalue", "show", "neighbors")
163 assert out["lldp.eth0.port.ifname"] == "eth1"
164 assert out["lldp.eth0.port.descr"] == "alias of eth1"
165
166
167def test_portid_subtype_macaddress(lldpd1, lldpd, lldpcli, links, namespaces):
168 with namespaces(2):
169 ipr = pyroute2.IPRoute()
170 idx = ipr.link_lookup(ifname="eth1")[0]
171 ipr.link('set', index=idx, ifalias="alias of eth1")
172 lldpd()
8fe53e87 173 lldpcli("configure", "lldp", "portidsubtype", "macaddress")
e1717397
VB
174 time.sleep(3)
175 with namespaces(1):
176 out = lldpcli("-f", "keyvalue", "show", "neighbors")
177 assert out["lldp.eth0.port.mac"] == "00:00:00:00:00:02"
178 assert out["lldp.eth0.port.descr"] == "eth1"
179
180
181def test_portid_subtype_local(lldpd1, lldpd, lldpcli, namespaces):
182 with namespaces(2):
183 lldpd()
8fe53e87 184 lldpcli("configure", "lldp", "portidsubtype", "local", "localname")
e1717397
VB
185 time.sleep(3)
186 with namespaces(1):
187 out = lldpcli("-f", "keyvalue", "show", "neighbors")
188 assert out["lldp.eth0.port.local"] == "localname"
189 assert out["lldp.eth0.port.descr"] == "eth1"
190
191
192def test_portid_subtype_local_with_description(lldpd1, lldpd, lldpcli, namespaces):
193 with namespaces(2):
194 lldpd()
8fe53e87 195 lldpcli("configure", "lldp", "portidsubtype", "local", "localname", "description", "localdescription")
e1717397
VB
196 time.sleep(3)
197 with namespaces(1):
198 out = lldpcli("-f", "keyvalue", "show", "neighbors")
199 assert out["lldp.eth0.port.local"] == "localname"
200 assert out["lldp.eth0.port.descr"] == "localdescription"
201
202
203def test_portid_subtype_local_with_alias(lldpd1, lldpd, lldpcli, namespaces):
204 with namespaces(2):
205 ipr = pyroute2.IPRoute()
206 idx = ipr.link_lookup(ifname="eth1")[0]
207 ipr.link('set', index=idx, ifalias="alias of eth1")
208 lldpd()
209 lldpd()
8fe53e87 210 lldpcli("configure", "lldp", "portidsubtype", "local", "localname")
e1717397
VB
211 time.sleep(3)
212 with namespaces(1):
213 out = lldpcli("-f", "keyvalue", "show", "neighbors")
214 assert out["lldp.eth0.port.local"] == "localname"
215 assert out["lldp.eth0.port.descr"] == "alias of eth1"
6934b73d
VB
216
217
218def test_port_status_txonly(lldpd, lldpcli, namespaces, links):
219 links(namespaces(1), namespaces(2))
220 with namespaces(1):
221 lldpd()
222 lldpcli("configure", "lldp", "status", "tx-only")
223 with namespaces(2):
224 lldpd()
225 with namespaces(1):
226 out = lldpcli("-f", "keyvalue", "show", "neighbors")
227 assert out == {}
228 lldpcli("update")
229 with namespaces(2):
230 out = lldpcli("-f", "keyvalue", "show", "neighbors")
231 assert out["lldp.eth1.chassis.mac"] == "00:00:00:00:00:01"
232
233
234def test_port_status_rxonly(lldpd, lldpcli, namespaces, links):
235 links(namespaces(1), namespaces(2))
236 with namespaces(1):
237 lldpd()
238 lldpcli("configure", "lldp", "status", "rx-only")
239 with namespaces(2):
240 lldpd()
241 with namespaces(1):
242 out = lldpcli("-f", "keyvalue", "show", "neighbors")
243 assert out["lldp.eth0.chassis.mac"] == "00:00:00:00:00:02"
244 lldpcli("update")
245 with namespaces(2):
246 out = lldpcli("-f", "keyvalue", "show", "neighbors")
247 assert out == {}
248
249
250def test_port_status_rxandtx(lldpd, lldpcli, namespaces, links):
251 links(namespaces(1), namespaces(2))
252 with namespaces(1):
253 lldpd()
254 lldpcli("configure", "lldp", "status", "rx-and-tx") # noop
255 with namespaces(2):
256 lldpd()
257 with namespaces(1):
258 out = lldpcli("-f", "keyvalue", "show", "neighbors")
259 assert out["lldp.eth0.chassis.mac"] == "00:00:00:00:00:02"
260 lldpcli("update")
261 with namespaces(2):
262 out = lldpcli("-f", "keyvalue", "show", "neighbors")
263 assert out["lldp.eth1.chassis.mac"] == "00:00:00:00:00:01"
264
265
266def test_port_status_disabled(lldpd, lldpcli, namespaces, links):
267 links(namespaces(1), namespaces(2))
268 with namespaces(1):
269 lldpd()
270 lldpcli("configure", "lldp", "status", "disabled")
271 with namespaces(2):
272 lldpd()
273 with namespaces(1):
274 out = lldpcli("-f", "keyvalue", "show", "neighbors")
275 assert out == {}
276 lldpcli("update")
277 with namespaces(2):
278 out = lldpcli("-f", "keyvalue", "show", "neighbors")
279 assert out == {}
280
281