2025-03-17 07:33:45 +01:00
|
|
|
# Copyright (c) 2023-2025 Arista Networks, Inc.
|
2025-02-05 11:39:42 +01:00
|
|
|
# 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.path_selection.py."""
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
2025-05-15 09:34:27 +02:00
|
|
|
import sys
|
|
|
|
from typing import TYPE_CHECKING, Any
|
2025-02-05 11:39:42 +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:39:42 +01:00
|
|
|
from anta.tests.path_selection import VerifyPathsHealth, VerifySpecificPath
|
2025-02-05 11:54:23 +01:00
|
|
|
from tests.units.anta_tests import test
|
2025-02-05 11:39:42 +01:00
|
|
|
|
2025-05-15 09:34:27 +02:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from tests.units.anta_tests import AntaUnitTestDataDict
|
|
|
|
|
|
|
|
DATA: AntaUnitTestDataDict = {
|
|
|
|
(VerifyPathsHealth, "success"): {
|
2025-02-05 11:39:42 +01:00
|
|
|
"eos_data": [
|
|
|
|
{
|
|
|
|
"dpsPeers": {
|
|
|
|
"10.255.0.1": {
|
|
|
|
"dpsGroups": {
|
2025-05-15 09:34:27 +02:00
|
|
|
"internet": {"dpsPaths": {"path3": {"state": "routeResolved", "dpsSessions": {"0": {"active": True}}}}},
|
|
|
|
"mpls": {"dpsPaths": {"path4": {"state": "ipsecEstablished", "dpsSessions": {"0": {"active": True}}}}},
|
|
|
|
}
|
2025-02-05 11:39:42 +01:00
|
|
|
},
|
|
|
|
"10.255.0.2": {
|
|
|
|
"dpsGroups": {
|
2025-05-15 09:34:27 +02:00
|
|
|
"internet": {"dpsPaths": {"path1": {"state": "ipsecEstablished", "dpsSessions": {"0": {"active": True}}}}},
|
|
|
|
"mpls": {"dpsPaths": {"path2": {"state": "routeResolved", "dpsSessions": {"0": {"active": True}}}}},
|
|
|
|
}
|
2025-02-05 11:39:42 +01:00
|
|
|
},
|
|
|
|
}
|
2025-05-15 09:34:27 +02:00
|
|
|
}
|
2025-02-05 11:39:42 +01:00
|
|
|
],
|
|
|
|
"inputs": {},
|
2025-05-15 09:34:27 +02:00
|
|
|
"expected": {"result": AntaTestStatus.SUCCESS},
|
2025-02-05 11:39:42 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifyPathsHealth, "failure-no-peer"): {
|
|
|
|
"eos_data": [{"dpsPeers": {}}],
|
2025-02-05 11:39:42 +01:00
|
|
|
"inputs": {},
|
2025-05-15 09:34:27 +02:00
|
|
|
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["No path configured for router path-selection"]},
|
2025-02-05 11:39:42 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifyPathsHealth, "failure-not-established"): {
|
2025-02-05 11:39:42 +01:00
|
|
|
"eos_data": [
|
|
|
|
{
|
|
|
|
"dpsPeers": {
|
|
|
|
"10.255.0.1": {
|
|
|
|
"dpsGroups": {
|
2025-05-15 09:34:27 +02:00
|
|
|
"internet": {"dpsPaths": {"path3": {"state": "ipsecPending", "dpsSessions": {"0": {"active": False}}}}},
|
|
|
|
"mpls": {"dpsPaths": {"path4": {"state": "ipsecPending", "dpsSessions": {"0": {"active": False}}}}},
|
|
|
|
}
|
2025-02-05 11:39:42 +01:00
|
|
|
},
|
|
|
|
"10.255.0.2": {
|
|
|
|
"dpsGroups": {
|
2025-05-15 09:34:27 +02:00
|
|
|
"internet": {"dpsPaths": {"path1": {"state": "ipsecEstablished", "dpsSessions": {"0": {"active": True}}}}},
|
|
|
|
"mpls": {"dpsPaths": {"path2": {"state": "ipsecPending", "dpsSessions": {"0": {"active": False}}}}},
|
|
|
|
}
|
2025-02-05 11:39:42 +01:00
|
|
|
},
|
|
|
|
}
|
2025-05-15 09:34:27 +02:00
|
|
|
}
|
2025-02-05 11:39:42 +01:00
|
|
|
],
|
|
|
|
"inputs": {},
|
|
|
|
"expected": {
|
2025-05-15 09:34:27 +02:00
|
|
|
"result": AntaTestStatus.FAILURE,
|
2025-02-05 11:39:42 +01:00
|
|
|
"messages": [
|
2025-03-17 07:33:45 +01:00
|
|
|
"Peer: 10.255.0.1 Path Group: internet - Invalid path state - Expected: ipsecEstablished, routeResolved Actual: ipsecPending",
|
|
|
|
"Peer: 10.255.0.1 Path Group: mpls - Invalid path state - Expected: ipsecEstablished, routeResolved Actual: ipsecPending",
|
|
|
|
"Peer: 10.255.0.2 Path Group: mpls - Invalid path state - Expected: ipsecEstablished, routeResolved Actual: ipsecPending",
|
2025-02-05 11:39:42 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifyPathsHealth, "failure-inactive"): {
|
2025-02-05 11:39:42 +01:00
|
|
|
"eos_data": [
|
|
|
|
{
|
|
|
|
"dpsPeers": {
|
|
|
|
"10.255.0.1": {
|
|
|
|
"dpsGroups": {
|
2025-05-15 09:34:27 +02:00
|
|
|
"internet": {"dpsPaths": {"path3": {"state": "routeResolved", "dpsSessions": {"0": {"active": False}}}}},
|
|
|
|
"mpls": {"dpsPaths": {"path4": {"state": "routeResolved", "dpsSessions": {"0": {"active": False}}}}},
|
|
|
|
}
|
2025-02-05 11:39:42 +01:00
|
|
|
},
|
|
|
|
"10.255.0.2": {
|
|
|
|
"dpsGroups": {
|
2025-05-15 09:34:27 +02:00
|
|
|
"internet": {"dpsPaths": {"path1": {"state": "routeResolved", "dpsSessions": {"0": {"active": True}}}}},
|
|
|
|
"mpls": {"dpsPaths": {"path2": {"state": "routeResolved", "dpsSessions": {"0": {"active": False}}}}},
|
|
|
|
}
|
2025-02-05 11:39:42 +01:00
|
|
|
},
|
|
|
|
}
|
2025-05-15 09:34:27 +02:00
|
|
|
}
|
2025-02-05 11:39:42 +01:00
|
|
|
],
|
|
|
|
"inputs": {},
|
|
|
|
"expected": {
|
2025-05-15 09:34:27 +02:00
|
|
|
"result": AntaTestStatus.FAILURE,
|
2025-02-05 11:39:42 +01:00
|
|
|
"messages": [
|
2025-03-17 07:33:45 +01:00
|
|
|
"Peer: 10.255.0.1 Path Group internet - Telemetry state inactive",
|
|
|
|
"Peer: 10.255.0.1 Path Group mpls - Telemetry state inactive",
|
|
|
|
"Peer: 10.255.0.2 Path Group mpls - Telemetry state inactive",
|
2025-02-05 11:39:42 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifySpecificPath, "success"): {
|
2025-02-05 11:39:42 +01:00
|
|
|
"eos_data": [
|
|
|
|
{
|
|
|
|
"dpsPeers": {
|
2025-03-17 07:33:45 +01:00
|
|
|
"10.255.0.2": {
|
2025-02-05 11:39:42 +01:00
|
|
|
"dpsGroups": {
|
2025-03-17 07:33:45 +01:00
|
|
|
"mpls": {
|
2025-02-05 11:39:42 +01:00
|
|
|
"dpsPaths": {
|
2025-03-17 07:33:45 +01:00
|
|
|
"path7": {},
|
|
|
|
"path8": {
|
2025-02-05 11:39:42 +01:00
|
|
|
"source": "172.18.13.2",
|
|
|
|
"destination": "172.18.15.2",
|
2025-03-17 07:33:45 +01:00
|
|
|
"state": "ipsecEstablished",
|
2025-02-05 11:39:42 +01:00
|
|
|
"dpsSessions": {"0": {"active": True}},
|
2025-03-17 07:33:45 +01:00
|
|
|
},
|
2025-02-05 11:39:42 +01:00
|
|
|
}
|
2025-03-17 07:33:45 +01:00
|
|
|
},
|
|
|
|
"internet": {},
|
2025-02-05 11:39:42 +01:00
|
|
|
}
|
2025-03-17 07:33:45 +01:00
|
|
|
},
|
|
|
|
"10.255.0.1": {
|
2025-02-05 11:39:42 +01:00
|
|
|
"dpsGroups": {
|
2025-03-17 07:33:45 +01:00
|
|
|
"internet": {
|
2025-02-05 11:39:42 +01:00
|
|
|
"dpsPaths": {
|
2025-03-17 07:33:45 +01:00
|
|
|
"path6": {
|
|
|
|
"source": "100.64.3.2",
|
|
|
|
"destination": "100.64.1.2",
|
2025-02-05 11:39:42 +01:00
|
|
|
"state": "ipsecEstablished",
|
|
|
|
"dpsSessions": {"0": {"active": True}},
|
|
|
|
}
|
|
|
|
}
|
2025-03-17 07:33:45 +01:00
|
|
|
},
|
|
|
|
"mpls": {},
|
2025-02-05 11:39:42 +01:00
|
|
|
}
|
2025-03-17 07:33:45 +01:00
|
|
|
},
|
2025-02-05 11:39:42 +01:00
|
|
|
}
|
2025-03-17 07:33:45 +01:00
|
|
|
}
|
2025-02-05 11:39:42 +01:00
|
|
|
],
|
|
|
|
"inputs": {
|
|
|
|
"paths": [
|
2025-03-17 07:33:45 +01:00
|
|
|
{"peer": "10.255.0.1", "path_group": "internet", "source_address": "100.64.3.2", "destination_address": "100.64.1.2"},
|
2025-02-05 11:39:42 +01:00
|
|
|
{"peer": "10.255.0.2", "path_group": "mpls", "source_address": "172.18.13.2", "destination_address": "172.18.15.2"},
|
|
|
|
]
|
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
"expected": {"result": AntaTestStatus.SUCCESS},
|
2025-02-05 11:39:42 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifySpecificPath, "failure-expected-path-group-not-found"): {
|
|
|
|
"eos_data": [{"dpsPeers": {"10.255.0.2": {"dpsGroups": {"internet": {}}}, "10.255.0.1": {"peerName": "", "dpsGroups": {"mpls": {}}}}}],
|
2025-02-05 11:39:42 +01:00
|
|
|
"inputs": {
|
|
|
|
"paths": [
|
2025-03-17 07:33:45 +01:00
|
|
|
{"peer": "10.255.0.1", "path_group": "internet", "source_address": "100.64.3.2", "destination_address": "100.64.1.2"},
|
2025-02-05 11:39:42 +01:00
|
|
|
{"peer": "10.255.0.2", "path_group": "mpls", "source_address": "172.18.13.2", "destination_address": "172.18.15.2"},
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"expected": {
|
2025-05-15 09:34:27 +02:00
|
|
|
"result": AntaTestStatus.FAILURE,
|
2025-02-05 11:39:42 +01:00
|
|
|
"messages": [
|
2025-03-17 07:33:45 +01:00
|
|
|
"Peer: 10.255.0.1 PathGroup: internet Source: 100.64.3.2 Destination: 100.64.1.2 - No DPS path found for this peer and path group",
|
|
|
|
"Peer: 10.255.0.2 PathGroup: mpls Source: 172.18.13.2 Destination: 172.18.15.2 - No DPS path found for this peer and path group",
|
2025-02-05 11:39:42 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifySpecificPath, "failure-no-router-path-configured"): {
|
2025-03-17 07:33:45 +01:00
|
|
|
"eos_data": [{"dpsPeers": {}}],
|
|
|
|
"inputs": {"paths": [{"peer": "10.255.0.1", "path_group": "internet", "source_address": "100.64.3.2", "destination_address": "100.64.1.2"}]},
|
2025-05-15 09:34:27 +02:00
|
|
|
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["Router path-selection not configured"]},
|
2025-03-17 07:33:45 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifySpecificPath, "failure-no-specific-peer-configured"): {
|
2025-03-17 07:33:45 +01:00
|
|
|
"eos_data": [{"dpsPeers": {"10.255.0.2": {}}}],
|
|
|
|
"inputs": {"paths": [{"peer": "10.255.0.1", "path_group": "internet", "source_address": "172.18.3.2", "destination_address": "172.18.5.2"}]},
|
2025-05-15 09:34:27 +02:00
|
|
|
"expected": {
|
|
|
|
"result": AntaTestStatus.FAILURE,
|
|
|
|
"messages": ["Peer: 10.255.0.1 PathGroup: internet Source: 172.18.3.2 Destination: 172.18.5.2 - Peer not found"],
|
|
|
|
},
|
2025-03-17 07:33:45 +01:00
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifySpecificPath, "failure-not-established"): {
|
2025-02-05 11:39:42 +01:00
|
|
|
"eos_data": [
|
|
|
|
{
|
|
|
|
"dpsPeers": {
|
2025-03-17 07:33:45 +01:00
|
|
|
"10.255.0.2": {
|
|
|
|
"dpsGroups": {
|
|
|
|
"mpls": {
|
|
|
|
"dpsPaths": {
|
|
|
|
"path7": {},
|
|
|
|
"path8": {
|
|
|
|
"source": "172.18.13.2",
|
|
|
|
"destination": "172.18.15.2",
|
|
|
|
"state": "ipsecPending",
|
|
|
|
"dpsSessions": {"0": {"active": True}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"internet": {"dpsPaths": {}},
|
|
|
|
}
|
|
|
|
},
|
2025-02-05 11:39:42 +01:00
|
|
|
"10.255.0.1": {
|
|
|
|
"dpsGroups": {
|
|
|
|
"internet": {
|
|
|
|
"dpsPaths": {
|
2025-03-17 07:33:45 +01:00
|
|
|
"path6": {"source": "172.18.3.2", "destination": "172.18.5.2", "state": "ipsecPending", "dpsSessions": {"0": {"active": True}}}
|
2025-02-05 11:39:42 +01:00
|
|
|
}
|
2025-03-17 07:33:45 +01:00
|
|
|
},
|
|
|
|
"mpls": {"dpsPaths": {}},
|
2025-02-05 11:39:42 +01:00
|
|
|
}
|
2025-03-17 07:33:45 +01:00
|
|
|
},
|
2025-02-05 11:39:42 +01:00
|
|
|
}
|
2025-03-17 07:33:45 +01:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"inputs": {
|
|
|
|
"paths": [
|
|
|
|
{"peer": "10.255.0.1", "path_group": "internet", "source_address": "172.18.3.2", "destination_address": "172.18.5.2"},
|
|
|
|
{"peer": "10.255.0.2", "path_group": "mpls", "source_address": "172.18.13.2", "destination_address": "172.18.15.2"},
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"expected": {
|
2025-05-15 09:34:27 +02:00
|
|
|
"result": AntaTestStatus.FAILURE,
|
2025-03-17 07:33:45 +01:00
|
|
|
"messages": [
|
2025-05-15 09:34:27 +02:00
|
|
|
"Peer: 10.255.0.1 PathGroup: internet Source: 172.18.3.2 Destination: 172.18.5.2 - Invalid state path - "
|
|
|
|
"Expected: ipsecEstablished, routeResolved Actual: ipsecPending",
|
|
|
|
"Peer: 10.255.0.2 PathGroup: mpls Source: 172.18.13.2 Destination: 172.18.15.2 - Invalid state path - "
|
|
|
|
"Expected: ipsecEstablished, routeResolved Actual: ipsecPending",
|
2025-03-17 07:33:45 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifySpecificPath, "failure-inactive"): {
|
2025-03-17 07:33:45 +01:00
|
|
|
"eos_data": [
|
2025-02-05 11:39:42 +01:00
|
|
|
{
|
|
|
|
"dpsPeers": {
|
|
|
|
"10.255.0.2": {
|
|
|
|
"dpsGroups": {
|
|
|
|
"mpls": {
|
|
|
|
"dpsPaths": {
|
2025-03-17 07:33:45 +01:00
|
|
|
"path8": {
|
2025-02-05 11:39:42 +01:00
|
|
|
"source": "172.18.13.2",
|
|
|
|
"destination": "172.18.15.2",
|
2025-03-17 07:33:45 +01:00
|
|
|
"state": "routeResolved",
|
2025-02-05 11:39:42 +01:00
|
|
|
"dpsSessions": {"0": {"active": False}},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2025-03-17 07:33:45 +01:00
|
|
|
},
|
|
|
|
"10.255.0.1": {
|
|
|
|
"dpsGroups": {
|
|
|
|
"internet": {
|
|
|
|
"dpsPaths": {
|
|
|
|
"path6": {"source": "172.18.3.2", "destination": "172.18.5.2", "state": "routeResolved", "dpsSessions": {"0": {"active": False}}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2025-02-05 11:39:42 +01:00
|
|
|
}
|
2025-03-17 07:33:45 +01:00
|
|
|
}
|
2025-02-05 11:39:42 +01:00
|
|
|
],
|
|
|
|
"inputs": {
|
|
|
|
"paths": [
|
|
|
|
{"peer": "10.255.0.1", "path_group": "internet", "source_address": "172.18.3.2", "destination_address": "172.18.5.2"},
|
|
|
|
{"peer": "10.255.0.2", "path_group": "mpls", "source_address": "172.18.13.2", "destination_address": "172.18.15.2"},
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"expected": {
|
2025-05-15 09:34:27 +02:00
|
|
|
"result": AntaTestStatus.FAILURE,
|
2025-02-05 11:39:42 +01:00
|
|
|
"messages": [
|
2025-03-17 07:33:45 +01:00
|
|
|
"Peer: 10.255.0.1 PathGroup: internet Source: 172.18.3.2 Destination: 172.18.5.2 - Telemetry state inactive for this path",
|
|
|
|
"Peer: 10.255.0.2 PathGroup: mpls Source: 172.18.13.2 Destination: 172.18.15.2 - Telemetry state inactive for this path",
|
2025-02-05 11:39:42 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
(VerifySpecificPath, "failure-source-destination-not-configured"): {
|
2025-02-05 11:39:42 +01:00
|
|
|
"eos_data": [
|
|
|
|
{
|
|
|
|
"dpsPeers": {
|
2025-03-17 07:33:45 +01:00
|
|
|
"10.255.0.2": {
|
2025-02-05 11:39:42 +01:00
|
|
|
"dpsGroups": {
|
2025-03-17 07:33:45 +01:00
|
|
|
"mpls": {
|
2025-02-05 11:39:42 +01:00
|
|
|
"dpsPaths": {
|
2025-03-17 07:33:45 +01:00
|
|
|
"path8": {"source": "172.18.3.2", "destination": "172.8.15.2", "state": "routeResolved", "dpsSessions": {"0": {"active": False}}}
|
2025-02-05 11:39:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2025-03-17 07:33:45 +01:00
|
|
|
},
|
|
|
|
"10.255.0.1": {
|
2025-02-05 11:39:42 +01:00
|
|
|
"dpsGroups": {
|
2025-03-17 07:33:45 +01:00
|
|
|
"internet": {
|
2025-02-05 11:39:42 +01:00
|
|
|
"dpsPaths": {
|
2025-03-17 07:33:45 +01:00
|
|
|
"path6": {"source": "172.8.3.2", "destination": "172.8.5.2", "state": "routeResolved", "dpsSessions": {"0": {"active": False}}}
|
2025-02-05 11:39:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2025-03-17 07:33:45 +01:00
|
|
|
},
|
2025-02-05 11:39:42 +01:00
|
|
|
}
|
2025-03-17 07:33:45 +01:00
|
|
|
}
|
2025-02-05 11:39:42 +01:00
|
|
|
],
|
|
|
|
"inputs": {
|
|
|
|
"paths": [
|
|
|
|
{"peer": "10.255.0.1", "path_group": "internet", "source_address": "172.18.3.2", "destination_address": "172.18.5.2"},
|
|
|
|
{"peer": "10.255.0.2", "path_group": "mpls", "source_address": "172.18.13.2", "destination_address": "172.18.15.2"},
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"expected": {
|
2025-05-15 09:34:27 +02:00
|
|
|
"result": AntaTestStatus.FAILURE,
|
2025-02-05 11:39:42 +01:00
|
|
|
"messages": [
|
2025-03-17 07:33:45 +01:00
|
|
|
"Peer: 10.255.0.1 PathGroup: internet Source: 172.18.3.2 Destination: 172.18.5.2 - No path matching the source and destination found",
|
|
|
|
"Peer: 10.255.0.2 PathGroup: mpls Source: 172.18.13.2 Destination: 172.18.15.2 - No path matching the source and destination found",
|
2025-02-05 11:39:42 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2025-05-15 09:34:27 +02:00
|
|
|
}
|