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(anta.tests): Second round of cleaning up BGP tests module #914

Merged
merged 26 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f8f2259
fix(anta.tests): First round of cleaning up BGP tests module
carl-baillargeon Oct 17, 2024
1b31f40
Added queues knob
carl-baillargeon Oct 24, 2024
a4dd185
Update unit tests for VerifyBGPPeerCount
carl-baillargeon Oct 25, 2024
bee1462
Updated unit tests
Oct 29, 2024
1a24678
Added unit tests for helper function, updated docstrings
Oct 30, 2024
fef7810
Updated unit tests for _check_bgp_neighbor_capability
Oct 30, 2024
de277c7
Resolved conflicts and updated the space after : in failure msgs
Nov 5, 2024
01170cd
fix(anta.tests): Refactor input subclasses of BGP tests
carl-baillargeon Nov 6, 2024
f7f0950
Updated test VerifyBGPPeerDropStats, VerifyBGPPeerUpdateErrors, Verif…
Nov 11, 2024
d7e7486
Updated unit tests
Nov 13, 2024
1dcdf57
Fix the CI failure
Nov 13, 2024
f1387c8
Fix the unit test afte merge conflicts
vitthalmagadum Nov 15, 2024
ecf9fa1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 15, 2024
4ddb290
Addressed review comments: updated failure msgs
vitthalmagadum Nov 19, 2024
1ed7934
Addressed review comments: updated ci failure
vitthalmagadum Nov 28, 2024
4a801c5
Updated unit tests for input models
vitthalmagadum Nov 28, 2024
c62cfd8
autogenerated test.yml
vitthalmagadum Dec 3, 2024
9a9a22f
Merge branch 'main' into fix/bgp_modules_v2
gmuloc Dec 4, 2024
9333519
Update after rebase
carl-baillargeon Dec 23, 2024
34a4053
Fix CI
carl-baillargeon Dec 23, 2024
9d547a5
Merge branch 'main' into fix/bgp_modules_v2
gmuloc Dec 23, 2024
12615e4
Merge branch 'main' into fix/bgp_modules_v2
gmuloc Dec 24, 2024
7716349
Update anta/input_models/routing/bgp.py
gmuloc Dec 24, 2024
7cfb7d0
Update anta/tests/routing/bgp.py
gmuloc Dec 24, 2024
59cfe5e
Apply suggestions from code review
carl-baillargeon Dec 24, 2024
a61274d
Merge branch 'main' into fix/bgp_modules_v2
gmuloc Dec 24, 2024
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
87 changes: 83 additions & 4 deletions anta/input_models/routing/bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

from __future__ import annotations

from ipaddress import IPv4Address, IPv6Address
from ipaddress import IPv4Address, IPv4Network, IPv6Address
from typing import TYPE_CHECKING, Any
from warnings import warn

from pydantic import BaseModel, ConfigDict, PositiveInt, model_validator
from pydantic import BaseModel, ConfigDict, Field, PositiveInt, model_validator
from pydantic_extra_types.mac_address import MacAddress

from anta.custom_types import Afi, Safi
from anta.custom_types import Afi, BgpDropStats, BgpUpdateError, MultiProtocolCaps, Safi, Vni

if TYPE_CHECKING:
import sys
Expand Down Expand Up @@ -97,7 +98,7 @@ def eos_key(self) -> str:
return AFI_SAFI_EOS_KEY[(self.afi, self.safi)]

def __str__(self) -> str:
"""Return a string representation of the BgpAddressFamily model. Used in failure messages.
"""Return a human-readable string representation of the BgpAddressFamily for reporting.

Examples
--------
Expand Down Expand Up @@ -128,3 +129,81 @@ def __init__(self, **data: Any) -> None: # noqa: ANN401
stacklevel=2,
)
super().__init__(**data)


class BgpPeer(BaseModel):
"""Model for a BGP peer.

Only IPv4 peers are supported for now.
"""

model_config = ConfigDict(extra="forbid")
peer_address: IPv4Address
"""IPv4 address of the BGP peer."""
vrf: str = "default"
"""Optional VRF for the BGP peer. Defaults to `default`."""
advertised_routes: list[IPv4Network] | None = None
"""List of advertised routes in CIDR format. Required field in the `VerifyBGPExchangedRoutes` test."""
received_routes: list[IPv4Network] | None = None
"""List of received routes in CIDR format. Required field in the `VerifyBGPExchangedRoutes` test."""
capabilities: list[MultiProtocolCaps] | None = None
"""List of BGP multiprotocol capabilities. Required field in the `VerifyBGPPeerMPCaps` test."""
strict: bool = False
"""If True, requires exact match of the provided BGP multiprotocol capabilities.

Optional field in the `VerifyBGPPeerMPCaps` test. Defaults to False."""
hold_time: int | None = Field(default=None, ge=3, le=7200)
"""BGP hold time in seconds. Required field in the `VerifyBGPTimers` test."""
keep_alive_time: int | None = Field(default=None, ge=0, le=3600)
"""BGP keepalive time in seconds. Required field in the `VerifyBGPTimers` test."""
drop_stats: list[BgpDropStats] | None = None
"""List of drop statistics to be verified.

Optional field in the `VerifyBGPPeerDropStats` test. If not provided, the test will verifies all drop statistics."""
update_errors: list[BgpUpdateError] | None = None
"""List of update error counters to be verified.

Optional field in the `VerifyBGPPeerUpdateErrors` test. If not provided, the test will verifies all the update error counters."""
inbound_route_map: str | None = None
"""Inbound route map applied, defaults to None. Required field in the `VerifyBgpRouteMaps` test."""
outbound_route_map: str | None = None
"""Outbound route map applied, defaults to None. Required field in the `VerifyBgpRouteMaps` test."""
maximum_routes: int | None = Field(default=None, ge=0, le=4294967294)
"""The maximum allowable number of BGP routes, `0` means unlimited. Required field in the `VerifyBGPPeerRouteLimit` test"""
warning_limit: int | None = Field(default=None, ge=0, le=4294967294)
"""Optional maximum routes warning limit. If not provided, it defaults to `0` meaning no warning limit."""

def __str__(self) -> str:
"""Return a human-readable string representation of the BgpPeer for reporting."""
return f"Peer: {self.peer_address} VRF: {self.vrf}"


class BgpNeighbor(BgpPeer): # pragma: no cover
"""Alias for the BgpPeer model to maintain backward compatibility.

When initialised, it will emit a deprecation warning and call the BgpPeer model.

TODO: Remove this class in ANTA v2.0.0.
"""

def __init__(self, **data: Any) -> None: # noqa: ANN401
"""Initialize the BgpPeer class, emitting a depreciation warning."""
warn(
message="BgpNeighbor model is deprecated and will be removed in ANTA v2.0.0. Use the BgpPeer model instead.",
category=DeprecationWarning,
stacklevel=2,
)
super().__init__(**data)


class VxlanEndpoint(BaseModel):
gmuloc marked this conversation as resolved.
Show resolved Hide resolved
"""Model for a VXLAN endpoint."""

address: IPv4Address | MacAddress
"""IPv4 or MAC address of the VXLAN endpoint."""
vni: Vni
"""VNI of the VXLAN endpoint."""

def __str__(self) -> str:
"""Return a human-readable string representation of the VxlanEndpoint for reporting."""
return f"Address: {self.address} VNI: {self.vni}"
5 changes: 2 additions & 3 deletions anta/reporter/md_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import logging
import re
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, ClassVar
from typing import TYPE_CHECKING, ClassVar, TextIO

from anta.constants import MD_REPORT_TOC
from anta.logger import anta_log_exception
Expand All @@ -17,7 +17,6 @@

if TYPE_CHECKING:
from collections.abc import Generator
from io import TextIOWrapper
from pathlib import Path

from anta.result_manager import ResultManager
Expand Down Expand Up @@ -72,7 +71,7 @@ class MDReportBase(ABC):
to generate and write content to the provided markdown file.
"""

def __init__(self, mdfile: TextIOWrapper, results: ResultManager) -> None:
def __init__(self, mdfile: TextIO, results: ResultManager) -> None:
"""Initialize the MDReportBase with an open markdown file object to write to and a ResultManager instance.

Parameters
Expand Down
Loading
Loading