| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
"""Tests for anta.input_models.routing.isis.py.""" |
| 5 |
|
| 6 |
from __future__ import annotations |
| 7 |
|
| 8 |
from typing import TYPE_CHECKING, Literal |
| 9 |
|
| 10 |
import pytest |
| 11 |
from pydantic import ValidationError |
| 12 |
|
| 13 |
from anta.input_models.routing.isis import ISISInstance, TunnelPath |
| 14 |
from anta.tests.routing.isis import VerifyISISSegmentRoutingAdjacencySegments, VerifyISISSegmentRoutingDataplane |
| 15 |
|
| 16 |
if TYPE_CHECKING: |
| 17 |
from ipaddress import IPv4Address |
| 18 |
|
| 19 |
from anta.custom_types import Interface |
| 20 |
|
| 21 |
|
| 22 |
class TestVerifyISISSegmentRoutingAdjacencySegmentsInput: |
| 23 |
"""Test anta.tests.routing.isis.VerifyISISSegmentRoutingAdjacencySegments.Input.""" |
| 24 |
|
| 25 |
@pytest.mark.parametrize( |
| 26 |
("instances"), |
| 27 |
[ |
| 28 |
pytest.param( |
| 29 |
[{"name": "CORE-ISIS", "vrf": "default", "segments": [{"interface": "Ethernet2", "address": "10.0.1.3", "sid_origin": "dynamic"}]}], id="valid_vrf" |
| 30 |
), |
| 31 |
], |
| 32 |
) |
| 33 |
def test_valid(self, instances: list[ISISInstance]) -> None: |
| 34 |
"""Test VerifyISISSegmentRoutingAdjacencySegments.Input valid inputs.""" |
| 35 |
VerifyISISSegmentRoutingAdjacencySegments.Input(instances=instances) |
| 36 |
|
| 37 |
@pytest.mark.parametrize( |
| 38 |
("instances"), |
| 39 |
[ |
| 40 |
pytest.param( |
| 41 |
[{"name": "CORE-ISIS", "vrf": "PROD", "segments": [{"interface": "Ethernet2", "address": "10.0.1.3", "sid_origin": "dynamic"}]}], id="invalid_vrf" |
| 42 |
), |
| 43 |
], |
| 44 |
) |
| 45 |
def test_invalid(self, instances: list[ISISInstance]) -> None: |
| 46 |
"""Test VerifyISISSegmentRoutingAdjacencySegments.Input invalid inputs.""" |
| 47 |
with pytest.raises(ValidationError): |
| 48 |
VerifyISISSegmentRoutingAdjacencySegments.Input(instances=instances) |
| 49 |
|
| 50 |
|
| 51 |
class TestVerifyISISSegmentRoutingDataplaneInput: |
| 52 |
"""Test anta.tests.routing.isis.VerifyISISSegmentRoutingDataplane.Input.""" |
| 53 |
|
| 54 |
@pytest.mark.parametrize( |
| 55 |
("instances"), |
| 56 |
[ |
| 57 |
pytest.param([{"name": "CORE-ISIS", "vrf": "default", "dataplane": "MPLS"}], id="valid_vrf"), |
| 58 |
], |
| 59 |
) |
| 60 |
def test_valid(self, instances: list[ISISInstance]) -> None: |
| 61 |
"""Test VerifyISISSegmentRoutingDataplane.Input valid inputs.""" |
| 62 |
VerifyISISSegmentRoutingDataplane.Input(instances=instances) |
| 63 |
|
| 64 |
@pytest.mark.parametrize( |
| 65 |
("instances"), |
| 66 |
[ |
| 67 |
pytest.param([{"name": "CORE-ISIS", "vrf": "PROD", "dataplane": "MPLS"}], id="invalid_vrf"), |
| 68 |
], |
| 69 |
) |
| 70 |
def test_invalid(self, instances: list[ISISInstance]) -> None: |
| 71 |
"""Test VerifyISISSegmentRoutingDataplane.Input invalid inputs.""" |
| 72 |
with pytest.raises(ValidationError): |
| 73 |
VerifyISISSegmentRoutingDataplane.Input(instances=instances) |
| 74 |
|
| 75 |
|
| 76 |
class TestTunnelPath: |
| 77 |
"""Test anta.input_models.routing.isis.TestTunnelPath.""" |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
@pytest.mark.parametrize( |
| 82 |
("nexthop", "type", "interface", "tunnel_id", "expected"), |
| 83 |
[ |
| 84 |
pytest.param("1.1.1.1", None, None, None, "Next-hop: 1.1.1.1", id="nexthop"), |
| 85 |
pytest.param(None, "ip", None, None, "Type: ip", id="type"), |
| 86 |
pytest.param(None, None, "Et1", None, "Interface: Ethernet1", id="interface"), |
| 87 |
pytest.param(None, None, None, "TI-LFA", "Tunnel ID: TI-LFA", id="tunnel_id"), |
| 88 |
pytest.param("1.1.1.1", "ip", "Et1", "TI-LFA", "Next-hop: 1.1.1.1 Type: ip Interface: Ethernet1 Tunnel ID: TI-LFA", id="all"), |
| 89 |
pytest.param(None, None, None, None, "", id="None"), |
| 90 |
], |
| 91 |
) |
| 92 |
def test_valid__str__( |
| 93 |
self, |
| 94 |
nexthop: IPv4Address | None, |
| 95 |
type: Literal["ip", "tunnel"] | None, |
| 96 |
interface: Interface | None, |
| 97 |
tunnel_id: Literal["TI-LFA", "ti-lfa", "unset"] | None, |
| 98 |
expected: str, |
| 99 |
) -> None: |
| 100 |
"""Test TunnelPath __str__.""" |
| 101 |
assert str(TunnelPath(nexthop=nexthop, type=type, interface=interface, tunnel_id=tunnel_id)) == expected |