2025-03-17 07:33:45 +01:00
|
|
|
# Copyright (c) 2023-2025 Arista Networks, Inc.
|
2025-02-05 11:32:35 +01:00
|
|
|
# Use of this source code is governed by the Apache License 2.0
|
|
|
|
# that can be found in the LICENSE file.
|
2025-02-05 11:38:32 +01:00
|
|
|
"""Tests for anta.tests.routing.ospf.py."""
|
|
|
|
|
2025-02-05 11:32:35 +01:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2025-05-15 09:34:27 +02:00
|
|
|
import sys
|
|
|
|
from typing import TYPE_CHECKING, Any
|
2025-02-05 11:32:35 +01:00
|
|
|
|
2025-05-15 09:34:27 +02:00
|
|
|
from anta.models import AntaTest
|
|
|
|
from anta.result_manager.models import AntaTestStatus
|
2025-02-05 11:38:32 +01:00
|
|
|
from anta.tests.routing.ospf import VerifyOSPFMaxLSA, VerifyOSPFNeighborCount, VerifyOSPFNeighborState
|
2025-05-15 09:34:27 +02:00
|
|
|
from tests.units.anta_tests import AntaUnitTest, test
|
2025-02-05 11:32:35 +01:00
|
|
|
|
2025-05-15 09:34:27 +02:00
|
|
|
if sys.version_info >= (3, 10):
|
|
|
|
from typing import TypeAlias
|
|
|
|
else:
|
|
|
|
TypeAlias = type
|
|
|
|
|
|
|
|
|
|
|
|
AntaUnitTestDataDict: TypeAlias = dict[tuple[type[AntaTest], str], AntaUnitTest]
|
|
|
|
|
|
|
|
DATA: AntaUnitTestDataDict = {
|
|
|
|
(VerifyOSPFNeighborState, "success"): {
|
2025-02-05 11:32:35 +01:00
|
|
|
"eos_data": [
|
|
|
|
{
|
|
|
|
"vrfs": {
|
|
|
|
"default": {
|
|
|
|
"instList": {
|
|
|
|
"666": {
|
|
|
|
"ospfNeighborEntries": [
|
|
|
|
{
|
|
|
|
"routerId": "7.7.7.7",
|
|
|
|
"priority": 1,
|
|
|
|
"drState": "DR",
|
|
|
|
"interfaceName": "Ethernet1",
|
|
|
|
"adjacencyState": "full",
|
|
|
|
"inactivity": 1683298014.844345,
|
|
|
|
"interfaceAddress": "10.3.0.1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"routerId": "9.9.9.9",
|
|
|
|
"priority": 1,
|
|
|
|
"drState": "DR",
|
|
|
|
"interfaceName": "Ethernet1",
|
|
|
|
"adjacencyState": "full",
|
|
|
|
"inactivity": 1683298014.844345,
|
|
|
|
"interfaceAddress": "10.3.0.1",
|
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2025-02-05 11:32:35 +01:00
|
|
|
},
|
|
|
|
"BLAH": {
|
|
|
|
"instList": {
|
|
|
|
"777": {
|
|
|
|
"ospfNeighborEntries": [
|
|
|
|
{
|
|
|
|
"routerId": "8.8.8.8",
|
|
|
|
"priority": 1,
|
|
|
|
"drState": "DR",
|
|
|
|
"interfaceName": "Ethernet1",
|
|
|
|
"adjacencyState": "full",
|
|
|
|
"inactivity": 1683298014.844345,
|
|
|
|
"interfaceAddress": "10.3.0.1",
|
2025-05-15 09:34:27 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2025-02-05 11:32:35 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
}
|
|
|
|
}
|
2025-02-05 11:32:35 +01:00
|
|
|
],
|
2025-05-15 09:34:27 +02:00
|
|
|
"expected": {"result": AntaTestStatus.SUCCESS},
|
2025-02-05 11:32:35 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifyOSPFNeighborState, "failure"): {
|
2025-02-05 11:32:35 +01:00
|
|
|
"eos_data": [
|
|
|
|
{
|
|
|
|
"vrfs": {
|
|
|
|
"default": {
|
|
|
|
"instList": {
|
|
|
|
"666": {
|
|
|
|
"ospfNeighborEntries": [
|
|
|
|
{
|
|
|
|
"routerId": "7.7.7.7",
|
|
|
|
"priority": 1,
|
|
|
|
"drState": "DR",
|
|
|
|
"interfaceName": "Ethernet1",
|
|
|
|
"adjacencyState": "2-way",
|
|
|
|
"inactivity": 1683298014.844345,
|
|
|
|
"interfaceAddress": "10.3.0.1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"routerId": "9.9.9.9",
|
|
|
|
"priority": 1,
|
|
|
|
"drState": "DR",
|
|
|
|
"interfaceName": "Ethernet1",
|
|
|
|
"adjacencyState": "full",
|
|
|
|
"inactivity": 1683298014.844345,
|
|
|
|
"interfaceAddress": "10.3.0.1",
|
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2025-02-05 11:32:35 +01:00
|
|
|
},
|
|
|
|
"BLAH": {
|
|
|
|
"instList": {
|
|
|
|
"777": {
|
|
|
|
"ospfNeighborEntries": [
|
|
|
|
{
|
|
|
|
"routerId": "8.8.8.8",
|
|
|
|
"priority": 1,
|
|
|
|
"drState": "DR",
|
|
|
|
"interfaceName": "Ethernet1",
|
|
|
|
"adjacencyState": "down",
|
|
|
|
"inactivity": 1683298014.844345,
|
|
|
|
"interfaceAddress": "10.3.0.1",
|
2025-05-15 09:34:27 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2025-02-05 11:32:35 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
}
|
|
|
|
}
|
2025-02-05 11:32:35 +01:00
|
|
|
],
|
|
|
|
"expected": {
|
2025-05-15 09:34:27 +02:00
|
|
|
"result": AntaTestStatus.FAILURE,
|
2025-02-05 11:32:35 +01:00
|
|
|
"messages": [
|
2025-03-17 07:33:45 +01:00
|
|
|
"Instance: 666 VRF: default Interface: 7.7.7.7 - Incorrect adjacency state - Expected: Full Actual: 2-way",
|
|
|
|
"Instance: 777 VRF: BLAH Interface: 8.8.8.8 - Incorrect adjacency state - Expected: Full Actual: down",
|
2025-02-05 11:32:35 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifyOSPFNeighborState, "skipped-ospf-not-configured"): {
|
|
|
|
"eos_data": [{"vrfs": {}}],
|
|
|
|
"expected": {"result": AntaTestStatus.SKIPPED, "messages": ["OSPF not configured"]},
|
2025-03-17 07:33:45 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifyOSPFNeighborState, "skipped-neighbor-not-found"): {
|
|
|
|
"eos_data": [{"vrfs": {"default": {"instList": {"666": {"ospfNeighborEntries": []}}}, "BLAH": {"instList": {"777": {"ospfNeighborEntries": []}}}}}],
|
|
|
|
"expected": {"result": AntaTestStatus.SKIPPED, "messages": ["No OSPF neighbor detected"]},
|
2025-02-05 11:32:35 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifyOSPFNeighborCount, "success"): {
|
2025-02-05 11:32:35 +01:00
|
|
|
"eos_data": [
|
|
|
|
{
|
|
|
|
"vrfs": {
|
|
|
|
"default": {
|
|
|
|
"instList": {
|
|
|
|
"666": {
|
|
|
|
"ospfNeighborEntries": [
|
|
|
|
{
|
|
|
|
"routerId": "7.7.7.7",
|
|
|
|
"priority": 1,
|
|
|
|
"drState": "DR",
|
|
|
|
"interfaceName": "Ethernet1",
|
|
|
|
"adjacencyState": "full",
|
|
|
|
"inactivity": 1683298014.844345,
|
|
|
|
"interfaceAddress": "10.3.0.1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"routerId": "9.9.9.9",
|
|
|
|
"priority": 1,
|
|
|
|
"drState": "DR",
|
|
|
|
"interfaceName": "Ethernet1",
|
|
|
|
"adjacencyState": "full",
|
|
|
|
"inactivity": 1683298014.844345,
|
|
|
|
"interfaceAddress": "10.3.0.1",
|
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2025-02-05 11:32:35 +01:00
|
|
|
},
|
|
|
|
"BLAH": {
|
|
|
|
"instList": {
|
|
|
|
"777": {
|
|
|
|
"ospfNeighborEntries": [
|
|
|
|
{
|
|
|
|
"routerId": "8.8.8.8",
|
|
|
|
"priority": 1,
|
|
|
|
"drState": "DR",
|
|
|
|
"interfaceName": "Ethernet1",
|
|
|
|
"adjacencyState": "full",
|
|
|
|
"inactivity": 1683298014.844345,
|
|
|
|
"interfaceAddress": "10.3.0.1",
|
2025-05-15 09:34:27 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2025-02-05 11:32:35 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
}
|
|
|
|
}
|
2025-02-05 11:32:35 +01:00
|
|
|
],
|
|
|
|
"inputs": {"number": 3},
|
2025-05-15 09:34:27 +02:00
|
|
|
"expected": {"result": AntaTestStatus.SUCCESS},
|
2025-02-05 11:32:35 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifyOSPFNeighborCount, "failure-good-number-wrong-state"): {
|
2025-02-05 11:32:35 +01:00
|
|
|
"eos_data": [
|
|
|
|
{
|
|
|
|
"vrfs": {
|
|
|
|
"default": {
|
|
|
|
"instList": {
|
|
|
|
"666": {
|
|
|
|
"ospfNeighborEntries": [
|
|
|
|
{
|
|
|
|
"routerId": "7.7.7.7",
|
|
|
|
"priority": 1,
|
|
|
|
"drState": "DR",
|
|
|
|
"interfaceName": "Ethernet1",
|
|
|
|
"adjacencyState": "2-way",
|
|
|
|
"inactivity": 1683298014.844345,
|
|
|
|
"interfaceAddress": "10.3.0.1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"routerId": "9.9.9.9",
|
|
|
|
"priority": 1,
|
|
|
|
"drState": "DR",
|
|
|
|
"interfaceName": "Ethernet1",
|
|
|
|
"adjacencyState": "full",
|
|
|
|
"inactivity": 1683298014.844345,
|
|
|
|
"interfaceAddress": "10.3.0.1",
|
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2025-02-05 11:32:35 +01:00
|
|
|
},
|
|
|
|
"BLAH": {
|
|
|
|
"instList": {
|
|
|
|
"777": {
|
|
|
|
"ospfNeighborEntries": [
|
|
|
|
{
|
|
|
|
"routerId": "8.8.8.8",
|
|
|
|
"priority": 1,
|
|
|
|
"drState": "DR",
|
|
|
|
"interfaceName": "Ethernet1",
|
|
|
|
"adjacencyState": "down",
|
|
|
|
"inactivity": 1683298014.844345,
|
|
|
|
"interfaceAddress": "10.3.0.1",
|
2025-05-15 09:34:27 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2025-02-05 11:32:35 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
}
|
|
|
|
}
|
2025-02-05 11:32:35 +01:00
|
|
|
],
|
|
|
|
"inputs": {"number": 3},
|
2025-05-15 09:34:27 +02:00
|
|
|
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["Neighbor count mismatch - Expected: 3 Actual: 1"]},
|
2025-02-05 11:32:35 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifyOSPFNeighborCount, "skipped-ospf-not-configured"): {
|
|
|
|
"eos_data": [{"vrfs": {}}],
|
2025-02-05 11:32:35 +01:00
|
|
|
"inputs": {"number": 3},
|
2025-05-15 09:34:27 +02:00
|
|
|
"expected": {"result": AntaTestStatus.SKIPPED, "messages": ["OSPF not configured"]},
|
2025-03-17 07:33:45 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifyOSPFNeighborCount, "skipped-no-neighbor-detected"): {
|
|
|
|
"eos_data": [{"vrfs": {"default": {"instList": {"666": {"ospfNeighborEntries": []}}}, "BLAH": {"instList": {"777": {"ospfNeighborEntries": []}}}}}],
|
2025-03-17 07:33:45 +01:00
|
|
|
"inputs": {"number": 3},
|
2025-05-15 09:34:27 +02:00
|
|
|
"expected": {"result": AntaTestStatus.SKIPPED, "messages": ["No OSPF neighbor detected"]},
|
2025-02-05 11:32:35 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifyOSPFMaxLSA, "success"): {
|
2025-02-05 11:38:32 +01:00
|
|
|
"eos_data": [
|
|
|
|
{
|
|
|
|
"vrfs": {
|
|
|
|
"default": {
|
|
|
|
"instList": {
|
|
|
|
"1": {
|
|
|
|
"instanceId": 1,
|
2025-05-15 09:34:27 +02:00
|
|
|
"maxLsaInformation": {"maxLsa": 12000, "maxLsaThreshold": 75},
|
2025-02-05 11:38:32 +01:00
|
|
|
"routerId": "1.1.1.1",
|
|
|
|
"lsaInformation": {
|
|
|
|
"lsaArrivalInterval": 1000,
|
|
|
|
"lsaStartInterval": 1000,
|
|
|
|
"lsaHoldInterval": 5000,
|
|
|
|
"lsaMaxWaitInterval": 5000,
|
|
|
|
"numLsa": 9,
|
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
}
|
|
|
|
}
|
2025-02-05 11:38:32 +01:00
|
|
|
},
|
|
|
|
"TEST": {
|
|
|
|
"instList": {
|
|
|
|
"10": {
|
|
|
|
"instanceId": 10,
|
2025-05-15 09:34:27 +02:00
|
|
|
"maxLsaInformation": {"maxLsa": 1000, "maxLsaThreshold": 75},
|
2025-02-05 11:38:32 +01:00
|
|
|
"routerId": "20.20.20.20",
|
|
|
|
"lsaInformation": {
|
|
|
|
"lsaArrivalInterval": 1000,
|
|
|
|
"lsaStartInterval": 1000,
|
|
|
|
"lsaHoldInterval": 5000,
|
|
|
|
"lsaMaxWaitInterval": 5000,
|
|
|
|
"numLsa": 5,
|
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
}
|
|
|
|
}
|
2025-02-05 11:38:32 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
}
|
|
|
|
}
|
2025-02-05 11:38:32 +01:00
|
|
|
],
|
2025-05-15 09:34:27 +02:00
|
|
|
"expected": {"result": AntaTestStatus.SUCCESS},
|
2025-02-05 11:38:32 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifyOSPFMaxLSA, "failure"): {
|
2025-02-05 11:38:32 +01:00
|
|
|
"eos_data": [
|
|
|
|
{
|
|
|
|
"vrfs": {
|
|
|
|
"default": {
|
|
|
|
"instList": {
|
|
|
|
"1": {
|
|
|
|
"instanceId": 1,
|
2025-05-15 09:34:27 +02:00
|
|
|
"maxLsaInformation": {"maxLsa": 12000, "maxLsaThreshold": 75},
|
2025-02-05 11:38:32 +01:00
|
|
|
"routerId": "1.1.1.1",
|
|
|
|
"lsaInformation": {
|
|
|
|
"lsaArrivalInterval": 1000,
|
|
|
|
"lsaStartInterval": 1000,
|
|
|
|
"lsaHoldInterval": 5000,
|
|
|
|
"lsaMaxWaitInterval": 5000,
|
|
|
|
"numLsa": 11500,
|
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
}
|
|
|
|
}
|
2025-02-05 11:38:32 +01:00
|
|
|
},
|
|
|
|
"TEST": {
|
|
|
|
"instList": {
|
|
|
|
"10": {
|
|
|
|
"instanceId": 10,
|
2025-05-15 09:34:27 +02:00
|
|
|
"maxLsaInformation": {"maxLsa": 1000, "maxLsaThreshold": 75},
|
2025-02-05 11:38:32 +01:00
|
|
|
"routerId": "20.20.20.20",
|
|
|
|
"lsaInformation": {
|
|
|
|
"lsaArrivalInterval": 1000,
|
|
|
|
"lsaStartInterval": 1000,
|
|
|
|
"lsaHoldInterval": 5000,
|
|
|
|
"lsaMaxWaitInterval": 5000,
|
|
|
|
"numLsa": 1500,
|
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
}
|
|
|
|
}
|
2025-02-05 11:38:32 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
}
|
|
|
|
}
|
2025-02-05 11:38:32 +01:00
|
|
|
],
|
|
|
|
"expected": {
|
2025-05-15 09:34:27 +02:00
|
|
|
"result": AntaTestStatus.FAILURE,
|
2025-03-17 07:33:45 +01:00
|
|
|
"messages": [
|
|
|
|
"Instance: 1 - Crossed the maximum LSA threshold - Expected: < 9000 Actual: 11500",
|
|
|
|
"Instance: 10 - Crossed the maximum LSA threshold - Expected: < 750 Actual: 1500",
|
|
|
|
],
|
2025-02-05 11:38:32 +01:00
|
|
|
},
|
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifyOSPFMaxLSA, "skipped"): {"eos_data": [{"vrfs": {}}], "expected": {"result": AntaTestStatus.SKIPPED, "messages": ["OSPF not configured"]}},
|
|
|
|
}
|