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