Debian Codegraph @

tests/units/anta_tests/test_vxlan.py

raw symbols SCIP
1 # Copyright (c) 2023-2026 Arista Networks, Inc.
2 # Use of this source code is governed by the Apache License 2.0
3 # that can be found in the LICENSE file.
4 """Tests for anta.tests.vxlan.py."""
5
6 from __future__ import annotations
7
8 from typing import TypeAlias
9
10 from anta.models import AntaTest
11 from anta.result_manager.models import AntaTestStatus
12 from anta.tests.vxlan import (
13 VerifyVxlan1ConnSettings,
14 VerifyVxlan1Interface,
15 VerifyVxlan1VVTEPIPAddresses,
16 VerifyVxlanConfigSanity,
17 VerifyVxlanVniBinding,
18 VerifyVxlanVtep,
19 )
20 from tests.units.anta_tests import AntaUnitTest, test
21
22 AntaUnitTestData: TypeAlias = dict[tuple[type[AntaTest], str], AntaUnitTest]
23
24 DATA: AntaUnitTestData = {
25 (VerifyVxlan1Interface, "success"): {
26 "eos_data": [{"interfaceDescriptions": {"Vxlan1": {"lineProtocolStatus": "up", "interfaceStatus": "up"}}}],
27 "expected": {"result": AntaTestStatus.SUCCESS},
28 },
29 (VerifyVxlan1Interface, "skipped"): {
30 "eos_data": [{"interfaceDescriptions": {"Loopback0": {"lineProtocolStatus": "up", "interfaceStatus": "up"}}}],
31 "expected": {"result": AntaTestStatus.SKIPPED, "messages": ["Interface: Vxlan1 - Not configured"]},
32 },
33 (VerifyVxlan1Interface, "failure-down-up"): {
34 "eos_data": [{"interfaceDescriptions": {"Vxlan1": {"lineProtocolStatus": "down", "interfaceStatus": "up"}}}],
35 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["Interface: Vxlan1 - Incorrect Line protocol status/Status - Expected: up/up Actual: down/up"]},
36 },
37 (VerifyVxlan1Interface, "failure-up-down"): {
38 "eos_data": [{"interfaceDescriptions": {"Vxlan1": {"lineProtocolStatus": "up", "interfaceStatus": "down"}}}],
39 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["Interface: Vxlan1 - Incorrect Line protocol status/Status - Expected: up/up Actual: up/down"]},
40 },
41 (VerifyVxlan1Interface, "failure-down-down"): {
42 "eos_data": [{"interfaceDescriptions": {"Vxlan1": {"lineProtocolStatus": "down", "interfaceStatus": "down"}}}],
43 "expected": {
44 "result": AntaTestStatus.FAILURE,
45 "messages": ["Interface: Vxlan1 - Incorrect Line protocol status/Status - Expected: up/up Actual: down/down"],
46 },
47 },
48 (VerifyVxlanConfigSanity, "success"): {
49 "eos_data": [
50 {
51 "categories": {
52 "localVtep": {
53 "description": "Local VTEP Configuration Check",
54 "allCheckPass": True,
55 "detail": "",
56 "hasWarning": False,
57 "items": [
58 {"name": "Loopback IP Address", "checkPass": True, "hasWarning": False, "detail": ""},
59 {"name": "VLAN-VNI Map", "checkPass": True, "hasWarning": False, "detail": ""},
60 {"name": "Flood List", "checkPass": True, "hasWarning": False, "detail": ""},
61 {"name": "Routing", "checkPass": True, "hasWarning": False, "detail": ""},
62 {"name": "VNI VRF ACL", "checkPass": True, "hasWarning": False, "detail": ""},
63 {"name": "VRF-VNI Dynamic VLAN", "checkPass": True, "hasWarning": False, "detail": ""},
64 {"name": "Decap VRF-VNI Map", "checkPass": True, "hasWarning": False, "detail": ""},
65 ],
66 },
67 "remoteVtep": {
68 "description": "Remote VTEP Configuration Check",
69 "allCheckPass": True,
70 "detail": "",
71 "hasWarning": False,
72 "items": [{"name": "Remote VTEP", "checkPass": True, "hasWarning": False, "detail": ""}],
73 },
74 "pd": {
75 "description": "Platform Dependent Check",
76 "allCheckPass": True,
77 "detail": "",
78 "hasWarning": False,
79 "items": [
80 {"name": "VXLAN Bridging", "checkPass": True, "hasWarning": False, "detail": ""},
81 {"name": "VXLAN Routing", "checkPass": True, "hasWarning": False, "detail": "VXLAN Routing not enabled"},
82 ],
83 },
84 "cvx": {
85 "description": "CVX Configuration Check",
86 "allCheckPass": True,
87 "detail": "",
88 "hasWarning": False,
89 "items": [{"name": "CVX Server", "checkPass": True, "hasWarning": False, "detail": "Not in controller client mode"}],
90 },
91 "mlag": {
92 "description": "MLAG Configuration Check",
93 "allCheckPass": True,
94 "detail": "Run 'show mlag config-sanity' to verify MLAG config",
95 "hasWarning": False,
96 "items": [
97 {"name": "Peer VTEP IP", "checkPass": True, "hasWarning": False, "detail": ""},
98 {"name": "MLAG VTEP IP", "checkPass": True, "hasWarning": False, "detail": ""},
99 {"name": "Virtual VTEP IP", "checkPass": True, "hasWarning": False, "detail": ""},
100 {"name": "Peer VLAN-VNI", "checkPass": True, "hasWarning": False, "detail": ""},
101 {"name": "MLAG Inactive State", "checkPass": True, "hasWarning": False, "detail": ""},
102 ],
103 },
104 },
105 "warnings": [],
106 }
107 ],
108 "expected": {"result": AntaTestStatus.SUCCESS},
109 },
110 (VerifyVxlanConfigSanity, "failure"): {
111 "eos_data": [
112 {
113 "categories": {
114 "localVtep": {
115 "description": "Local VTEP Configuration Check",
116 "allCheckPass": False,
117 "detail": "",
118 "hasWarning": True,
119 "items": [
120 {"name": "Loopback IP Address", "checkPass": True, "hasWarning": False, "detail": ""},
121 {"name": "VLAN-VNI Map", "checkPass": False, "hasWarning": False, "detail": "No VLAN-VNI mapping in Vxlan1"},
122 {"name": "Flood List", "checkPass": False, "hasWarning": True, "detail": "No VXLAN VLANs in Vxlan1"},
123 {"name": "Routing", "checkPass": True, "hasWarning": False, "detail": ""},
124 {"name": "VNI VRF ACL", "checkPass": True, "hasWarning": False, "detail": ""},
125 {"name": "VRF-VNI Dynamic VLAN", "checkPass": True, "hasWarning": False, "detail": ""},
126 {"name": "Decap VRF-VNI Map", "checkPass": True, "hasWarning": False, "detail": ""},
127 ],
128 },
129 "remoteVtep": {
130 "description": "Remote VTEP Configuration Check",
131 "allCheckPass": True,
132 "detail": "",
133 "hasWarning": False,
134 "items": [{"name": "Remote VTEP", "checkPass": True, "hasWarning": False, "detail": ""}],
135 },
136 "pd": {
137 "description": "Platform Dependent Check",
138 "allCheckPass": True,
139 "detail": "",
140 "hasWarning": False,
141 "items": [
142 {"name": "VXLAN Bridging", "checkPass": True, "hasWarning": False, "detail": ""},
143 {"name": "VXLAN Routing", "checkPass": True, "hasWarning": False, "detail": "VXLAN Routing not enabled"},
144 ],
145 },
146 "cvx": {
147 "description": "CVX Configuration Check",
148 "allCheckPass": True,
149 "detail": "",
150 "hasWarning": False,
151 "items": [{"name": "CVX Server", "checkPass": True, "hasWarning": False, "detail": "Not in controller client mode"}],
152 },
153 "mlag": {
154 "description": "MLAG Configuration Check",
155 "allCheckPass": True,
156 "detail": "Run 'show mlag config-sanity' to verify MLAG config",
157 "hasWarning": False,
158 "items": [
159 {"name": "Peer VTEP IP", "checkPass": True, "hasWarning": False, "detail": ""},
160 {"name": "MLAG VTEP IP", "checkPass": True, "hasWarning": False, "detail": ""},
161 {"name": "Virtual VTEP IP", "checkPass": True, "hasWarning": False, "detail": ""},
162 {"name": "Peer VLAN-VNI", "checkPass": True, "hasWarning": False, "detail": ""},
163 {"name": "MLAG Inactive State", "checkPass": True, "hasWarning": False, "detail": ""},
164 ],
165 },
166 },
167 "warnings": ["Your configuration contains warnings. This does not mean misconfigurations. But you may wish to re-check your configurations."],
168 }
169 ],
170 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["Vxlan Category: localVtep - Config sanity check is not passing"]},
171 },
172 (VerifyVxlanConfigSanity, "skipped"): {
173 "eos_data": [{"categories": {}}],
174 "expected": {"result": AntaTestStatus.SKIPPED, "messages": ["VXLAN is not configured"]},
175 },
176 (VerifyVxlanVniBinding, "success"): {
177 "eos_data": [
178 {
179 "vxlanIntfs": {
180 "Vxlan1": {
181 "vniBindings": {
182 "10020": {"vlan": 20, "dynamicVlan": False, "source": "static", "interfaces": {"Ethernet31": {"dot1q": 0}, "Vxlan1": {"dot1q": 20}}}
183 },
184 "vniBindingsToVrf": {"500": {"vrfName": "TEST", "vlan": 1199, "source": "evpn"}, "600": {"vrfName": "PROD", "vlan": 1198, "source": "evpn"}},
185 }
186 }
187 }
188 ],
189 "inputs": {"bindings": {10020: 20, 500: 1199, 600: "PROD"}},
190 "expected": {"result": AntaTestStatus.SUCCESS},
191 },
192 (VerifyVxlanVniBinding, "failure-no-binding"): {
193 "eos_data": [
194 {
195 "vxlanIntfs": {
196 "Vxlan1": {
197 "vniBindings": {
198 "10020": {"vlan": 20, "dynamicVlan": False, "source": "static", "interfaces": {"Ethernet31": {"dot1q": 0}, "Vxlan1": {"dot1q": 20}}}
199 },
200 "vniBindingsToVrf": {"500": {"vrfName": "PROD", "vlan": 1199, "source": "evpn"}},
201 }
202 }
203 }
204 ],
205 "inputs": {"bindings": {10010: 10, 10020: 20, 500: 1199}},
206 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["Interface: Vxlan1 VNI: 10010 - Binding not found"]},
207 },
208 (VerifyVxlanVniBinding, "failure-vrf-wrong-binding"): {
209 "eos_data": [
210 {
211 "vxlanIntfs": {
212 "Vxlan1": {
213 "vniBindings": {
214 "10020": {"vlan": 20, "dynamicVlan": False, "source": "static", "interfaces": {"Ethernet31": {"dot1q": 0}, "Vxlan1": {"dot1q": 20}}}
215 },
216 "vniBindingsToVrf": {"500": {"vrfName": "PROD", "vlan": 1199, "source": "evpn"}, "600": {"vrfName": "TEST", "vlan": 1199, "source": "evpn"}},
217 }
218 }
219 }
220 ],
221 "inputs": {"bindings": {10020: 20, 500: 1199, 600: "PROD"}},
222 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["Interface: Vxlan1 VNI: 600 - Wrong VRF binding - Expected: PROD Actual: TEST"]},
223 },
224 (VerifyVxlanVniBinding, "failure-wrong-binding"): {
225 "eos_data": [
226 {
227 "vxlanIntfs": {
228 "Vxlan1": {
229 "vniBindings": {
230 "10020": {"vlan": 30, "dynamicVlan": False, "source": "static", "interfaces": {"Ethernet31": {"dot1q": 0}, "Vxlan1": {"dot1q": 20}}}
231 },
232 "vniBindingsToVrf": {"500": {"vrfName": "PROD", "vlan": 1199, "source": "evpn"}},
233 }
234 }
235 }
236 ],
237 "inputs": {"bindings": {10020: 20, 500: 1199}},
238 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["Interface: Vxlan1 VNI: 10020 - Wrong VLAN binding - Expected: 20 Actual: 30"]},
239 },
240 (VerifyVxlanVniBinding, "failure-no-and-wrong-binding"): {
241 "eos_data": [
242 {
243 "vxlanIntfs": {
244 "Vxlan1": {
245 "vniBindings": {
246 "10020": {"vlan": 30, "dynamicVlan": False, "source": "static", "interfaces": {"Ethernet31": {"dot1q": 0}, "Vxlan1": {"dot1q": 20}}}
247 },
248 "vniBindingsToVrf": {"500": {"vrfName": "PROD", "vlan": 1199, "source": "evpn"}},
249 }
250 }
251 }
252 ],
253 "inputs": {"bindings": {10010: 10, 10020: 20, 500: 1199}},
254 "expected": {
255 "result": AntaTestStatus.FAILURE,
256 "messages": ["Interface: Vxlan1 VNI: 10010 - Binding not found", "Interface: Vxlan1 VNI: 10020 - Wrong VLAN binding - Expected: 20 Actual: 30"],
257 },
258 },
259 (VerifyVxlanVniBinding, "failure-wrong-vni-vrf-binding"): {
260 "eos_data": [
261 {
262 "vxlanIntfs": {
263 "Vxlan1": {
264 "vniBindings": {
265 "10020": {"vlan": 30, "dynamicVlan": False, "source": "static", "interfaces": {"Ethernet31": {"dot1q": 0}, "Vxlan1": {"dot1q": 20}}}
266 },
267 "vniBindingsToVrf": {"500": {"vrfName": "PROD", "vlan": 1199, "source": "evpn"}},
268 }
269 }
270 }
271 ],
272 "inputs": {"bindings": {10020: "PROD", 500: 30}},
273 "expected": {
274 "result": AntaTestStatus.FAILURE,
275 "messages": ["Interface: Vxlan1 VNI: 10020 - Binding not found", "Interface: Vxlan1 VNI: 500 - Wrong VLAN binding - Expected: 30 Actual: 1199"],
276 },
277 },
278 (VerifyVxlanVniBinding, "skipped"): {
279 "eos_data": [{"vxlanIntfs": {}}],
280 "inputs": {"bindings": {10020: 20, 500: 1199}},
281 "expected": {"result": AntaTestStatus.SKIPPED, "messages": ["Interface: Vxlan1 - Not configured"]},
282 },
283 (VerifyVxlanVtep, "success"): {
284 "eos_data": [{"vteps": {}, "interfaces": {"Vxlan1": {"vteps": ["10.1.1.5", "10.1.1.6"]}}}],
285 "inputs": {"vteps": ["10.1.1.5", "10.1.1.6"]},
286 "expected": {"result": AntaTestStatus.SUCCESS},
287 },
288 (VerifyVxlanVtep, "failure-missing-vtep"): {
289 "eos_data": [{"vteps": {}, "interfaces": {"Vxlan1": {"vteps": ["10.1.1.5", "10.1.1.6"]}}}],
290 "inputs": {"vteps": ["10.1.1.5", "10.1.1.6", "10.1.1.7"]},
291 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["The following VTEP peer(s) are missing from the Vxlan1 interface: 10.1.1.7"]},
292 },
293 (VerifyVxlanVtep, "failure-no-vtep"): {
294 "eos_data": [{"vteps": {}, "interfaces": {"Vxlan1": {"vteps": []}}}],
295 "inputs": {"vteps": ["10.1.1.5", "10.1.1.6"]},
296 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["The following VTEP peer(s) are missing from the Vxlan1 interface: 10.1.1.5, 10.1.1.6"]},
297 },
298 (VerifyVxlanVtep, "failure-no-input-vtep"): {
299 "eos_data": [{"vteps": {}, "interfaces": {"Vxlan1": {"vteps": ["10.1.1.5"]}}}],
300 "inputs": {"vteps": []},
301 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["Unexpected VTEP peer(s) on Vxlan1 interface: 10.1.1.5"]},
302 },
303 (VerifyVxlanVtep, "failure-missmatch"): {
304 "eos_data": [{"vteps": {}, "interfaces": {"Vxlan1": {"vteps": ["10.1.1.6", "10.1.1.7", "10.1.1.8"]}}}],
305 "inputs": {"vteps": ["10.1.1.5", "10.1.1.6"]},
306 "expected": {
307 "result": AntaTestStatus.FAILURE,
308 "messages": [
309 "The following VTEP peer(s) are missing from the Vxlan1 interface: 10.1.1.5",
310 "Unexpected VTEP peer(s) on Vxlan1 interface: 10.1.1.7, 10.1.1.8",
311 ],
312 },
313 },
314 (VerifyVxlanVtep, "skipped"): {
315 "eos_data": [{"vteps": {}, "interfaces": {}}],
316 "inputs": {"vteps": ["10.1.1.5", "10.1.1.6", "10.1.1.7"]},
317 "expected": {"result": AntaTestStatus.SKIPPED, "messages": ["Interface: Vxlan1 - Not configured"]},
318 },
319 (VerifyVxlan1ConnSettings, "success"): {
320 "eos_data": [{"interfaces": {"Vxlan1": {"srcIpIntf": "Loopback1", "udpPort": 4789}}}],
321 "inputs": {"source_interface": "Loopback1", "udp_port": 4789},
322 "expected": {"result": AntaTestStatus.SUCCESS},
323 },
324 (VerifyVxlan1ConnSettings, "success-dps-src-intf"): {
325 "eos_data": [{"interfaces": {"Vxlan1": {"srcIpIntf": "Dps1", "udpPort": 4789}}}],
326 "inputs": {"source_interface": "Dps1", "udp_port": 4789},
327 "expected": {"result": AntaTestStatus.SUCCESS},
328 },
329 (VerifyVxlan1ConnSettings, "skipped"): {
330 "eos_data": [{"interfaces": {}}],
331 "inputs": {"source_interface": "Loopback1", "udp_port": 4789},
332 "expected": {"result": AntaTestStatus.SKIPPED, "messages": ["Interface: Vxlan1 - Not configured"]},
333 },
334 (VerifyVxlan1ConnSettings, "failure-wrong-interface"): {
335 "eos_data": [{"interfaces": {"Vxlan1": {"srcIpIntf": "Loopback10", "udpPort": 4789}}}],
336 "inputs": {"source_interface": "lo1", "udp_port": 4789},
337 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["Interface: Vxlan1 - Incorrect Source interface - Expected: Loopback1 Actual: Loopback10"]},
338 },
339 (VerifyVxlan1ConnSettings, "failure-wrong-port"): {
340 "eos_data": [{"interfaces": {"Vxlan1": {"srcIpIntf": "Loopback10", "udpPort": 4789}}}],
341 "inputs": {"source_interface": "Lo1", "udp_port": 4780},
342 "expected": {
343 "result": AntaTestStatus.FAILURE,
344 "messages": [
345 "Interface: Vxlan1 - Incorrect Source interface - Expected: Loopback1 Actual: Loopback10",
346 "Interface: Vxlan1 - Incorrect UDP port - Expected: 4780 Actual: 4789",
347 ],
348 },
349 },
350 (VerifyVxlan1ConnSettings, "failure-dps-src-intf"): {
351 "eos_data": [{"interfaces": {"Vxlan1": {"srcIpIntf": "Loopback10", "udpPort": 4789}}}],
352 "inputs": {"source_interface": "dps1", "udp_port": 4789},
353 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["Interface: Vxlan1 - Incorrect Source interface - Expected: Dps1 Actual: Loopback10"]},
354 },
355 (VerifyVxlan1VVTEPIPAddresses, "success-ipv4-only"): {
356 "eos_data": [{"interfaces": {"Vxlan1": {"vArpVtepAddr": "5.5.5.5"}}}],
357 "inputs": {"ipv4_address": "5.5.5.5"},
358 "expected": {"result": AntaTestStatus.SUCCESS},
359 },
360 (VerifyVxlan1VVTEPIPAddresses, "success-ipv6-only"): {
361 "eos_data": [{"interfaces": {"Vxlan1": {"vArpVtepAddrV6": "fd00:dc:1::1"}}}],
362 "inputs": {"ipv6_address": "fd00:dc:1::1"},
363 "expected": {"result": AntaTestStatus.SUCCESS},
364 },
365 (VerifyVxlan1VVTEPIPAddresses, "success-dual-stack"): {
366 "eos_data": [{"interfaces": {"Vxlan1": {"vArpVtepAddr": "5.5.5.5", "vArpVtepAddrV6": "fd00:dc:1::1"}}}],
367 "inputs": {"ipv4_address": "5.5.5.5", "ipv6_address": "fd00:dc:1::1"},
368 "expected": {"result": AntaTestStatus.SUCCESS},
369 },
370 (VerifyVxlan1VVTEPIPAddresses, "skipped"): {
371 "eos_data": [{"interfaces": {}}],
372 "inputs": {"ipv4_address": "5.5.5.5"},
373 "expected": {"result": AntaTestStatus.SKIPPED, "messages": ["Interface: Vxlan1 - Not configured"]},
374 },
375 (VerifyVxlan1VVTEPIPAddresses, "failure-incorrect-ipv4"): {
376 "eos_data": [{"interfaces": {"Vxlan1": {"vArpVtepAddr": "6.6.6.6"}}}],
377 "inputs": {"ipv4_address": "5.5.5.5"},
378 "expected": {
379 "result": AntaTestStatus.FAILURE,
380 "messages": ["Interface: Vxlan1 - Incorrect VVTEP IPv4 address - Expected: 5.5.5.5 Actual: 6.6.6.6"],
381 },
382 },
383 (VerifyVxlan1VVTEPIPAddresses, "failure-incorrect-ipv6"): {
384 "eos_data": [{"interfaces": {"Vxlan1": {"vArpVtepAddrV6": "fd00:dc:1::2"}}}],
385 "inputs": {"ipv6_address": "fd00:dc:1::1"},
386 "expected": {
387 "result": AntaTestStatus.FAILURE,
388 "messages": ["Interface: Vxlan1 - Incorrect VVTEP IPv6 address - Expected: fd00:dc:1::1 Actual: fd00:dc:1::2"],
389 },
390 },
391 (VerifyVxlan1VVTEPIPAddresses, "failure-not-configured-ipv4"): {
392 "eos_data": [{"interfaces": {"Vxlan1": {"srcIpIntf": "Loopback10", "udpPort": 4789}}}],
393 "inputs": {"ipv4_address": "5.5.5.5"},
394 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["Interface: Vxlan1 - VVTEP IPv4 address is not configured"]},
395 },
396 (VerifyVxlan1VVTEPIPAddresses, "failure-not-configured-ipv6"): {
397 "eos_data": [{"interfaces": {"Vxlan1": {"srcIpIntf": "Loopback10", "udpPort": 4789}}}],
398 "inputs": {"ipv6_address": "fd00:dc:1::1"},
399 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["Interface: Vxlan1 - VVTEP IPv6 address is not configured"]},
400 },
401 (VerifyVxlan1VVTEPIPAddresses, "failure-dual-stack-partial"): {
402 "eos_data": [{"interfaces": {"Vxlan1": {"vArpVtepAddr": "5.5.5.5", "vArpVtepAddrV6": "fd00:dc:1::2"}}}],
403 "inputs": {"ipv4_address": "5.5.5.5", "ipv6_address": "fd00:dc:1::1"},
404 "expected": {
405 "result": AntaTestStatus.FAILURE,
406 "messages": ["Interface: Vxlan1 - Incorrect VVTEP IPv6 address - Expected: fd00:dc:1::1 Actual: fd00:dc:1::2"],
407 },
408 },
409 }