From 1f5c5e7f9a7d9ff31d4c2b87ddde6dac05c7bd8c Mon Sep 17 00:00:00 2001 From: Marvin Vogt Date: Tue, 5 Dec 2023 15:05:38 +0000 Subject: [PATCH 1/3] Export `VRF` from prefix module --- src/anycastd/prefix/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/anycastd/prefix/__init__.py b/src/anycastd/prefix/__init__.py index 16c812f..43a401b 100644 --- a/src/anycastd/prefix/__init__.py +++ b/src/anycastd/prefix/__init__.py @@ -1,2 +1,2 @@ from anycastd.prefix._frrouting.main import FRRoutingPrefix -from anycastd.prefix._main import Prefix +from anycastd.prefix._main import VRF, Prefix From ed60bef8e3fd0d43018ed63be3fe1cd96f6c6ed3 Mon Sep 17 00:00:00 2001 From: Marvin Vogt Date: Tue, 5 Dec 2023 15:16:47 +0000 Subject: [PATCH 2/3] Use the same underlying `VRF` type throughout codebase --- src/anycastd/_configuration/prefix.py | 3 ++- tests/configuration/test_sub_configuration.py | 4 ++-- tests/conftest.py | 4 ++-- tests/prefix/frrouting/conftest.py | 15 ++++++++------- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/anycastd/_configuration/prefix.py b/src/anycastd/_configuration/prefix.py index 36f6cf7..2437d8d 100644 --- a/src/anycastd/_configuration/prefix.py +++ b/src/anycastd/_configuration/prefix.py @@ -3,6 +3,7 @@ from typing import Literal, TypeAlias from anycastd._configuration.sub import SubConfiguration +from anycastd.prefix import VRF class PrefixConfiguration(SubConfiguration): @@ -19,7 +20,7 @@ class FRRPrefixConfiguration(PrefixConfiguration): """ prefix: IPv4Network | IPv6Network - vrf: int | None = None + vrf: VRF = None vtysh: Path = Path("/usr/bin/vtysh") diff --git a/tests/configuration/test_sub_configuration.py b/tests/configuration/test_sub_configuration.py index bdb194a..bee841d 100644 --- a/tests/configuration/test_sub_configuration.py +++ b/tests/configuration/test_sub_configuration.py @@ -56,12 +56,12 @@ def test_from_simplified_format(config: str, expected: SubConfiguration): ( { "prefix": "2001:db8::/32", - "vrf": 42, + "vrf": "42", "vtysh": "/vtysh", }, FRRPrefixConfiguration( prefix=IPv6Network("2001:db8::/32"), - vrf=42, + vrf="42", vtysh=Path("/vtysh"), ), ), diff --git a/tests/conftest.py b/tests/conftest.py index 71acc07..18bdc77 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,9 +2,9 @@ from typing import TypeAlias import pytest +from anycastd.prefix import VRF _IP_Prefix: TypeAlias = IPv4Network | IPv6Network -_VRF: TypeAlias = str | None @pytest.fixture(scope="session") @@ -31,6 +31,6 @@ def example_networks(request) -> _IP_Prefix: @pytest.fixture(params=[None, "vrf-func-test"]) -def example_vrfs(request) -> _VRF: +def example_vrfs(request) -> VRF: """Parametrize tests with example VRFs.""" return request.param diff --git a/tests/prefix/frrouting/conftest.py b/tests/prefix/frrouting/conftest.py index f3e02bb..9e7d3ce 100644 --- a/tests/prefix/frrouting/conftest.py +++ b/tests/prefix/frrouting/conftest.py @@ -7,8 +7,9 @@ from pathlib import Path import pytest +from anycastd.prefix import VRF -from tests.conftest import _VRF, _IP_Prefix +from tests.conftest import _IP_Prefix def get_afi(prefix: _IP_Prefix) -> str: @@ -125,10 +126,10 @@ def vtysh(frr_container) -> Vtysh: @pytest.fixture -def bgp_prefix_configured() -> Callable[[_IP_Prefix, Vtysh, _VRF], bool]: +def bgp_prefix_configured() -> Callable[[_IP_Prefix, Vtysh, VRF], bool]: """A callable that can be used to check if a BGP prefix is configured.""" - def _(prefix: _IP_Prefix, vtysh: Vtysh, vrf: _VRF = None) -> bool: + def _(prefix: _IP_Prefix, vtysh: Vtysh, vrf: VRF = None) -> bool: family = get_afi(prefix) cmd = ( f"show ip bgp vrf {vrf} {family} unicast {prefix} json" @@ -151,10 +152,10 @@ def _(prefix: _IP_Prefix, vtysh: Vtysh, vrf: _VRF = None) -> bool: @pytest.fixture -def add_bgp_prefix() -> Callable[[_IP_Prefix, int, Vtysh, _VRF], None]: +def add_bgp_prefix() -> Callable[[_IP_Prefix, int, Vtysh, VRF], None]: """A callable that can be used to add a BGP prefix.""" - def _(prefix: _IP_Prefix, asn: int, vtysh: Vtysh, vrf: _VRF = None) -> None: + def _(prefix: _IP_Prefix, asn: int, vtysh: Vtysh, vrf: VRF = None) -> None: """Add a network to the BGP configuration using vtysh.""" family = get_afi(prefix) vtysh( @@ -170,10 +171,10 @@ def _(prefix: _IP_Prefix, asn: int, vtysh: Vtysh, vrf: _VRF = None) -> None: @pytest.fixture -def remove_bgp_prefix() -> Callable[[_IP_Prefix, int, Vtysh, _VRF], None]: +def remove_bgp_prefix() -> Callable[[_IP_Prefix, int, Vtysh, VRF], None]: """A callable that can be used to remove a BGP prefix.""" - def _(prefix: _IP_Prefix, asn: int, vtysh: Vtysh, vrf: _VRF = None) -> None: + def _(prefix: _IP_Prefix, asn: int, vtysh: Vtysh, vrf: VRF = None) -> None: """Remove a network from the BGP configuration using vtysh.""" family = get_afi(prefix) vtysh( From 022709a0199aa86cfec04be91464174dd9d66f88 Mon Sep 17 00:00:00 2001 From: Marvin Vogt Date: Tue, 5 Dec 2023 15:17:56 +0000 Subject: [PATCH 3/3] Add vrf number to `example_vrfs` fixture --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 18bdc77..f4f9b08 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -30,7 +30,7 @@ def example_networks(request) -> _IP_Prefix: return request.getfixturevalue(request.param) -@pytest.fixture(params=[None, "vrf-func-test"]) +@pytest.fixture(params=[None, "vrf-func-test", "47"]) def example_vrfs(request) -> VRF: """Parametrize tests with example VRFs.""" return request.param