Debian Codegraph @

tests/units/anta_tests/routing/test_ospf.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.routing.ospf.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.routing.ospf import VerifyOSPFMaxLSA, VerifyOSPFNeighborCount, VerifyOSPFNeighborState, VerifyOSPFSpecificNeighbors
13 from tests.units.anta_tests import AntaUnitTest, test
14
15 AntaUnitTestData: TypeAlias = dict[tuple[type[AntaTest], str], AntaUnitTest]
16
17 DATA: AntaUnitTestData = {
18 (VerifyOSPFNeighborState, "success"): {
19 "eos_data": [
20 {
21 "vrfs": {
22 "default": {
23 "instList": {
24 "666": {
25 "ospfNeighborEntries": [
26 {
27 "routerId": "7.7.7.7",
28 "priority": 1,
29 "drState": "DR",
30 "interfaceName": "Ethernet1",
31 "adjacencyState": "full",
32 "inactivity": 1683298014.844345,
33 "interfaceAddress": "10.3.0.1",
34 },
35 {
36 "routerId": "9.9.9.9",
37 "priority": 1,
38 "drState": "DR",
39 "interfaceName": "Ethernet1",
40 "adjacencyState": "full",
41 "inactivity": 1683298014.844345,
42 "interfaceAddress": "10.3.0.1",
43 },
44 ]
45 }
46 }
47 },
48 "BLAH": {
49 "instList": {
50 "777": {
51 "ospfNeighborEntries": [
52 {
53 "routerId": "8.8.8.8",
54 "priority": 1,
55 "drState": "DR",
56 "interfaceName": "Ethernet1",
57 "adjacencyState": "full",
58 "inactivity": 1683298014.844345,
59 "interfaceAddress": "10.3.0.1",
60 }
61 ]
62 }
63 }
64 },
65 }
66 }
67 ],
68 "expected": {"result": AntaTestStatus.SUCCESS},
69 },
70 (VerifyOSPFNeighborState, "failure"): {
71 "eos_data": [
72 {
73 "vrfs": {
74 "default": {
75 "instList": {
76 "666": {
77 "ospfNeighborEntries": [
78 {
79 "routerId": "7.7.7.7",
80 "priority": 1,
81 "drState": "DR",
82 "interfaceName": "Ethernet1",
83 "adjacencyState": "2-way",
84 "inactivity": 1683298014.844345,
85 "interfaceAddress": "10.3.0.1",
86 },
87 {
88 "routerId": "9.9.9.9",
89 "priority": 1,
90 "drState": "DR",
91 "interfaceName": "Ethernet1",
92 "adjacencyState": "full",
93 "inactivity": 1683298014.844345,
94 "interfaceAddress": "10.3.0.1",
95 },
96 ]
97 }
98 }
99 },
100 "BLAH": {
101 "instList": {
102 "777": {
103 "ospfNeighborEntries": [
104 {
105 "routerId": "8.8.8.8",
106 "priority": 1,
107 "drState": "DR",
108 "interfaceName": "Ethernet1",
109 "adjacencyState": "down",
110 "inactivity": 1683298014.844345,
111 "interfaceAddress": "10.3.0.1",
112 }
113 ]
114 }
115 }
116 },
117 }
118 }
119 ],
120 "expected": {
121 "result": AntaTestStatus.FAILURE,
122 "messages": [
123 "Instance: 666 VRF: default Neighbor ID: 7.7.7.7 - Incorrect adjacency state - Expected: Full Actual: 2-way",
124 "Instance: 777 VRF: BLAH Neighbor ID: 8.8.8.8 - Incorrect adjacency state - Expected: Full Actual: down",
125 ],
126 },
127 },
128 (VerifyOSPFNeighborState, "skipped-ospf-not-configured"): {
129 "eos_data": [{"vrfs": {}}],
130 "expected": {"result": AntaTestStatus.SKIPPED, "messages": ["OSPF not configured"]},
131 },
132 (VerifyOSPFNeighborState, "skipped-neighbor-not-found"): {
133 "eos_data": [{"vrfs": {"default": {"instList": {"666": {"ospfNeighborEntries": []}}}, "BLAH": {"instList": {"777": {"ospfNeighborEntries": []}}}}}],
134 "expected": {"result": AntaTestStatus.SKIPPED, "messages": ["No OSPF neighbor detected"]},
135 },
136 (VerifyOSPFNeighborCount, "success"): {
137 "eos_data": [
138 {
139 "vrfs": {
140 "default": {
141 "instList": {
142 "666": {
143 "ospfNeighborEntries": [
144 {
145 "routerId": "7.7.7.7",
146 "priority": 1,
147 "drState": "DR",
148 "interfaceName": "Ethernet1",
149 "adjacencyState": "full",
150 "inactivity": 1683298014.844345,
151 "interfaceAddress": "10.3.0.1",
152 },
153 {
154 "routerId": "9.9.9.9",
155 "priority": 1,
156 "drState": "DR",
157 "interfaceName": "Ethernet1",
158 "adjacencyState": "full",
159 "inactivity": 1683298014.844345,
160 "interfaceAddress": "10.3.0.1",
161 },
162 ]
163 }
164 }
165 },
166 "BLAH": {
167 "instList": {
168 "777": {
169 "ospfNeighborEntries": [
170 {
171 "routerId": "8.8.8.8",
172 "priority": 1,
173 "drState": "DR",
174 "interfaceName": "Ethernet1",
175 "adjacencyState": "full",
176 "inactivity": 1683298014.844345,
177 "interfaceAddress": "10.3.0.1",
178 }
179 ]
180 }
181 }
182 },
183 }
184 }
185 ],
186 "inputs": {"number": 3},
187 "expected": {"result": AntaTestStatus.SUCCESS},
188 },
189 (VerifyOSPFNeighborCount, "failure-good-number-wrong-state"): {
190 "eos_data": [
191 {
192 "vrfs": {
193 "default": {
194 "instList": {
195 "666": {
196 "ospfNeighborEntries": [
197 {
198 "routerId": "7.7.7.7",
199 "priority": 1,
200 "drState": "DR",
201 "interfaceName": "Ethernet1",
202 "adjacencyState": "2-way",
203 "inactivity": 1683298014.844345,
204 "interfaceAddress": "10.3.0.1",
205 },
206 {
207 "routerId": "9.9.9.9",
208 "priority": 1,
209 "drState": "DR",
210 "interfaceName": "Ethernet1",
211 "adjacencyState": "full",
212 "inactivity": 1683298014.844345,
213 "interfaceAddress": "10.3.0.1",
214 },
215 ]
216 }
217 }
218 },
219 "BLAH": {
220 "instList": {
221 "777": {
222 "ospfNeighborEntries": [
223 {
224 "routerId": "8.8.8.8",
225 "priority": 1,
226 "drState": "DR",
227 "interfaceName": "Ethernet1",
228 "adjacencyState": "down",
229 "inactivity": 1683298014.844345,
230 "interfaceAddress": "10.3.0.1",
231 }
232 ]
233 }
234 }
235 },
236 }
237 }
238 ],
239 "inputs": {"number": 3},
240 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["Neighbor count mismatch - Expected: 3 Actual: 1"]},
241 },
242 (VerifyOSPFNeighborCount, "skipped-ospf-not-configured"): {
243 "eos_data": [{"vrfs": {}}],
244 "inputs": {"number": 3},
245 "expected": {"result": AntaTestStatus.SKIPPED, "messages": ["OSPF not configured"]},
246 },
247 (VerifyOSPFNeighborCount, "skipped-no-neighbor-detected"): {
248 "eos_data": [{"vrfs": {"default": {"instList": {"666": {"ospfNeighborEntries": []}}}, "BLAH": {"instList": {"777": {"ospfNeighborEntries": []}}}}}],
249 "inputs": {"number": 3},
250 "expected": {"result": AntaTestStatus.SKIPPED, "messages": ["No OSPF neighbor detected"]},
251 },
252 (VerifyOSPFMaxLSA, "success"): {
253 "eos_data": [
254 {
255 "vrfs": {
256 "default": {
257 "instList": {
258 "1": {
259 "instanceId": 1,
260 "maxLsaInformation": {"maxLsa": 12000, "maxLsaThreshold": 75},
261 "routerId": "1.1.1.1",
262 "lsaInformation": {
263 "lsaArrivalInterval": 1000,
264 "lsaStartInterval": 1000,
265 "lsaHoldInterval": 5000,
266 "lsaMaxWaitInterval": 5000,
267 "numLsa": 9,
268 },
269 }
270 }
271 },
272 "TEST": {
273 "instList": {
274 "10": {
275 "instanceId": 10,
276 "maxLsaInformation": {"maxLsa": 1000, "maxLsaThreshold": 75},
277 "routerId": "20.20.20.20",
278 "lsaInformation": {
279 "lsaArrivalInterval": 1000,
280 "lsaStartInterval": 1000,
281 "lsaHoldInterval": 5000,
282 "lsaMaxWaitInterval": 5000,
283 "numLsa": 5,
284 },
285 }
286 }
287 },
288 }
289 }
290 ],
291 "expected": {"result": AntaTestStatus.SUCCESS},
292 },
293 (VerifyOSPFMaxLSA, "failure"): {
294 "eos_data": [
295 {
296 "vrfs": {
297 "default": {
298 "instList": {
299 "1": {
300 "instanceId": 1,
301 "maxLsaInformation": {"maxLsa": 12000, "maxLsaThreshold": 75},
302 "routerId": "1.1.1.1",
303 "lsaInformation": {
304 "lsaArrivalInterval": 1000,
305 "lsaStartInterval": 1000,
306 "lsaHoldInterval": 5000,
307 "lsaMaxWaitInterval": 5000,
308 "numLsa": 11500,
309 },
310 }
311 }
312 },
313 "TEST": {
314 "instList": {
315 "10": {
316 "instanceId": 10,
317 "maxLsaInformation": {"maxLsa": 1000, "maxLsaThreshold": 75},
318 "routerId": "20.20.20.20",
319 "lsaInformation": {
320 "lsaArrivalInterval": 1000,
321 "lsaStartInterval": 1000,
322 "lsaHoldInterval": 5000,
323 "lsaMaxWaitInterval": 5000,
324 "numLsa": 1500,
325 },
326 }
327 }
328 },
329 }
330 }
331 ],
332 "expected": {
333 "result": AntaTestStatus.FAILURE,
334 "messages": [
335 "Instance: 1 - Crossed the maximum LSA threshold - Expected: < 9000 Actual: 11500",
336 "Instance: 10 - Crossed the maximum LSA threshold - Expected: < 750 Actual: 1500",
337 ],
338 },
339 },
340 (VerifyOSPFMaxLSA, "skipped"): {"eos_data": [{"vrfs": {}}], "expected": {"result": AntaTestStatus.SKIPPED, "messages": ["OSPF not configured"]}},
341 (VerifyOSPFSpecificNeighbors, "success"): {
342 "eos_data": [
343 {
344 "vrfs": {
345 "default": {
346 "instList": {
347 "100": {
348 "ospfNeighborEntries": [
349 {
350 "routerId": "10.1.0.14",
351 "interfaceAddress": "10.1.255.53",
352 "interfaceName": "Ethernet4",
353 "adjacencyState": "full",
354 "details": {
355 "areaId": "0.0.0.0", # noqa: S104
356 },
357 },
358 {
359 "routerId": "10.1.0.13",
360 "interfaceAddress": "10.1.255.49",
361 "interfaceName": "Ethernet3",
362 "adjacencyState": "full",
363 "details": {
364 "areaId": "0.0.0.0", # noqa: S104
365 },
366 },
367 ]
368 }
369 }
370 },
371 "PROD": {
372 "instList": {
373 "200": {
374 "ospfNeighborEntries": [
375 {
376 "routerId": "10.1.0.14",
377 "interfaceAddress": "10.1.255.53",
378 "interfaceName": "Ethernet4",
379 "adjacencyState": "full",
380 "details": {
381 "areaId": "0.0.0.1",
382 },
383 },
384 {
385 "routerId": "10.1.0.13",
386 "interfaceAddress": "10.1.255.49",
387 "interfaceName": "Ethernet3",
388 "adjacencyState": "full",
389 "details": {
390 "areaId": "0.0.0.2",
391 },
392 },
393 ]
394 }
395 }
396 },
397 },
398 }
399 ],
400 "inputs": {
401 "neighbors": [
402 {"instance": 100, "vrf": "default", "ip_address": "10.1.255.53", "local_interface": "Ethernet4", "area_id": 0},
403 {
404 "instance": 100,
405 "vrf": "default",
406 "ip_address": "10.1.255.49",
407 "local_interface": "Ethernet3",
408 "area_id": "0.0.0.0", # noqa: S104
409 },
410 {"instance": 200, "vrf": "PROD", "ip_address": "10.1.255.53", "local_interface": "Ethernet4", "area_id": 1},
411 {"instance": 200, "vrf": "PROD", "ip_address": "10.1.255.49", "local_interface": "Ethernet3", "area_id": "0.0.0.2"},
412 ]
413 },
414 "expected": {"result": AntaTestStatus.SUCCESS},
415 },
416 (VerifyOSPFSpecificNeighbors, "success-2-ways"): {
417 "eos_data": [
418 {
419 "vrfs": {
420 "default": {
421 "instList": {
422 "100": {
423 "ospfNeighborEntries": [
424 {
425 "routerId": "10.1.0.14",
426 "interfaceAddress": "10.1.255.53",
427 "interfaceName": "Vlan911",
428 "adjacencyState": "2Ways",
429 "details": {
430 "areaId": "0.0.0.0", # noqa: S104
431 },
432 },
433 {
434 "routerId": "10.1.0.13",
435 "interfaceAddress": "10.1.255.49",
436 "interfaceName": "Ethernet3",
437 "adjacencyState": "full",
438 "details": {
439 "areaId": "0.0.0.0", # noqa: S104
440 },
441 },
442 ]
443 }
444 }
445 }
446 },
447 }
448 ],
449 "inputs": {
450 "neighbors": [
451 {"instance": 100, "vrf": "default", "ip_address": "10.1.255.53", "local_interface": "Vlan911", "area_id": 0, "state": "2Ways"},
452 {
453 "instance": 100,
454 "vrf": "default",
455 "ip_address": "10.1.255.49",
456 "local_interface": "Ethernet3",
457 "area_id": "0.0.0.0", # noqa: S104
458 },
459 ]
460 },
461 "expected": {"result": AntaTestStatus.SUCCESS},
462 },
463 (VerifyOSPFSpecificNeighbors, "failure-ospf-not-configured"): {
464 "eos_data": [
465 {
466 "vrfs": {},
467 }
468 ],
469 "inputs": {
470 "neighbors": [
471 {"instance": 100, "vrf": "default", "ip_address": "10.1.255.53", "local_interface": "Ethernet4", "area_id": 0},
472 ]
473 },
474 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["OSPF not configured"]},
475 },
476 (VerifyOSPFSpecificNeighbors, "neighbor-not-found"): {
477 "eos_data": [
478 {
479 "vrfs": {
480 "default": {
481 "instList": {
482 "100": {
483 "ospfNeighborEntries": [
484 {
485 "routerId": "10.1.0.14",
486 "interfaceAddress": "10.1.255.53",
487 "interfaceName": "Ethernet4",
488 "adjacencyState": "full",
489 "details": {
490 "areaId": "0.0.0.0", # noqa: S104
491 },
492 },
493 {
494 "routerId": "10.1.0.13",
495 "interfaceAddress": "10.1.255.49",
496 "interfaceName": "Ethernet3",
497 "adjacencyState": "full",
498 "details": {
499 "areaId": "0.0.0.0", # noqa: S104
500 },
501 },
502 ]
503 }
504 }
505 }
506 },
507 }
508 ],
509 "inputs": {
510 "neighbors": [
511 {"instance": 200, "vrf": "PROD", "ip_address": "10.1.255.53", "local_interface": "Ethernet4", "area_id": 1},
512 {"instance": 200, "vrf": "PROD", "ip_address": "10.1.255.49", "local_interface": "Ethernet3", "area_id": "0.0.0.2"},
513 ]
514 },
515 "expected": {
516 "result": AntaTestStatus.FAILURE,
517 "messages": [
518 "Instance: 200 VRF: PROD Neighbor IP: 10.1.255.53 Area: 0.0.0.1 - Neighbor not found",
519 "Instance: 200 VRF: PROD Neighbor IP: 10.1.255.49 Area: 0.0.0.2 - Neighbor not found",
520 ],
521 },
522 },
523 (VerifyOSPFSpecificNeighbors, "area-id-mismatch"): {
524 "eos_data": [
525 {
526 "vrfs": {
527 "default": {
528 "instList": {
529 "100": {
530 "ospfNeighborEntries": [
531 {
532 "routerId": "10.1.0.14",
533 "interfaceAddress": "10.1.255.53",
534 "interfaceName": "Ethernet4",
535 "adjacencyState": "full",
536 "details": {
537 "areaId": "0.0.217.3",
538 },
539 },
540 {
541 "routerId": "10.1.0.13",
542 "interfaceAddress": "10.1.255.49",
543 "interfaceName": "Ethernet3",
544 "adjacencyState": "full",
545 "details": {
546 "areaId": "0.0.217.3",
547 },
548 },
549 ]
550 }
551 }
552 },
553 },
554 }
555 ],
556 "inputs": {
557 "neighbors": [
558 {"instance": 100, "vrf": "default", "ip_address": "10.1.255.53", "local_interface": "Ethernet4", "area_id": 0},
559 {
560 "instance": 100,
561 "vrf": "default",
562 "ip_address": "10.1.255.49",
563 "local_interface": "Ethernet3",
564 "area_id": "0.0.0.0", # noqa: S104
565 },
566 ]
567 },
568 "expected": {
569 "result": AntaTestStatus.FAILURE,
570 "messages": [
571 "Instance: 100 VRF: default Neighbor IP: 10.1.255.53 Area: 0.0.0.0 - Area-ID mismatch - Expected: 0.0.0.0 Actual: 0.0.217.3",
572 "Instance: 100 VRF: default Neighbor IP: 10.1.255.49 Area: 0.0.0.0 - Area-ID mismatch - Expected: 0.0.0.0 Actual: 0.0.217.3",
573 ],
574 },
575 },
576 (VerifyOSPFSpecificNeighbors, "adjacency-state-mismatch"): {
577 "eos_data": [
578 {
579 "vrfs": {
580 "default": {
581 "instList": {
582 "100": {
583 "ospfNeighborEntries": [
584 {
585 "routerId": "10.1.0.14",
586 "interfaceAddress": "10.1.255.53",
587 "interfaceName": "Ethernet4",
588 "adjacencyState": "exchStart",
589 "details": {
590 "areaId": "0.0.217.3",
591 },
592 },
593 {
594 "routerId": "10.1.0.13",
595 "interfaceAddress": "10.1.255.49",
596 "interfaceName": "Ethernet3",
597 "adjacencyState": "down",
598 "details": {
599 "areaId": "0.0.217.3",
600 },
601 },
602 ]
603 }
604 }
605 },
606 },
607 }
608 ],
609 "inputs": {
610 "neighbors": [
611 {"instance": 100, "vrf": "default", "ip_address": "10.1.255.53", "local_interface": "Ethernet4", "area_id": 55555},
612 {"instance": 100, "vrf": "default", "ip_address": "10.1.255.49", "local_interface": "Ethernet3", "area_id": "0.0.217.3"},
613 ]
614 },
615 "expected": {
616 "result": AntaTestStatus.FAILURE,
617 "messages": [
618 "Instance: 100 VRF: default Neighbor IP: 10.1.255.53 Area: 0.0.217.3 - Adjacency state mismatch - Expected: full Actual: exchStart",
619 "Instance: 100 VRF: default Neighbor IP: 10.1.255.49 Area: 0.0.217.3 - Adjacency state mismatch - Expected: full Actual: down",
620 ],
621 },
622 },
623 }