Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of conflicting underlying types for VRF type #22

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/anycastd/_configuration/prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Literal, TypeAlias

from anycastd._configuration.sub import SubConfiguration
from anycastd.prefix import VRF


class PrefixConfiguration(SubConfiguration):
Expand All @@ -19,7 +20,7 @@ class FRRPrefixConfiguration(PrefixConfiguration):
"""

prefix: IPv4Network | IPv6Network
vrf: int | None = None
vrf: VRF = None
vtysh: Path = Path("/usr/bin/vtysh")


Expand Down
2 changes: 1 addition & 1 deletion src/anycastd/prefix/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from anycastd.prefix._frrouting.main import FRRoutingPrefix
from anycastd.prefix._main import Prefix
from anycastd.prefix._main import VRF, Prefix
4 changes: 2 additions & 2 deletions tests/configuration/test_sub_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
),
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -30,7 +30,7 @@ def example_networks(request) -> _IP_Prefix:
return request.getfixturevalue(request.param)


@pytest.fixture(params=[None, "vrf-func-test"])
def example_vrfs(request) -> _VRF:
@pytest.fixture(params=[None, "vrf-func-test", "47"])
def example_vrfs(request) -> VRF:
"""Parametrize tests with example VRFs."""
return request.param
15 changes: 8 additions & 7 deletions tests/prefix/frrouting/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand All @@ -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(
Expand All @@ -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(
Expand Down
Loading