| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
"""Tests for anta.input_models.routing.bgp.py.""" |
| 5 |
|
| 6 |
|
| 7 |
from __future__ import annotations |
| 8 |
|
| 9 |
from typing import TYPE_CHECKING, Any |
| 10 |
|
| 11 |
import pytest |
| 12 |
from pydantic import ValidationError |
| 13 |
|
| 14 |
from anta.input_models.routing.bgp import AddressFamilyConfig, BgpAddressFamily, BgpPeer, BgpRoute, RedistributedRouteConfig |
| 15 |
from anta.tests.routing.bgp import ( |
| 16 |
VerifyBGPExchangedRoutes, |
| 17 |
VerifyBGPNlriAcceptance, |
| 18 |
VerifyBGPPeerCount, |
| 19 |
VerifyBGPPeerGroup, |
| 20 |
VerifyBGPPeerMPCaps, |
| 21 |
VerifyBGPPeerRouteLimit, |
| 22 |
VerifyBGPPeerTtlMultiHops, |
| 23 |
VerifyBGPRouteECMP, |
| 24 |
VerifyBgpRouteMaps, |
| 25 |
VerifyBGPRoutePaths, |
| 26 |
VerifyBGPSpecificPeers, |
| 27 |
VerifyBGPTimers, |
| 28 |
) |
| 29 |
|
| 30 |
if TYPE_CHECKING: |
| 31 |
from ipaddress import IPv4Address, IPv6Address |
| 32 |
|
| 33 |
from anta.custom_types import Afi, Interface, RedistributedAfiSafi, RedistributedProtocol, Safi |
| 34 |
|
| 35 |
|
| 36 |
class TestBgpAddressFamily: |
| 37 |
"""Test anta.input_models.routing.bgp.BgpAddressFamily.""" |
| 38 |
|
| 39 |
@pytest.mark.parametrize( |
| 40 |
("afi", "safi", "vrf"), |
| 41 |
[ |
| 42 |
pytest.param("ipv4", "unicast", "MGMT", id="afi"), |
| 43 |
pytest.param("evpn", None, "default", id="safi"), |
| 44 |
pytest.param("ipv4", "unicast", "default", id="vrf"), |
| 45 |
], |
| 46 |
) |
| 47 |
def test_valid(self, afi: Afi, safi: Safi, vrf: str) -> None: |
| 48 |
"""Test BgpAddressFamily valid inputs.""" |
| 49 |
BgpAddressFamily(afi=afi, safi=safi, vrf=vrf) |
| 50 |
|
| 51 |
@pytest.mark.parametrize( |
| 52 |
("afi", "safi", "vrf"), |
| 53 |
[ |
| 54 |
pytest.param("ipv4", None, "default", id="afi"), |
| 55 |
pytest.param("evpn", "multicast", "default", id="safi"), |
| 56 |
pytest.param("evpn", None, "MGMT", id="vrf"), |
| 57 |
], |
| 58 |
) |
| 59 |
def test_invalid(self, afi: Afi, safi: Safi, vrf: str) -> None: |
| 60 |
"""Test BgpAddressFamily invalid inputs.""" |
| 61 |
with pytest.raises(ValidationError): |
| 62 |
BgpAddressFamily(afi=afi, safi=safi, vrf=vrf) |
| 63 |
|
| 64 |
|
| 65 |
class TestBgpPeer: |
| 66 |
"""Test anta.input_models.routing.bgp.BgpPeer.""" |
| 67 |
|
| 68 |
@pytest.mark.parametrize( |
| 69 |
("peer_address", "interface"), |
| 70 |
[ |
| 71 |
pytest.param("10.1.1.0", None, id="peer"), |
| 72 |
pytest.param(None, "Et1", id="interface"), |
| 73 |
], |
| 74 |
) |
| 75 |
def test_valid(self, peer_address: IPv4Address | IPv6Address, interface: Interface) -> None: |
| 76 |
"""Test BgpPeer valid inputs.""" |
| 77 |
BgpPeer(peer_address=peer_address, interface=interface) |
| 78 |
|
| 79 |
@pytest.mark.parametrize( |
| 80 |
("peer_address", "interface"), |
| 81 |
[ |
| 82 |
pytest.param("10.1.1.0", "Et1", id="both"), |
| 83 |
pytest.param(None, "None", id="both-None"), |
| 84 |
], |
| 85 |
) |
| 86 |
def test_invalid(self, peer_address: IPv4Address | IPv6Address, interface: Interface) -> None: |
| 87 |
"""Test BgpPeer invalid inputs.""" |
| 88 |
with pytest.raises(ValidationError): |
| 89 |
BgpPeer(peer_address=peer_address, interface=interface) |
| 90 |
|
| 91 |
|
| 92 |
class TestVerifyBGPPeerCountInput: |
| 93 |
"""Test anta.tests.routing.bgp.VerifyBGPPeerCount.Input.""" |
| 94 |
|
| 95 |
@pytest.mark.parametrize( |
| 96 |
("address_families"), |
| 97 |
[ |
| 98 |
pytest.param([{"afi": "evpn", "num_peers": 2}], id="valid"), |
| 99 |
], |
| 100 |
) |
| 101 |
def test_valid(self, address_families: list[BgpAddressFamily]) -> None: |
| 102 |
"""Test VerifyBGPPeerCount.Input valid inputs.""" |
| 103 |
VerifyBGPPeerCount.Input(address_families=address_families) |
| 104 |
|
| 105 |
@pytest.mark.parametrize( |
| 106 |
("address_families"), |
| 107 |
[ |
| 108 |
pytest.param([{"afi": "evpn", "num_peers": 0}], id="zero-peer"), |
| 109 |
pytest.param([{"afi": "evpn"}], id="None"), |
| 110 |
], |
| 111 |
) |
| 112 |
def test_invalid(self, address_families: list[BgpAddressFamily]) -> None: |
| 113 |
"""Test VerifyBGPPeerCount.Input invalid inputs.""" |
| 114 |
with pytest.raises(ValidationError): |
| 115 |
VerifyBGPPeerCount.Input(address_families=address_families) |
| 116 |
|
| 117 |
|
| 118 |
class TestVerifyBGPSpecificPeersInput: |
| 119 |
"""Test anta.tests.routing.bgp.VerifyBGPSpecificPeers.Input.""" |
| 120 |
|
| 121 |
@pytest.mark.parametrize( |
| 122 |
("address_families"), |
| 123 |
[ |
| 124 |
pytest.param([{"afi": "evpn", "peers": ["10.1.0.1", "10.1.0.2"]}], id="valid"), |
| 125 |
], |
| 126 |
) |
| 127 |
def test_valid(self, address_families: list[BgpAddressFamily]) -> None: |
| 128 |
"""Test VerifyBGPSpecificPeers.Input valid inputs.""" |
| 129 |
VerifyBGPSpecificPeers.Input(address_families=address_families) |
| 130 |
|
| 131 |
@pytest.mark.parametrize( |
| 132 |
("address_families"), |
| 133 |
[ |
| 134 |
pytest.param([{"afi": "evpn"}], id="None"), |
| 135 |
], |
| 136 |
) |
| 137 |
def test_invalid(self, address_families: list[BgpAddressFamily]) -> None: |
| 138 |
"""Test VerifyBGPSpecificPeers.Input invalid inputs.""" |
| 139 |
with pytest.raises(ValidationError): |
| 140 |
VerifyBGPSpecificPeers.Input(address_families=address_families) |
| 141 |
|
| 142 |
|
| 143 |
class TestVerifyBGPExchangedRoutesInput: |
| 144 |
"""Test anta.tests.routing.bgp.VerifyBGPExchangedRoutes.Input.""" |
| 145 |
|
| 146 |
@pytest.mark.parametrize( |
| 147 |
("bgp_peers"), |
| 148 |
[ |
| 149 |
pytest.param( |
| 150 |
[{"peer_address": "172.30.255.5", "vrf": "default", "advertised_routes": ["192.0.254.5/32"], "received_routes": ["192.0.255.4/32"]}], |
| 151 |
id="valid_both_received_advertised", |
| 152 |
), |
| 153 |
pytest.param([{"peer_address": "172.30.255.5", "vrf": "default", "advertised_routes": ["192.0.254.5/32"]}], id="valid_advertised_routes"), |
| 154 |
], |
| 155 |
) |
| 156 |
def test_valid(self, bgp_peers: list[BgpPeer]) -> None: |
| 157 |
"""Test VerifyBGPExchangedRoutes.Input valid inputs.""" |
| 158 |
VerifyBGPExchangedRoutes.Input(bgp_peers=bgp_peers) |
| 159 |
|
| 160 |
@pytest.mark.parametrize( |
| 161 |
("bgp_peers"), |
| 162 |
[ |
| 163 |
pytest.param([{"peer_address": "172.30.255.5", "vrf": "default"}], id="invalid"), |
| 164 |
], |
| 165 |
) |
| 166 |
def test_invalid(self, bgp_peers: list[BgpPeer]) -> None: |
| 167 |
"""Test VerifyBGPExchangedRoutes.Input invalid inputs.""" |
| 168 |
with pytest.raises(ValidationError): |
| 169 |
VerifyBGPExchangedRoutes.Input(bgp_peers=bgp_peers) |
| 170 |
|
| 171 |
|
| 172 |
class TestVerifyBGPPeerMPCapsInput: |
| 173 |
"""Test anta.tests.routing.bgp.VerifyBGPPeerMPCaps.Input.""" |
| 174 |
|
| 175 |
@pytest.mark.parametrize( |
| 176 |
("bgp_peers"), |
| 177 |
[ |
| 178 |
pytest.param([{"peer_address": "172.30.255.5", "vrf": "default", "capabilities": ["ipv4Unicast"]}], id="valid"), |
| 179 |
], |
| 180 |
) |
| 181 |
def test_valid(self, bgp_peers: list[BgpPeer]) -> None: |
| 182 |
"""Test VerifyBGPPeerMPCaps.Input valid inputs.""" |
| 183 |
VerifyBGPPeerMPCaps.Input(bgp_peers=bgp_peers) |
| 184 |
|
| 185 |
@pytest.mark.parametrize( |
| 186 |
("bgp_peers"), |
| 187 |
[ |
| 188 |
pytest.param([{"peer_address": "172.30.255.5", "vrf": "default"}], id="invalid"), |
| 189 |
], |
| 190 |
) |
| 191 |
def test_invalid(self, bgp_peers: list[BgpPeer]) -> None: |
| 192 |
"""Test VerifyBGPPeerMPCaps.Input invalid inputs.""" |
| 193 |
with pytest.raises(ValidationError): |
| 194 |
VerifyBGPPeerMPCaps.Input(bgp_peers=bgp_peers) |
| 195 |
|
| 196 |
|
| 197 |
class TestVerifyBGPTimersInput: |
| 198 |
"""Test anta.tests.routing.bgp.VerifyBGPTimers.Input.""" |
| 199 |
|
| 200 |
@pytest.mark.parametrize( |
| 201 |
("bgp_peers"), |
| 202 |
[ |
| 203 |
pytest.param([{"peer_address": "172.30.255.5", "vrf": "default", "hold_time": 180, "keep_alive_time": 60}], id="valid"), |
| 204 |
], |
| 205 |
) |
| 206 |
def test_valid(self, bgp_peers: list[BgpPeer]) -> None: |
| 207 |
"""Test VerifyBGPTimers.Input valid inputs.""" |
| 208 |
VerifyBGPTimers.Input(bgp_peers=bgp_peers) |
| 209 |
|
| 210 |
@pytest.mark.parametrize( |
| 211 |
("bgp_peers"), |
| 212 |
[ |
| 213 |
pytest.param([{"peer_address": "172.30.255.5", "vrf": "default"}], id="invalid"), |
| 214 |
pytest.param([{"peer_address": "172.30.255.5", "vrf": "default", "hold_time": 180}], id="invalid_keep_alive"), |
| 215 |
pytest.param([{"peer_address": "172.30.255.5", "vrf": "default", "keep_alive_time": 180}], id="invalid_hold_time"), |
| 216 |
], |
| 217 |
) |
| 218 |
def test_invalid(self, bgp_peers: list[BgpPeer]) -> None: |
| 219 |
"""Test VerifyBGPTimers.Input invalid inputs.""" |
| 220 |
with pytest.raises(ValidationError): |
| 221 |
VerifyBGPTimers.Input(bgp_peers=bgp_peers) |
| 222 |
|
| 223 |
|
| 224 |
class TestVerifyBgpRouteMapsInput: |
| 225 |
"""Test anta.tests.routing.bgp.VerifyBgpRouteMaps.Input.""" |
| 226 |
|
| 227 |
@pytest.mark.parametrize( |
| 228 |
("bgp_peers"), |
| 229 |
[ |
| 230 |
pytest.param([{"peer_address": "172.30.255.5", "vrf": "default", "inbound_route_map": "Test", "outbound_route_map": "Test"}], id="valid"), |
| 231 |
], |
| 232 |
) |
| 233 |
def test_valid(self, bgp_peers: list[BgpPeer]) -> None: |
| 234 |
"""Test VerifyBgpRouteMaps.Input valid inputs.""" |
| 235 |
VerifyBgpRouteMaps.Input(bgp_peers=bgp_peers) |
| 236 |
|
| 237 |
@pytest.mark.parametrize( |
| 238 |
("bgp_peers"), |
| 239 |
[ |
| 240 |
pytest.param([{"peer_address": "172.30.255.5", "vrf": "default"}], id="invalid"), |
| 241 |
], |
| 242 |
) |
| 243 |
def test_invalid(self, bgp_peers: list[BgpPeer]) -> None: |
| 244 |
"""Test VerifyBgpRouteMaps.Input invalid inputs.""" |
| 245 |
with pytest.raises(ValidationError): |
| 246 |
VerifyBgpRouteMaps.Input(bgp_peers=bgp_peers) |
| 247 |
|
| 248 |
|
| 249 |
class TestVerifyBGPPeerRouteLimitInput: |
| 250 |
"""Test anta.tests.routing.bgp.VerifyBGPPeerRouteLimit.Input.""" |
| 251 |
|
| 252 |
@pytest.mark.parametrize( |
| 253 |
("bgp_peers"), |
| 254 |
[ |
| 255 |
pytest.param([{"peer_address": "172.30.255.5", "vrf": "default", "maximum_routes": 10000}], id="valid"), |
| 256 |
], |
| 257 |
) |
| 258 |
def test_valid(self, bgp_peers: list[BgpPeer]) -> None: |
| 259 |
"""Test VerifyBGPPeerRouteLimit.Input valid inputs.""" |
| 260 |
VerifyBGPPeerRouteLimit.Input(bgp_peers=bgp_peers) |
| 261 |
|
| 262 |
@pytest.mark.parametrize( |
| 263 |
("bgp_peers"), |
| 264 |
[ |
| 265 |
pytest.param([{"peer_address": "172.30.255.5", "vrf": "default"}], id="invalid"), |
| 266 |
], |
| 267 |
) |
| 268 |
def test_invalid(self, bgp_peers: list[BgpPeer]) -> None: |
| 269 |
"""Test VerifyBGPPeerRouteLimit.Input invalid inputs.""" |
| 270 |
with pytest.raises(ValidationError): |
| 271 |
VerifyBGPPeerRouteLimit.Input(bgp_peers=bgp_peers) |
| 272 |
|
| 273 |
|
| 274 |
class TestVerifyBGPPeerGroupInput: |
| 275 |
"""Test anta.tests.routing.bgp.VerifyBGPPeerGroup.Input.""" |
| 276 |
|
| 277 |
@pytest.mark.parametrize( |
| 278 |
("bgp_peers"), |
| 279 |
[ |
| 280 |
pytest.param([{"peer_address": "172.30.255.5", "vrf": "default", "peer_group": "IPv4-UNDERLAY-PEERS"}], id="valid"), |
| 281 |
], |
| 282 |
) |
| 283 |
def test_valid(self, bgp_peers: list[BgpPeer]) -> None: |
| 284 |
"""Test VerifyBGPPeerGroup.Input valid inputs.""" |
| 285 |
VerifyBGPPeerGroup.Input(bgp_peers=bgp_peers) |
| 286 |
|
| 287 |
@pytest.mark.parametrize( |
| 288 |
("bgp_peers"), |
| 289 |
[ |
| 290 |
pytest.param([{"peer_address": "172.30.255.5", "vrf": "default"}], id="invalid"), |
| 291 |
], |
| 292 |
) |
| 293 |
def test_invalid(self, bgp_peers: list[BgpPeer]) -> None: |
| 294 |
"""Test VerifyBGPPeerGroup.Input invalid inputs.""" |
| 295 |
with pytest.raises(ValidationError): |
| 296 |
VerifyBGPPeerGroup.Input(bgp_peers=bgp_peers) |
| 297 |
|
| 298 |
|
| 299 |
class TestVerifyBGPNlriAcceptanceInput: |
| 300 |
"""Test anta.tests.routing.bgp.VerifyBGPNlriAcceptance.Input.""" |
| 301 |
|
| 302 |
@pytest.mark.parametrize( |
| 303 |
("bgp_peers"), |
| 304 |
[ |
| 305 |
pytest.param([{"peer_address": "172.30.255.5", "vrf": "default", "capabilities": ["ipv4Unicast"]}], id="valid"), |
| 306 |
], |
| 307 |
) |
| 308 |
def test_valid(self, bgp_peers: list[BgpPeer]) -> None: |
| 309 |
"""Test VerifyBGPNlriAcceptance.Input valid inputs.""" |
| 310 |
VerifyBGPNlriAcceptance.Input(bgp_peers=bgp_peers) |
| 311 |
|
| 312 |
@pytest.mark.parametrize( |
| 313 |
("bgp_peers"), |
| 314 |
[ |
| 315 |
pytest.param([{"peer_address": "172.30.255.5", "vrf": "default"}], id="invalid"), |
| 316 |
], |
| 317 |
) |
| 318 |
def test_invalid(self, bgp_peers: list[BgpPeer]) -> None: |
| 319 |
"""Test VerifyBGPNlriAcceptance.Input invalid inputs.""" |
| 320 |
with pytest.raises(ValidationError): |
| 321 |
VerifyBGPNlriAcceptance.Input(bgp_peers=bgp_peers) |
| 322 |
|
| 323 |
|
| 324 |
class TestVerifyBGPRouteECMPInput: |
| 325 |
"""Test anta.tests.routing.bgp.VerifyBGPRouteECMP.Input.""" |
| 326 |
|
| 327 |
@pytest.mark.parametrize( |
| 328 |
("bgp_routes"), |
| 329 |
[ |
| 330 |
pytest.param([{"prefix": "10.100.0.128/31", "vrf": "default", "ecmp_count": 2}], id="valid"), |
| 331 |
], |
| 332 |
) |
| 333 |
def test_valid(self, bgp_routes: list[BgpRoute]) -> None: |
| 334 |
"""Test VerifyBGPRouteECMP.Input valid inputs.""" |
| 335 |
VerifyBGPRouteECMP.Input(route_entries=bgp_routes) |
| 336 |
|
| 337 |
@pytest.mark.parametrize( |
| 338 |
("bgp_routes"), |
| 339 |
[ |
| 340 |
pytest.param([{"prefix": "10.100.0.128/31", "vrf": "default"}], id="invalid"), |
| 341 |
], |
| 342 |
) |
| 343 |
def test_invalid(self, bgp_routes: list[BgpRoute]) -> None: |
| 344 |
"""Test VerifyBGPRouteECMP.Input invalid inputs.""" |
| 345 |
with pytest.raises(ValidationError): |
| 346 |
VerifyBGPRouteECMP.Input(route_entries=bgp_routes) |
| 347 |
|
| 348 |
|
| 349 |
class TestVerifyBGPRoutePathsInput: |
| 350 |
"""Test anta.tests.routing.bgp.VerifyBGPRoutePaths.Input.""" |
| 351 |
|
| 352 |
@pytest.mark.parametrize( |
| 353 |
("route_entries"), |
| 354 |
[ |
| 355 |
pytest.param( |
| 356 |
[ |
| 357 |
{ |
| 358 |
"prefix": "10.100.0.128/31", |
| 359 |
"vrf": "default", |
| 360 |
"paths": [{"nexthop": "10.100.0.10", "origin": "Igp"}, {"nexthop": "10.100.4.5", "origin": "Incomplete"}], |
| 361 |
} |
| 362 |
], |
| 363 |
id="valid", |
| 364 |
), |
| 365 |
], |
| 366 |
) |
| 367 |
def test_valid(self, route_entries: list[BgpRoute]) -> None: |
| 368 |
"""Test VerifyBGPRoutePaths.Input valid inputs.""" |
| 369 |
VerifyBGPRoutePaths.Input(route_entries=route_entries) |
| 370 |
|
| 371 |
@pytest.mark.parametrize( |
| 372 |
("route_entries"), |
| 373 |
[ |
| 374 |
pytest.param([{"prefix": "10.100.0.128/31", "vrf": "default"}], id="invalid"), |
| 375 |
], |
| 376 |
) |
| 377 |
def test_invalid(self, route_entries: list[BgpRoute]) -> None: |
| 378 |
"""Test VerifyBGPRoutePaths.Input invalid inputs.""" |
| 379 |
with pytest.raises(ValidationError): |
| 380 |
VerifyBGPRoutePaths.Input(route_entries=route_entries) |
| 381 |
|
| 382 |
|
| 383 |
class TestVerifyBGPRedistributedRoute: |
| 384 |
"""Test anta.input_models.routing.bgp.RedistributedRouteConfig.""" |
| 385 |
|
| 386 |
@pytest.mark.parametrize( |
| 387 |
("proto", "include_leaked"), |
| 388 |
[ |
| 389 |
pytest.param("Connected", True, id="proto-valid"), |
| 390 |
pytest.param("Static", False, id="proto-valid-leaked-false"), |
| 391 |
pytest.param("User", False, id="proto-User"), |
| 392 |
], |
| 393 |
) |
| 394 |
def test_validate_inputs(self, proto: RedistributedProtocol, include_leaked: bool) -> None: |
| 395 |
"""Test RedistributedRouteConfig valid inputs.""" |
| 396 |
RedistributedRouteConfig(proto=proto, include_leaked=include_leaked) |
| 397 |
|
| 398 |
@pytest.mark.parametrize( |
| 399 |
("proto", "include_leaked"), |
| 400 |
[ |
| 401 |
pytest.param("Dynamic", True, id="proto-valid"), |
| 402 |
pytest.param("User", True, id="proto-valid-leaked-false"), |
| 403 |
], |
| 404 |
) |
| 405 |
def test_invalid(self, proto: RedistributedProtocol, include_leaked: bool) -> None: |
| 406 |
"""Test RedistributedRouteConfig invalid inputs.""" |
| 407 |
with pytest.raises(ValidationError): |
| 408 |
RedistributedRouteConfig(proto=proto, include_leaked=include_leaked) |
| 409 |
|
| 410 |
@pytest.mark.parametrize( |
| 411 |
("proto", "include_leaked", "route_map", "expected"), |
| 412 |
[ |
| 413 |
pytest.param("Connected", True, "RM-CONN-2-BGP", "Proto: Connected, Include Leaked: True, Route Map: RM-CONN-2-BGP", id="check-all-params"), |
| 414 |
pytest.param("Static", False, None, "Proto: Static", id="check-proto-include_leaked-false"), |
| 415 |
pytest.param("User", False, "RM-CONN-2-BGP", "Proto: EOS SDK, Route Map: RM-CONN-2-BGP", id="check-proto-route_map"), |
| 416 |
pytest.param("Dynamic", False, None, "Proto: Dynamic", id="check-proto-only"), |
| 417 |
], |
| 418 |
) |
| 419 |
def test_valid_str(self, proto: RedistributedProtocol, include_leaked: bool, route_map: str | None, expected: str) -> None: |
| 420 |
"""Test RedistributedRouteConfig __str__.""" |
| 421 |
assert str(RedistributedRouteConfig(proto=proto, include_leaked=include_leaked, route_map=route_map)) == expected |
| 422 |
|
| 423 |
|
| 424 |
class TestVerifyBGPAddressFamilyConfig: |
| 425 |
"""Test anta.input_models.routing.bgp.AddressFamilyConfig.""" |
| 426 |
|
| 427 |
@pytest.mark.parametrize( |
| 428 |
("afi_safi", "redistributed_routes"), |
| 429 |
[ |
| 430 |
pytest.param("ipv4Unicast", [{"proto": "OSPFv3 External", "include_leaked": True, "route_map": "RM-CONN-2-BGP"}], id="afisafi-ipv4-unicast"), |
| 431 |
pytest.param("ipv6 Multicast", [{"proto": "OSPF Internal", "include_leaked": True, "route_map": "RM-CONN-2-BGP"}], id="afisafi-ipv6-multicast"), |
| 432 |
pytest.param("ipv4-Multicast", [{"proto": "IS-IS", "include_leaked": False, "route_map": "RM-CONN-2-BGP"}], id="afisafi-ipv4-multicast"), |
| 433 |
pytest.param("ipv6_Unicast", [{"proto": "AttachedHost", "route_map": "RM-CONN-2-BGP"}], id="afisafi-ipv6-unicast"), |
| 434 |
], |
| 435 |
) |
| 436 |
def test_valid(self, afi_safi: RedistributedAfiSafi, redistributed_routes: list[Any]) -> None: |
| 437 |
"""Test AddressFamilyConfig valid inputs.""" |
| 438 |
AddressFamilyConfig(afi_safi=afi_safi, redistributed_routes=redistributed_routes) |
| 439 |
|
| 440 |
@pytest.mark.parametrize( |
| 441 |
("afi_safi", "redistributed_routes"), |
| 442 |
[ |
| 443 |
pytest.param("evpn", [{"proto": "OSPFv3 Nssa-External", "include_leaked": True, "route_map": "RM-CONN-2-BGP"}], id="invalid-address-family"), |
| 444 |
pytest.param("ipv6 sr-te", [{"proto": "RIP", "route_map": "RM-CONN-2-BGP"}], id="ipv6-invalid-address-family"), |
| 445 |
pytest.param("iipv6_Unicast", [{"proto": "Bgp", "include_leaked": True, "route_map": "RM-CONN-2-BGP"}], id="ipv6-unicast-invalid-address-family"), |
| 446 |
pytest.param("ipv6_Unicastt", [{"proto": "Static", "include_leaked": True, "route_map": "RM-CONN-2-BGP"}], id="ipv6-unicast-invalid-address-family"), |
| 447 |
], |
| 448 |
) |
| 449 |
def test_invalid(self, afi_safi: RedistributedAfiSafi, redistributed_routes: list[Any]) -> None: |
| 450 |
"""Test AddressFamilyConfig invalid inputs.""" |
| 451 |
with pytest.raises(ValidationError): |
| 452 |
AddressFamilyConfig(afi_safi=afi_safi, redistributed_routes=redistributed_routes) |
| 453 |
|
| 454 |
@pytest.mark.parametrize( |
| 455 |
("afi_safi", "redistributed_routes"), |
| 456 |
[ |
| 457 |
pytest.param("ipv4Unicast", [{"proto": "OSPF External", "include_leaked": True, "route_map": "RM-CONN-2-BGP"}], id="v4u-proto-ospf-external"), |
| 458 |
pytest.param("ipv4 Unicast", [{"proto": "OSPF Internal", "include_leaked": True, "route_map": "RM-CONN-2-BGP"}], id="v4u-proto-ospf-internal"), |
| 459 |
pytest.param("ipv4-Unicast", [{"proto": "OSPF Nssa-External", "include_leaked": True, "route_map": "RM-CONN-2-BGP"}], id="v4u-proto-ospf-nssa-external"), |
| 460 |
pytest.param("ipv4_Unicast", [{"proto": "OSPFv3 External", "include_leaked": True, "route_map": "RM-CONN-2-BGP"}], id="v4u-proto-ospfv3-external"), |
| 461 |
pytest.param("Ipv4Unicast", [{"proto": "OSPFv3 Internal", "include_leaked": True, "route_map": "RM-CONN-2-BGP"}], id="v4u-proto-ospfv3-internal"), |
| 462 |
pytest.param( |
| 463 |
"ipv4Unicast", [{"proto": "OSPFv3 Nssa-External", "include_leaked": True, "route_map": "RM-CONN-2-BGP"}], id="v4u-proto-ospfv3-nssa-external" |
| 464 |
), |
| 465 |
pytest.param("ipv4unicast", [{"proto": "AttachedHost", "include_leaked": False, "route_map": "RM-CONN-2-BGP"}], id="v4u-proto-attached-host"), |
| 466 |
pytest.param("IPv4UNiCast", [{"proto": "RIP", "include_leaked": False, "route_map": "RM-CONN-2-BGP"}], id="v4u-proto-rip"), |
| 467 |
pytest.param("IPv4UnicasT", [{"proto": "Bgp", "include_leaked": True, "route_map": "RM-CONN-2-BGP"}], id="v4u-proto-bgp"), |
| 468 |
pytest.param("ipv6_Multicast", [{"proto": "Static", "include_leaked": True, "route_map": "RM-CONN-2-BGP"}], id="v6m-proto-static"), |
| 469 |
pytest.param("ipv6 Multicast", [{"proto": "OSPF Internal", "include_leaked": True, "route_map": "RM-CONN-2-BGP"}], id="v6m-proto-ospf-internal"), |
| 470 |
pytest.param("ipv6-Multicast", [{"proto": "Connected", "include_leaked": True, "route_map": "RM-CONN-2-BGP"}], id="v6m-proto-connected"), |
| 471 |
pytest.param("ipv4-Multicast", [{"proto": "IS-IS", "include_leaked": False, "route_map": "RM-CONN-2-BGP"}], id="v4m-proto-isis"), |
| 472 |
pytest.param("ipv4Multicast", [{"proto": "Connected", "include_leaked": True, "route_map": "RM-CONN-2-BGP"}], id="v4m-proto-connected"), |
| 473 |
pytest.param("ipv4_Multicast", [{"proto": "AttachedHost", "include_leaked": False, "route_map": "RM-CONN-2-BGP"}], id="v4m-proto-attached-host"), |
| 474 |
pytest.param("ipv6_Unicast", [{"proto": "AttachedHost", "route_map": "RM-CONN-2-BGP"}], id="v6u-proto-attached-host"), |
| 475 |
pytest.param("ipv6unicast", [{"proto": "DHCP", "route_map": "RM-CONN-2-BGP"}], id="v6u-proto-dhcp"), |
| 476 |
pytest.param("ipv6 Unicast", [{"proto": "Dynamic", "include_leaked": False, "route_map": "RM-CONN-2-BGP"}], id="v6u-proto-dynamic"), |
| 477 |
], |
| 478 |
) |
| 479 |
def test_validate_afi_safi_supported_routes(self, afi_safi: RedistributedAfiSafi, redistributed_routes: list[Any]) -> None: |
| 480 |
"""Test AddressFamilyConfig validate afi-safi supported routes.""" |
| 481 |
AddressFamilyConfig(afi_safi=afi_safi, redistributed_routes=redistributed_routes) |
| 482 |
|
| 483 |
@pytest.mark.parametrize( |
| 484 |
("afi_safi", "redistributed_routes"), |
| 485 |
[ |
| 486 |
pytest.param("ipv6_Unicast", [{"proto": "RIP", "route_map": "RM-CONN-2-BGP"}], id="invalid-proto-ipv6-unicast-rip"), |
| 487 |
pytest.param("ipv6-Unicast", [{"proto": "OSPF Internal", "route_map": "RM-CONN-2-BGP"}], id="invalid-proto-ipv6-unicast-ospf-internal"), |
| 488 |
pytest.param("ipv4Unicast", [{"proto": "DHCP", "route_map": "RM-CONN-2-BGP"}], id="invalid-proto-ipv4-unicast-dhcp"), |
| 489 |
pytest.param("ipv4-Multicast", [{"proto": "Bgp", "route_map": "RM-CONN-2-BGP"}], id="invalid-proto-ipv4-multicast-bgp"), |
| 490 |
pytest.param("ipv4-Multicast", [{"proto": "RIP", "route_map": "RM-CONN-2-BGP"}], id="invalid-proto-ipv4-multicast-rip"), |
| 491 |
pytest.param("ipv6-Multicast", [{"proto": "Dynamic", "route_map": "RM-CONN-2-BGP"}], id="invalid-proto-ipv4-multicast-dynamic"), |
| 492 |
pytest.param("ipv6-Multicast", [{"proto": "AttachedHost", "route_map": "RM-CONN-2-BGP"}], id="invalid-proto-ipv6-multicast-attached-host"), |
| 493 |
], |
| 494 |
) |
| 495 |
def test_invalid_afi_safi_supported_routes(self, afi_safi: RedistributedAfiSafi, redistributed_routes: list[Any]) -> None: |
| 496 |
"""Test AddressFamilyConfig invalid afi-safi supported routes.""" |
| 497 |
with pytest.raises(ValidationError): |
| 498 |
AddressFamilyConfig(afi_safi=afi_safi, redistributed_routes=redistributed_routes) |
| 499 |
|
| 500 |
@pytest.mark.parametrize( |
| 501 |
("afi_safi", "redistributed_routes", "expected"), |
| 502 |
[ |
| 503 |
pytest.param( |
| 504 |
"v4u", [{"proto": "OSPFv3 Nssa-External", "include_leaked": True, "route_map": "RM-CONN-2-BGP"}], "AFI-SAFI: IPv4 Unicast", id="valid-ipv4-unicast" |
| 505 |
), |
| 506 |
pytest.param("v4m", [{"proto": "IS-IS", "route_map": "RM-CONN-2-BGP"}], "AFI-SAFI: IPv4 Multicast", id="valid-ipv4-multicast"), |
| 507 |
pytest.param("v6u", [{"proto": "Bgp", "include_leaked": True, "route_map": "RM-CONN-2-BGP"}], "AFI-SAFI: IPv6 Unicast", id="valid-ipv6-unicast"), |
| 508 |
pytest.param("v6m", [{"proto": "Static", "include_leaked": True, "route_map": "RM-CONN-2-BGP"}], "AFI-SAFI: IPv6 Multicast", id="valid-ipv6-multicast"), |
| 509 |
], |
| 510 |
) |
| 511 |
def test_valid_str(self, afi_safi: RedistributedAfiSafi, redistributed_routes: list[Any], expected: str) -> None: |
| 512 |
"""Test AddressFamilyConfig __str__.""" |
| 513 |
assert str(AddressFamilyConfig(afi_safi=afi_safi, redistributed_routes=redistributed_routes)) == expected |
| 514 |
|
| 515 |
|
| 516 |
class TestVerifyBGPPeerTtlMultiHopsInput: |
| 517 |
"""Test anta.tests.routing.bgp.VerifyBGPPeerTtlMultiHops.Input.""" |
| 518 |
|
| 519 |
@pytest.mark.parametrize( |
| 520 |
("bgp_peers"), |
| 521 |
[ |
| 522 |
pytest.param([{"peer_address": "172.30.255.5", "vrf": "default", "ttl": 3, "max_ttl_hops": 3}], id="valid"), |
| 523 |
], |
| 524 |
) |
| 525 |
def test_valid(self, bgp_peers: list[BgpPeer]) -> None: |
| 526 |
"""Test VerifyBGPPeerTtlMultiHops.Input valid inputs.""" |
| 527 |
VerifyBGPPeerTtlMultiHops.Input(bgp_peers=bgp_peers) |
| 528 |
|
| 529 |
@pytest.mark.parametrize( |
| 530 |
("bgp_peers"), |
| 531 |
[ |
| 532 |
pytest.param([{"peer_address": "172.30.255.5", "vrf": "default", "ttl": None, "max_ttl_hops": 3}], id="invalid-ttl-time"), |
| 533 |
pytest.param([{"peer_address": "172.30.255.6", "vrf": "default", "ttl": 3, "max_ttl_hops": None}], id="invalid-max-ttl-hops"), |
| 534 |
], |
| 535 |
) |
| 536 |
def test_invalid(self, bgp_peers: list[BgpPeer]) -> None: |
| 537 |
"""Test VerifyBGPPeerTtlMultiHops.Input invalid inputs.""" |
| 538 |
with pytest.raises(ValidationError): |
| 539 |
VerifyBGPPeerTtlMultiHops.Input(bgp_peers=bgp_peers) |