]> git.ipfire.org Git - thirdparty/lldpd.git/blame - tests/integration/test_basic.py
client: fix typos in manual page (#239)
[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
48def test_overrided_description(lldpd1, lldpd, lldpcli, namespaces):
49 with namespaces(2):
50 lldpd("-S", "Modified description")
51 with namespaces(1):
52 out = lldpcli("-f", "keyvalue", "show", "neighbors")
53 assert out['lldp.eth0.chassis.descr'] == "Modified description"
54
55
56def test_hide_kernel(lldpd1, lldpd, lldpcli, namespaces):
57 with namespaces(2):
58 lldpd("-k")
59 with namespaces(1):
60 out = lldpcli("-f", "keyvalue", "show", "neighbors")
61 assert out["lldp.eth0.chassis.descr"] == \
62 "Spectacular GNU/Linux 2016"
63
64
65def test_listen_only(lldpd1, lldpd, lldpcli, namespaces):
66 with namespaces(2):
67 lldpd("-r")
68 with namespaces(1):
69 out = lldpcli("-f", "keyvalue", "show", "neighbors")
70 assert out == {}
71
72
73def test_forced_management_address(lldpd1, lldpd, lldpcli, namespaces):
74 with namespaces(2):
75 lldpd("-m", "2001:db8::47")
76 with namespaces(1):
77 out = lldpcli("-f", "keyvalue", "show", "neighbors")
78 assert out["lldp.eth0.chassis.mgmt-ip"] == "2001:db8::47"
79
80
81def test_management_address(lldpd1, lldpd, lldpcli, links, namespaces):
82 with namespaces(2):
83 ipr = pyroute2.IPRoute()
84 idx = ipr.link_lookup(ifname="eth1")[0]
85 ipr.addr('add', index=idx, address="192.168.14.2", mask=24)
86 ipr.addr('add', index=idx, address="172.25.21.47", mask=24)
87 lldpd("-m", "172.25.*")
88 with namespaces(1):
89 out = lldpcli("-f", "keyvalue", "show", "neighbors")
90 assert out["lldp.eth0.chassis.mgmt-ip"] == "172.25.21.47"
e1717397
VB
91
92
93def test_portid_subtype_ifname(lldpd1, lldpd, lldpcli, namespaces):
94 with namespaces(2):
95 lldpd()
8fe53e87 96 lldpcli("configure", "lldp", "portidsubtype", "ifname")
e1717397
VB
97 time.sleep(3)
98 with namespaces(1):
99 out = lldpcli("-f", "keyvalue", "show", "neighbors")
100 assert out["lldp.eth0.port.ifname"] == "eth1"
101 assert out["lldp.eth0.port.descr"] == "eth1"
102
103
104def test_portid_subtype_with_alias(lldpd1, lldpd, lldpcli, links, namespaces):
105 with namespaces(2):
106 ipr = pyroute2.IPRoute()
107 idx = ipr.link_lookup(ifname="eth1")[0]
108 ipr.link('set', index=idx, ifalias="alias of eth1")
109 lldpd()
110 with namespaces(1):
111 out = lldpcli("-f", "keyvalue", "show", "neighbors")
112 assert out["lldp.eth0.port.ifname"] == "eth1"
113 assert out["lldp.eth0.port.descr"] == "alias of eth1"
114
115
116def test_portid_subtype_macaddress(lldpd1, lldpd, lldpcli, links, namespaces):
117 with namespaces(2):
118 ipr = pyroute2.IPRoute()
119 idx = ipr.link_lookup(ifname="eth1")[0]
120 ipr.link('set', index=idx, ifalias="alias of eth1")
121 lldpd()
8fe53e87 122 lldpcli("configure", "lldp", "portidsubtype", "macaddress")
e1717397
VB
123 time.sleep(3)
124 with namespaces(1):
125 out = lldpcli("-f", "keyvalue", "show", "neighbors")
126 assert out["lldp.eth0.port.mac"] == "00:00:00:00:00:02"
127 assert out["lldp.eth0.port.descr"] == "eth1"
128
129
130def test_portid_subtype_local(lldpd1, lldpd, lldpcli, namespaces):
131 with namespaces(2):
132 lldpd()
8fe53e87 133 lldpcli("configure", "lldp", "portidsubtype", "local", "localname")
e1717397
VB
134 time.sleep(3)
135 with namespaces(1):
136 out = lldpcli("-f", "keyvalue", "show", "neighbors")
137 assert out["lldp.eth0.port.local"] == "localname"
138 assert out["lldp.eth0.port.descr"] == "eth1"
139
140
141def test_portid_subtype_local_with_description(lldpd1, lldpd, lldpcli, namespaces):
142 with namespaces(2):
143 lldpd()
8fe53e87 144 lldpcli("configure", "lldp", "portidsubtype", "local", "localname", "description", "localdescription")
e1717397
VB
145 time.sleep(3)
146 with namespaces(1):
147 out = lldpcli("-f", "keyvalue", "show", "neighbors")
148 assert out["lldp.eth0.port.local"] == "localname"
149 assert out["lldp.eth0.port.descr"] == "localdescription"
150
151
152def test_portid_subtype_local_with_alias(lldpd1, lldpd, lldpcli, namespaces):
153 with namespaces(2):
154 ipr = pyroute2.IPRoute()
155 idx = ipr.link_lookup(ifname="eth1")[0]
156 ipr.link('set', index=idx, ifalias="alias of eth1")
157 lldpd()
158 lldpd()
8fe53e87 159 lldpcli("configure", "lldp", "portidsubtype", "local", "localname")
e1717397
VB
160 time.sleep(3)
161 with namespaces(1):
162 out = lldpcli("-f", "keyvalue", "show", "neighbors")
163 assert out["lldp.eth0.port.local"] == "localname"
164 assert out["lldp.eth0.port.descr"] == "alias of eth1"
6934b73d
VB
165
166
167def test_port_status_txonly(lldpd, lldpcli, namespaces, links):
168 links(namespaces(1), namespaces(2))
169 with namespaces(1):
170 lldpd()
171 lldpcli("configure", "lldp", "status", "tx-only")
172 with namespaces(2):
173 lldpd()
174 with namespaces(1):
175 out = lldpcli("-f", "keyvalue", "show", "neighbors")
176 assert out == {}
177 lldpcli("update")
178 with namespaces(2):
179 out = lldpcli("-f", "keyvalue", "show", "neighbors")
180 assert out["lldp.eth1.chassis.mac"] == "00:00:00:00:00:01"
181
182
183def test_port_status_rxonly(lldpd, lldpcli, namespaces, links):
184 links(namespaces(1), namespaces(2))
185 with namespaces(1):
186 lldpd()
187 lldpcli("configure", "lldp", "status", "rx-only")
188 with namespaces(2):
189 lldpd()
190 with namespaces(1):
191 out = lldpcli("-f", "keyvalue", "show", "neighbors")
192 assert out["lldp.eth0.chassis.mac"] == "00:00:00:00:00:02"
193 lldpcli("update")
194 with namespaces(2):
195 out = lldpcli("-f", "keyvalue", "show", "neighbors")
196 assert out == {}
197
198
199def test_port_status_rxandtx(lldpd, lldpcli, namespaces, links):
200 links(namespaces(1), namespaces(2))
201 with namespaces(1):
202 lldpd()
203 lldpcli("configure", "lldp", "status", "rx-and-tx") # noop
204 with namespaces(2):
205 lldpd()
206 with namespaces(1):
207 out = lldpcli("-f", "keyvalue", "show", "neighbors")
208 assert out["lldp.eth0.chassis.mac"] == "00:00:00:00:00:02"
209 lldpcli("update")
210 with namespaces(2):
211 out = lldpcli("-f", "keyvalue", "show", "neighbors")
212 assert out["lldp.eth1.chassis.mac"] == "00:00:00:00:00:01"
213
214
215def test_port_status_disabled(lldpd, lldpcli, namespaces, links):
216 links(namespaces(1), namespaces(2))
217 with namespaces(1):
218 lldpd()
219 lldpcli("configure", "lldp", "status", "disabled")
220 with namespaces(2):
221 lldpd()
222 with namespaces(1):
223 out = lldpcli("-f", "keyvalue", "show", "neighbors")
224 assert out == {}
225 lldpcli("update")
226 with namespaces(2):
227 out = lldpcli("-f", "keyvalue", "show", "neighbors")
228 assert out == {}
229
230