]>
git.ipfire.org Git - thirdparty/lldpd.git/blob - tests/integration/test_basic.py
1ff7f4b728f77ea5b6f75cd8c2e88e958216d189
6 def test_one_neighbor(lldpd1
, lldpd
, lldpcli
, namespaces
):
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",
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",
28 "lldp.eth0.port.descr": "eth1",
29 "lldp.eth0.port.ttl": "120"}
32 @pytest.mark
.parametrize("neighbors", (5, 10, 20))
33 def 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):
38 lldpd(sleep
=(i
== 1 and 2 or 0),
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
)
48 def test_one_interface(lldpd1
, lldpd
, lldpcli
, namespaces
):
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"}
72 @pytest.mark
.parametrize("interfaces", (5, 10, 20))
73 def 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):
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)] == \
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)
88 def test_overrided_description(lldpd1
, lldpd
, lldpcli
, namespaces
):
90 lldpd("-S", "Modified description")
92 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
93 assert out
['lldp.eth0.chassis.descr'] == "Modified description"
96 def test_overrided_description2(lldpd1
, lldpd
, lldpcli
, namespaces
):
99 lldpcli("configure", "system", "description", "Modified description")
103 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
104 assert out
['lldp.eth0.chassis.descr'] == "Modified description"
107 def test_overrided_chassisid(lldpd1
, lldpd
, lldpcli
, namespaces
):
110 lldpcli("configure", "system", "chassisid", "Modified chassis ID")
114 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
115 assert out
['lldp.eth0.chassis.local'] == "Modified chassis ID"
118 def test_overrided_chassisid_reverse(lldpd1
, lldpd
, lldpcli
, namespaces
):
121 lldpcli("configure", "system", "chassisid", "Modified chassis ID")
122 lldpcli("unconfigure", "system", "chassisid")
126 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
127 assert out
['lldp.eth0.chassis.mac'] == "00:00:00:00:00:02"
130 def test_hide_kernel(lldpd1
, lldpd
, lldpcli
, namespaces
):
134 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
135 assert out
["lldp.eth0.chassis.descr"] == \
136 "Spectacular GNU/Linux 2016"
139 def test_listen_only(lldpd1
, lldpd
, lldpcli
, namespaces
):
143 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
147 def test_forced_management_address(lldpd1
, lldpd
, lldpcli
, namespaces
):
149 lldpd("-m", "2001:db8::47")
151 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
152 assert out
["lldp.eth0.chassis.mgmt-ip"] == "2001:db8::47"
155 def test_management_address(lldpd1
, lldpd
, lldpcli
, links
, namespaces
):
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.*")
163 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
164 assert out
["lldp.eth0.chassis.mgmt-ip"] == "172.25.21.47"
167 def test_portid_subtype_ifname(lldpd1
, lldpd
, lldpcli
, namespaces
):
170 lldpcli("configure", "lldp", "portidsubtype", "ifname")
173 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
174 assert out
["lldp.eth0.port.ifname"] == "eth1"
175 assert out
["lldp.eth0.port.descr"] == "eth1"
178 def test_portid_subtype_with_alias(lldpd1
, lldpd
, lldpcli
, links
, namespaces
):
180 ipr
= pyroute2
.IPRoute()
181 idx
= ipr
.link_lookup(ifname
="eth1")[0]
182 ipr
.link('set', index
=idx
, ifalias
="alias of eth1")
185 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
186 assert out
["lldp.eth0.port.ifname"] == "eth1"
187 assert out
["lldp.eth0.port.descr"] == "alias of eth1"
190 def test_portid_subtype_macaddress(lldpd1
, lldpd
, lldpcli
, links
, namespaces
):
192 ipr
= pyroute2
.IPRoute()
193 idx
= ipr
.link_lookup(ifname
="eth1")[0]
194 ipr
.link('set', index
=idx
, ifalias
="alias of eth1")
196 lldpcli("configure", "lldp", "portidsubtype", "macaddress")
199 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
200 assert out
["lldp.eth0.port.mac"] == "00:00:00:00:00:02"
201 assert out
["lldp.eth0.port.descr"] == "eth1"
204 def test_portid_subtype_local(lldpd1
, lldpd
, lldpcli
, namespaces
):
207 lldpcli("configure", "lldp", "portidsubtype", "local", "localname")
210 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
211 assert out
["lldp.eth0.port.local"] == "localname"
212 assert out
["lldp.eth0.port.descr"] == "eth1"
215 def test_portid_subtype_local_with_description(lldpd1
, lldpd
, lldpcli
, namespaces
):
218 lldpcli("configure", "lldp", "portidsubtype", "local", "localname", "description", "localdescription")
221 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
222 assert out
["lldp.eth0.port.local"] == "localname"
223 assert out
["lldp.eth0.port.descr"] == "localdescription"
226 def test_portid_subtype_local_with_alias(lldpd1
, lldpd
, lldpcli
, namespaces
):
228 ipr
= pyroute2
.IPRoute()
229 idx
= ipr
.link_lookup(ifname
="eth1")[0]
230 ipr
.link('set', index
=idx
, ifalias
="alias of eth1")
233 lldpcli("configure", "lldp", "portidsubtype", "local", "localname")
236 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
237 assert out
["lldp.eth0.port.local"] == "localname"
238 assert out
["lldp.eth0.port.descr"] == "alias of eth1"
241 def test_port_status_txonly(lldpd
, lldpcli
, namespaces
, links
):
242 links(namespaces(1), namespaces(2))
245 lldpcli("configure", "lldp", "status", "tx-only")
249 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
253 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
254 assert out
["lldp.eth1.chassis.mac"] == "00:00:00:00:00:01"
257 def test_port_status_rxonly(lldpd
, lldpcli
, namespaces
, links
):
258 links(namespaces(1), namespaces(2))
261 lldpcli("configure", "lldp", "status", "rx-only")
265 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
266 assert out
["lldp.eth0.chassis.mac"] == "00:00:00:00:00:02"
269 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
273 def test_port_status_rxandtx(lldpd
, lldpcli
, namespaces
, links
):
274 links(namespaces(1), namespaces(2))
277 lldpcli("configure", "lldp", "status", "rx-and-tx") # noop
281 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
282 assert out
["lldp.eth0.chassis.mac"] == "00:00:00:00:00:02"
285 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
286 assert out
["lldp.eth1.chassis.mac"] == "00:00:00:00:00:01"
289 def test_port_status_disabled(lldpd
, lldpcli
, namespaces
, links
):
290 links(namespaces(1), namespaces(2))
293 lldpcli("configure", "lldp", "status", "disabled")
297 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
301 out
= lldpcli("-f", "keyvalue", "show", "neighbors")