Debian Codegraph @

tests/units/anta_tests/test_evpn.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.evpn.py."""
5
6 from __future__ import annotations
7
8 import sys
9 from typing import TYPE_CHECKING, Any
10
11 from anta.models import AntaTest
12 from anta.result_manager.models import AntaTestStatus
13 from anta.tests.evpn import VerifyEVPNType5Routes
14 from tests.units.anta_tests import test
15
16 if TYPE_CHECKING:
17 from tests.units.anta_tests import AntaUnitTestData
18
19 DATA: AntaUnitTestData = {
20 (VerifyEVPNType5Routes, "success-all"): {
21 "eos_data": [
22 {
23 "vrf": "default",
24 "routerId": "10.100.1.5",
25 "asn": 65102,
26 "evpnRoutes": {
27 "RD: 10.100.1.3:10 ip-prefix 10.100.0.128/31": {
28 "routeKeyDetail": {"ipGenPrefix": "10.100.0.128/31", "domain": "local", "rd": "10.100.1.3:10", "nlriType": "ip-prefix"},
29 "evpnRoutePaths": [{"nextHop": "10.100.2.3", "routeType": {"active": True, "valid": True}}],
30 }
31 },
32 },
33 {
34 "vrf": "default",
35 "routerId": "10.100.1.5",
36 "asn": 65102,
37 "evpnRoutes": {
38 "RD: 10.100.1.3:10 ip-prefix 10.100.0.128/31": {
39 "routeKeyDetail": {"ipGenPrefix": "10.100.0.128/31", "domain": "local", "rd": "10.100.1.3:10", "nlriType": "ip-prefix"},
40 "evpnRoutePaths": [{"nextHop": "10.100.2.3", "routeType": {"active": True, "valid": True}}],
41 }
42 },
43 },
44 {
45 "vrf": "default",
46 "routerId": "10.100.1.5",
47 "asn": 65102,
48 "evpnRoutes": {
49 "RD: 10.100.1.3:10 ip-prefix 10.100.4.0/31": {
50 "routeKeyDetail": {"ipGenPrefix": "10.100.4.0/31", "domain": "local", "rd": "10.100.1.3:10", "nlriType": "ip-prefix"},
51 "evpnRoutePaths": [
52 {
53 "nextHop": "10.100.2.3",
54 "routeType": {"active": True, "valid": True},
55 "routeDetail": {"extCommunities": ["Route-Target-AS:10:10", "TunnelEncap:tunnelTypeVxlan", "EvpnRouterMac:02:1c:73:71:73:45"]},
56 }
57 ],
58 }
59 },
60 },
61 {
62 "vrf": "default",
63 "routerId": "10.100.1.5",
64 "asn": 65102,
65 "evpnRoutes": {
66 "RD: 10.100.1.3:10 ip-prefix 10.100.4.0/31": {
67 "routeKeyDetail": {"ipGenPrefix": "10.100.4.0/31", "domain": "local", "rd": "10.100.1.3:10", "nlriType": "ip-prefix"},
68 "evpnRoutePaths": [
69 {
70 "nextHop": "10.100.2.3",
71 "routeType": {"active": True, "valid": True},
72 "routeDetail": {"extCommunities": ["Route-Target-AS:10:10", "TunnelEncap:tunnelTypeVxlan", "EvpnRouterMac:02:1c:73:71:73:45"]},
73 }
74 ],
75 }
76 },
77 },
78 ],
79 "inputs": {
80 "prefixes": [
81 {"address": "10.100.0.128/31", "vni": 10},
82 {"address": "10.100.0.128/31", "vni": 10, "routes": [{"rd": "10.100.1.3:10", "domain": "local"}]},
83 {"address": "10.100.4.0/31", "vni": 10, "routes": [{"rd": "10.100.1.3:10", "domain": "local", "paths": [{"nexthop": "10.100.2.3"}]}]},
84 {
85 "address": "10.100.4.1/31",
86 "vni": 10,
87 "routes": [{"rd": "10.100.1.3:10", "domain": "local", "paths": [{"nexthop": "10.100.2.3", "route_targets": ["10:10"]}]}],
88 },
89 ]
90 },
91 "expected": {"result": AntaTestStatus.SUCCESS},
92 },
93 (VerifyEVPNType5Routes, "success-ipv6"): {
94 "eos_data": [
95 {
96 "vrf": "default",
97 "routerId": "10.1.0.21",
98 "asn": 65120,
99 "evpnRoutes": {
100 "RD: 10.1.0.21:500 ip-prefix fd00:dc:5::1/128": {
101 "totalPaths": 1,
102 "routeKeyDetail": {"ipGenPrefix": "fd00:dc:5::1/128", "domain": "local", "rd": "10.1.0.21:500", "nlriType": "ip-prefix"},
103 "evpnRoutePaths": [
104 {
105 "nextHop": "",
106 "asPathEntry": {"asPathType": "Local", "asPath": "i"},
107 "reasonNotBestpath": "noReason",
108 "routeType": {"active": True, "valid": True},
109 }
110 ],
111 },
112 "RD: 10.1.0.21:500 ip-prefix fd00:dc:5::1/128 remote": {
113 "totalPaths": 1,
114 "routeKeyDetail": {"ipGenPrefix": "fd00:dc:5::1/128", "domain": "remote", "rd": "10.1.0.21:500", "nlriType": "ip-prefix"},
115 "evpnRoutePaths": [
116 {
117 "nextHop": "",
118 "asPathEntry": {"asPathType": "Local", "asPath": "i"},
119 "reasonNotBestpath": "noReason",
120 "routeType": {"active": True, "valid": True},
121 }
122 ],
123 },
124 },
125 }
126 ],
127 "inputs": {"prefixes": [{"address": "fd00:dc:5::1/128", "vni": 500}]},
128 "expected": {"result": AntaTestStatus.SUCCESS},
129 },
130 (VerifyEVPNType5Routes, "success-across-all-rds"): {
131 "eos_data": [
132 {
133 "vrf": "default",
134 "routerId": "10.100.1.5",
135 "asn": 65102,
136 "evpnRoutes": {
137 "RD: 10.100.1.3:10 ip-prefix 10.100.0.128/31": {
138 "routeKeyDetail": {"ipGenPrefix": "10.100.0.128/31", "domain": "local", "rd": "10.100.1.3:10", "nlriType": "ip-prefix"},
139 "evpnRoutePaths": [{"nextHop": "10.100.2.3", "routeType": {"active": True, "valid": True}}],
140 },
141 "RD: 10.100.1.4:10 ip-prefix 10.100.0.128/31": {
142 "routeKeyDetail": {"ipGenPrefix": "10.100.0.128/31", "domain": "local", "rd": "10.100.1.4:10", "nlriType": "ip-prefix"},
143 "evpnRoutePaths": [{"nextHop": "10.100.2.3", "routeType": {"active": False, "valid": False}}],
144 },
145 },
146 }
147 ],
148 "inputs": {"prefixes": [{"address": "10.100.0.128/31", "vni": 10}]},
149 "expected": {"result": AntaTestStatus.SUCCESS},
150 },
151 (VerifyEVPNType5Routes, "success-specific-rd"): {
152 "eos_data": [
153 {
154 "vrf": "default",
155 "routerId": "10.100.1.5",
156 "asn": 65102,
157 "evpnRoutes": {
158 "RD: 10.100.1.3:10 ip-prefix 10.100.0.128/31": {
159 "routeKeyDetail": {"ipGenPrefix": "10.100.0.128/31", "domain": "local", "rd": "10.100.1.3:10", "nlriType": "ip-prefix"},
160 "evpnRoutePaths": [
161 {"nextHop": "10.100.2.3", "routeType": {"active": False, "valid": False}},
162 {"nextHop": "10.100.2.4", "routeType": {"active": True, "valid": True}},
163 ],
164 }
165 },
166 }
167 ],
168 "inputs": {"prefixes": [{"address": "10.100.0.128/31", "vni": 10, "routes": [{"rd": "10.100.1.3:10", "domain": "local"}]}]},
169 "expected": {"result": AntaTestStatus.SUCCESS},
170 },
171 (VerifyEVPNType5Routes, "success-specific-nexthop"): {
172 "eos_data": [
173 {
174 "vrf": "default",
175 "routerId": "10.100.1.5",
176 "asn": 65102,
177 "evpnRoutes": {
178 "RD: 10.100.1.3:10 ip-prefix 10.100.4.0/31": {
179 "routeKeyDetail": {"ipGenPrefix": "10.100.4.0/31", "domain": "local", "rd": "10.100.1.3:10", "nlriType": "ip-prefix"},
180 "evpnRoutePaths": [
181 {
182 "nextHop": "10.100.2.3",
183 "routeType": {"active": True, "valid": True},
184 "routeDetail": {"extCommunities": ["Route-Target-AS:10:10", "TunnelEncap:tunnelTypeVxlan", "EvpnRouterMac:02:1c:73:71:73:45"]},
185 },
186 {
187 "nextHop": "10.100.2.3",
188 "routeType": {"active": False, "valid": False},
189 "routeDetail": {"extCommunities": ["Route-Target-AS:10:10", "TunnelEncap:tunnelTypeVxlan", "EvpnRouterMac:02:1c:73:71:73:45"]},
190 },
191 ],
192 }
193 },
194 }
195 ],
196 "inputs": {
197 "prefixes": [{"address": "10.100.4.0/31", "vni": 10, "routes": [{"rd": "10.100.1.3:10", "domain": "local", "paths": [{"nexthop": "10.100.2.3"}]}]}]
198 },
199 "expected": {"result": AntaTestStatus.SUCCESS},
200 },
201 (VerifyEVPNType5Routes, "success-RTs"): {
202 "eos_data": [
203 {
204 "vrf": "default",
205 "routerId": "10.100.1.5",
206 "asn": 65102,
207 "evpnRoutes": {
208 "RD: 10.100.1.3:10 ip-prefix 10.100.4.0/31": {
209 "routeKeyDetail": {"ipGenPrefix": "10.100.4.0/31", "domain": "local", "rd": "10.100.1.3:10", "nlriType": "ip-prefix"},
210 "evpnRoutePaths": [
211 {
212 "nextHop": "10.100.2.3",
213 "routeType": {"active": True, "valid": True},
214 "routeDetail": {"extCommunities": ["Route-Target-AS:10:10", "TunnelEncap:tunnelTypeVxlan", "EvpnRouterMac:02:1c:73:71:73:45"]},
215 }
216 ],
217 }
218 },
219 }
220 ],
221 "inputs": {
222 "prefixes": [
223 {
224 "address": "10.100.4.1/31",
225 "vni": 10,
226 "routes": [{"rd": "10.100.1.3:10", "domain": "local", "paths": [{"nexthop": "10.100.2.3", "route_targets": ["10:10"]}]}],
227 }
228 ]
229 },
230 "expected": {"result": AntaTestStatus.SUCCESS},
231 },
232 (VerifyEVPNType5Routes, "failure-all"): {
233 "eos_data": [
234 {
235 "vrf": "default",
236 "routerId": "10.100.1.5",
237 "asn": 65102,
238 "evpnRoutes": {
239 "RD: 10.100.1.3:10 ip-prefix 10.100.0.128/31": {
240 "routeKeyDetail": {"ipGenPrefix": "10.100.0.128/31", "domain": "local", "rd": "10.100.1.3:10", "nlriType": "ip-prefix"},
241 "evpnRoutePaths": [{"nextHop": "10.100.2.3", "routeType": {"active": False, "valid": True}}],
242 }
243 },
244 },
245 {
246 "vrf": "default",
247 "routerId": "10.100.1.5",
248 "asn": 65102,
249 "evpnRoutes": {
250 "RD: 10.100.1.3:10 ip-prefix 10.100.0.128/31": {
251 "routeKeyDetail": {"ipGenPrefix": "10.100.0.128/31", "domain": "local", "rd": "10.100.1.3:10", "nlriType": "ip-prefix"},
252 "evpnRoutePaths": [{"nextHop": "10.100.2.3", "routeType": {"active": False, "valid": True}}],
253 }
254 },
255 },
256 {
257 "vrf": "default",
258 "routerId": "10.100.1.5",
259 "asn": 65102,
260 "evpnRoutes": {
261 "RD: 10.100.1.3:10 ip-prefix 10.100.4.0/31": {
262 "routeKeyDetail": {"ipGenPrefix": "10.100.4.0/31", "domain": "local", "rd": "10.100.1.3:10", "nlriType": "ip-prefix"},
263 "evpnRoutePaths": [
264 {
265 "nextHop": "10.100.2.3",
266 "routeType": {"active": True, "valid": False},
267 "routeDetail": {"extCommunities": ["Route-Target-AS:10:10", "TunnelEncap:tunnelTypeVxlan", "EvpnRouterMac:02:1c:73:71:73:45"]},
268 }
269 ],
270 }
271 },
272 },
273 {
274 "vrf": "default",
275 "routerId": "10.100.1.5",
276 "asn": 65102,
277 "evpnRoutes": {
278 "RD: 10.100.1.3:10 ip-prefix 10.100.4.0/31": {
279 "routeKeyDetail": {"ipGenPrefix": "10.100.4.0/31", "domain": "local", "rd": "10.100.1.3:10", "nlriType": "ip-prefix"},
280 "evpnRoutePaths": [
281 {
282 "nextHop": "10.100.2.3",
283 "routeType": {"active": False, "valid": True},
284 "routeDetail": {"extCommunities": ["Route-Target-AS:10:10", "TunnelEncap:tunnelTypeVxlan", "EvpnRouterMac:02:1c:73:71:73:45"]},
285 }
286 ],
287 }
288 },
289 },
290 ],
291 "inputs": {
292 "prefixes": [
293 {"address": "10.100.0.128/31", "vni": 10},
294 {"address": "10.100.0.128/31", "vni": 10, "routes": [{"rd": "10.100.1.3:10", "domain": "local"}]},
295 {"address": "10.100.4.0/31", "vni": 10, "routes": [{"rd": "10.100.1.3:10", "domain": "local", "paths": [{"nexthop": "10.100.2.3"}]}]},
296 {
297 "address": "10.100.4.1/31",
298 "vni": 10,
299 "routes": [{"rd": "10.100.1.3:10", "domain": "local", "paths": [{"nexthop": "10.100.2.3", "route_targets": ["10:10"]}]}],
300 },
301 ]
302 },
303 "expected": {
304 "result": AntaTestStatus.FAILURE,
305 "messages": [
306 "Prefix: 10.100.0.128/31 VNI: 10 - No active and valid path found across all RDs",
307 "Prefix: 10.100.0.128/31 VNI: 10 RD: 10.100.1.3:10 - No active and valid path found",
308 "Prefix: 10.100.4.0/31 VNI: 10 RD: 10.100.1.3:10 Nexthop: 10.100.2.3 - No active and valid path found",
309 "Prefix: 10.100.4.1/31 VNI: 10 RD: 10.100.1.3:10 Nexthop: 10.100.2.3 RTs: 10:10 - No active and valid path found",
310 ],
311 },
312 },
313 (VerifyEVPNType5Routes, "failure-not-configured"): {
314 "eos_data": [
315 {"vrf": "default", "routerId": "10.100.1.5", "asn": 65102, "evpnRoutes": {}},
316 {"vrf": "default", "routerId": "10.100.1.5", "asn": 65102, "evpnRoutes": {}},
317 ],
318 "inputs": {
319 "prefixes": [
320 {"address": "10.100.0.128/31", "vni": 10},
321 {
322 "address": "10.100.4.1/31",
323 "vni": 10,
324 "routes": [{"rd": "10.100.1.3:10", "domain": "local", "paths": [{"nexthop": "10.100.2.3", "route_targets": ["10:10"]}]}],
325 },
326 ]
327 },
328 "expected": {
329 "result": AntaTestStatus.FAILURE,
330 "messages": ["Prefix: 10.100.0.128/31 VNI: 10 - No EVPN Type-5 routes found", "Prefix: 10.100.4.1/31 VNI: 10 - No EVPN Type-5 routes found"],
331 },
332 },
333 (VerifyEVPNType5Routes, "failure-route-not-found-with-specified-rd-domain"): {
334 "eos_data": [
335 {
336 "vrf": "default",
337 "routerId": "10.100.1.5",
338 "asn": 65102,
339 "evpnRoutes": {
340 "RD: 10.100.1.3:10 ip-prefix 10.100.0.128/31": {
341 "routeKeyDetail": {"ipGenPrefix": "10.100.0.128/31", "domain": "remote", "rd": "10.100.1.4:10", "nlriType": "ip-prefix"},
342 "evpnRoutePaths": [
343 {"nextHop": "10.100.2.3", "routeType": {"active": False, "valid": False}},
344 {"nextHop": "10.100.2.4", "routeType": {"active": True, "valid": True}},
345 ],
346 }
347 },
348 }
349 ],
350 "inputs": {"prefixes": [{"address": "10.100.0.128/31", "vni": 10, "routes": [{"rd": "10.100.1.3:10", "domain": "remote"}]}]},
351 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["Prefix: 10.100.0.128/31 VNI: 10 RD: 10.100.1.3:10 Domain: remote - Route not found"]},
352 },
353 (VerifyEVPNType5Routes, "failiure-specific-nexthop-path-not-found"): {
354 "eos_data": [
355 {
356 "vrf": "default",
357 "routerId": "10.100.1.5",
358 "asn": 65102,
359 "evpnRoutes": {
360 "RD: 10.100.1.3:10 ip-prefix 10.100.4.0/31": {
361 "routeKeyDetail": {"ipGenPrefix": "10.100.4.0/31", "domain": "local", "rd": "10.100.1.3:10", "nlriType": "ip-prefix"},
362 "evpnRoutePaths": [
363 {
364 "nextHop": "10.100.2.4",
365 "routeType": {"active": True, "valid": True},
366 "routeDetail": {"extCommunities": ["Route-Target-AS:10:10", "TunnelEncap:tunnelTypeVxlan", "EvpnRouterMac:02:1c:73:71:73:45"]},
367 }
368 ],
369 }
370 },
371 }
372 ],
373 "inputs": {
374 "prefixes": [{"address": "10.100.4.0/31", "vni": 10, "routes": [{"rd": "10.100.1.3:10", "domain": "local", "paths": [{"nexthop": "10.100.2.3"}]}]}]
375 },
376 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["Prefix: 10.100.4.0/31 VNI: 10 RD: 10.100.1.3:10 Nexthop: 10.100.2.3 - Path not found"]},
377 },
378 (VerifyEVPNType5Routes, "failiure-specific-nexthop-RTs-path-not-found"): {
379 "eos_data": [
380 {
381 "vrf": "default",
382 "routerId": "10.100.1.5",
383 "asn": 65102,
384 "evpnRoutes": {
385 "RD: 10.100.1.3:10 ip-prefix 10.100.4.0/31": {
386 "routeKeyDetail": {"ipGenPrefix": "10.100.4.0/31", "domain": "local", "rd": "10.100.1.3:10", "nlriType": "ip-prefix"},
387 "evpnRoutePaths": [
388 {
389 "nextHop": "10.100.2.3",
390 "routeType": {"active": True, "valid": True},
391 "routeDetail": {"extCommunities": ["Route-Target-AS:20:20", "TunnelEncap:tunnelTypeVxlan", "EvpnRouterMac:02:1c:73:71:73:45"]},
392 }
393 ],
394 }
395 },
396 }
397 ],
398 "inputs": {
399 "prefixes": [
400 {
401 "address": "10.100.4.1/31",
402 "vni": 10,
403 "routes": [{"rd": "10.100.1.3:10", "domain": "local", "paths": [{"nexthop": "10.100.2.3", "route_targets": ["10:10"]}]}],
404 }
405 ]
406 },
407 "expected": {
408 "result": AntaTestStatus.FAILURE,
409 "messages": ["Prefix: 10.100.4.1/31 VNI: 10 RD: 10.100.1.3:10 Nexthop: 10.100.2.3 RTs: 10:10 - Path not found"],
410 },
411 },
412 (VerifyEVPNType5Routes, "failure-ipv6"): {
413 "eos_data": [
414 {
415 "vrf": "default",
416 "routerId": "10.1.0.21",
417 "asn": 65120,
418 "evpnRoutes": {
419 "RD: 10.1.0.21:500 ip-prefix fd00:dc:5::1/128": {
420 "totalPaths": 1,
421 "routeKeyDetail": {"ipGenPrefix": "fd00:dc:5::1/128", "domain": "local", "rd": "10.1.0.21:500", "nlriType": "ip-prefix"},
422 "evpnRoutePaths": [
423 {
424 "nextHop": "",
425 "asPathEntry": {"asPathType": "Local", "asPath": "i"},
426 "reasonNotBestpath": "noReason",
427 "routeType": {"active": True, "valid": False},
428 }
429 ],
430 },
431 "RD: 10.1.0.21:500 ip-prefix fd00:dc:5::1/128 remote": {
432 "totalPaths": 1,
433 "routeKeyDetail": {"ipGenPrefix": "fd00:dc:5::1/128", "domain": "remote", "rd": "10.1.0.21:500", "nlriType": "ip-prefix"},
434 "evpnRoutePaths": [
435 {
436 "nextHop": "",
437 "asPathEntry": {"asPathType": "Local", "asPath": "i"},
438 "reasonNotBestpath": "noReason",
439 "routeType": {"active": False, "valid": True},
440 }
441 ],
442 },
443 },
444 }
445 ],
446 "inputs": {"prefixes": [{"address": "fd00:dc:5::1/128", "vni": 500}]},
447 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["Prefix: fd00:dc:5::1/128 VNI: 500 - No active and valid path found across all RDs"]},
448 },
449 }