diff options
Diffstat (limited to 'tests/units/anta_tests/routing/test_ospf.py')
-rw-r--r-- | tests/units/anta_tests/routing/test_ospf.py | 298 |
1 files changed, 298 insertions, 0 deletions
diff --git a/tests/units/anta_tests/routing/test_ospf.py b/tests/units/anta_tests/routing/test_ospf.py new file mode 100644 index 0000000..fbabee9 --- /dev/null +++ b/tests/units/anta_tests/routing/test_ospf.py @@ -0,0 +1,298 @@ +# Copyright (c) 2023-2024 Arista Networks, Inc. +# Use of this source code is governed by the Apache License 2.0 +# that can be found in the LICENSE file. +""" +Tests for anta.tests.routing.ospf.py +""" +from __future__ import annotations + +from typing import Any + +from anta.tests.routing.ospf import VerifyOSPFNeighborCount, VerifyOSPFNeighborState +from tests.lib.anta import test # noqa: F401; pylint: disable=W0611 + +DATA: list[dict[str, Any]] = [ + { + "name": "success", + "test": VerifyOSPFNeighborState, + "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", + }, + ] + } + } + }, + "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", + } + ] + } + } + }, + } + } + ], + "inputs": None, + "expected": {"result": "success"}, + }, + { + "name": "failure", + "test": VerifyOSPFNeighborState, + "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", + }, + ] + } + } + }, + "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", + } + ] + } + } + }, + } + } + ], + "inputs": None, + "expected": { + "result": "failure", + "messages": [ + "Some neighbors are not correctly configured: [{'vrf': 'default', 'instance': '666', 'neighbor': '7.7.7.7', 'state': '2-way'}," + " {'vrf': 'BLAH', 'instance': '777', 'neighbor': '8.8.8.8', 'state': 'down'}]." + ], + }, + }, + { + "name": "skipped", + "test": VerifyOSPFNeighborState, + "eos_data": [ + { + "vrfs": {}, + } + ], + "inputs": None, + "expected": {"result": "skipped", "messages": ["no OSPF neighbor found"]}, + }, + { + "name": "success", + "test": VerifyOSPFNeighborCount, + "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", + }, + ] + } + } + }, + "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", + } + ] + } + } + }, + } + } + ], + "inputs": {"number": 3}, + "expected": {"result": "success"}, + }, + { + "name": "failure-wrong-number", + "test": VerifyOSPFNeighborCount, + "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", + }, + ] + } + } + } + } + } + ], + "inputs": {"number": 3}, + "expected": {"result": "failure", "messages": ["device has 1 neighbors (expected 3)"]}, + }, + { + "name": "failure-good-number-wrong-state", + "test": VerifyOSPFNeighborCount, + "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", + }, + ] + } + } + }, + "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", + } + ] + } + } + }, + } + } + ], + "inputs": {"number": 3}, + "expected": { + "result": "failure", + "messages": [ + "Some neighbors are not correctly configured: [{'vrf': 'default', 'instance': '666', 'neighbor': '7.7.7.7', 'state': '2-way'}," + " {'vrf': 'BLAH', 'instance': '777', 'neighbor': '8.8.8.8', 'state': 'down'}]." + ], + }, + }, + { + "name": "skipped", + "test": VerifyOSPFNeighborCount, + "eos_data": [ + { + "vrfs": {}, + } + ], + "inputs": {"number": 3}, + "expected": {"result": "skipped", "messages": ["no OSPF neighbor found"]}, + }, +] |