-
Notifications
You must be signed in to change notification settings - Fork 34
feat(anta.tests): Adding the test case to verify BFD session and timers #500
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2e4ab44
issue-499: Added testcase for BFD session and timers
MaheshGSLAB 8e92dd9
issue-499: improve code
MaheshGSLAB bc6a7af
issue-499: fix tox issue for py38
MaheshGSLAB 1be46af
issue-499: removed model_rebuild method
MaheshGSLAB 984d687
issue-499: updated the verification and split the testcase
MaheshGSLAB e292e1c
issue-499: Updated the show command
MaheshGSLAB 383d5f0
issue-499: removed Ipv6 support
MaheshGSLAB aac9f07
issue-499: Stricted input intervals and multiplier
MaheshGSLAB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
# Copyright (c) 2023-2024 Arista Networks, Inc. | ||
# Use of this source code is governed by the Apache License 2.0 | ||
# that can be found in the LICENSE file. | ||
""" | ||
BFD test functions | ||
""" | ||
# Mypy does not understand AntaTest.Input typing | ||
# mypy: disable-error-code=attr-defined | ||
from __future__ import annotations | ||
|
||
from ipaddress import IPv4Address | ||
from typing import Any, List | ||
|
||
from pydantic import BaseModel | ||
|
||
from anta.custom_types import BfdInterval, BfdMultiplier | ||
from anta.models import AntaCommand, AntaTest | ||
from anta.tools.get_value import get_value | ||
|
||
|
||
class VerifyBFDSpecificPeers(AntaTest): | ||
""" | ||
This class verifies if the IPv4 BFD peer's sessions are UP and remote disc is non-zero in the specified VRF. | ||
|
||
Expected results: | ||
* success: The test will pass if IPv4 BFD peers are up and remote disc is non-zero in the specified VRF. | ||
* failure: The test will fail if IPv4 BFD peers are not found, the status is not UP or remote disc is zero in the specified VRF. | ||
""" | ||
|
||
name = "VerifyBFDSpecificPeers" | ||
description = "Verifies the IPv4 BFD peer's sessions and remote disc in the specified VRF." | ||
categories = ["bfd"] | ||
commands = [AntaCommand(command="show bfd peers")] | ||
|
||
class Input(AntaTest.Input): | ||
""" | ||
This class defines the input parameters of the test case. | ||
""" | ||
|
||
bfd_peers: List[BFDPeers] | ||
"""List of IPv4 BFD peers""" | ||
|
||
class BFDPeers(BaseModel): | ||
""" | ||
This class defines the details of an IPv4 BFD peer. | ||
""" | ||
|
||
peer_address: IPv4Address | ||
"""IPv4 address of a BFD peer""" | ||
vrf: str = "default" | ||
"""Optional VRF for BGP peer. If not provided, it defaults to `default`.""" | ||
|
||
@AntaTest.anta_test | ||
def test(self) -> None: | ||
failures: dict[Any, Any] = {} | ||
|
||
# Iterating over BFD peers | ||
for bfd_peer in self.inputs.bfd_peers: | ||
peer = str(bfd_peer.peer_address) | ||
vrf = bfd_peer.vrf | ||
bfd_output = get_value(self.instance_commands[0].json_output, f"vrfs..{vrf}..ipv4Neighbors..{peer}..peerStats..", separator="..") | ||
|
||
# Check if BFD peer configured | ||
if not bfd_output: | ||
failures[peer] = {vrf: "Not Configured"} | ||
continue | ||
|
||
# Check BFD peer status and remote disc | ||
if not (bfd_output.get("status") == "up" and bfd_output.get("remoteDisc") != 0): | ||
failures[peer] = {vrf: {"status": bfd_output.get("status"), "remote_disc": bfd_output.get("remoteDisc")}} | ||
|
||
if not failures: | ||
self.result.is_success() | ||
else: | ||
self.result.is_failure(f"Following BFD peers are not configured, status is not up or remote disc is zero:\n{failures}") | ||
|
||
|
||
class VerifyBFDPeersIntervals(AntaTest): | ||
""" | ||
This class verifies the timers of the IPv4 BFD peers in the specified VRF. | ||
|
||
Expected results: | ||
* success: The test will pass if the timers of the IPv4 BFD peers are correct in the specified VRF. | ||
* failure: The test will fail if the IPv4 BFD peers are not found or their timers are incorrect in the specified VRF. | ||
""" | ||
|
||
name = "VerifyBFDPeersIntervals" | ||
description = "Verifies the timers of the IPv4 BFD peers in the specified VRF." | ||
categories = ["bfd"] | ||
commands = [AntaCommand(command="show bfd peers detail")] | ||
|
||
class Input(AntaTest.Input): | ||
""" | ||
This class defines the input parameters of the test case. | ||
""" | ||
|
||
bfd_peers: List[BFDPeers] | ||
"""List of BFD peers""" | ||
|
||
class BFDPeers(BaseModel): | ||
""" | ||
This class defines the details of an IPv4 BFD peer. | ||
""" | ||
|
||
peer_address: IPv4Address | ||
"""IPv4 address of a BFD peer""" | ||
vrf: str = "default" | ||
"""Optional VRF for BGP peer. If not provided, it defaults to `default`.""" | ||
tx_interval: BfdInterval | ||
"""Tx interval of BFD peer in milliseconds""" | ||
rx_interval: BfdInterval | ||
"""Rx interval of BFD peer in milliseconds""" | ||
multiplier: BfdMultiplier | ||
"""Multiplier of BFD peer""" | ||
|
||
@AntaTest.anta_test | ||
def test(self) -> None: | ||
failures: dict[Any, Any] = {} | ||
|
||
# Iterating over BFD peers | ||
for bfd_peers in self.inputs.bfd_peers: | ||
peer = str(bfd_peers.peer_address) | ||
vrf = bfd_peers.vrf | ||
|
||
# Converting milliseconds intervals into actual value | ||
tx_interval = bfd_peers.tx_interval * 1000 | ||
rx_interval = bfd_peers.rx_interval * 1000 | ||
multiplier = bfd_peers.multiplier | ||
bfd_output = get_value(self.instance_commands[0].json_output, f"vrfs..{vrf}..ipv4Neighbors..{peer}..peerStats..", separator="..") | ||
|
||
# Check if BFD peer configured | ||
if not bfd_output: | ||
failures[peer] = {vrf: "Not Configured"} | ||
continue | ||
|
||
bfd_details = bfd_output.get("peerStatsDetail", {}) | ||
intervals_ok = ( | ||
bfd_details.get("operTxInterval") == tx_interval and bfd_details.get("operRxInterval") == rx_interval and bfd_details.get("detectMult") == multiplier | ||
) | ||
|
||
# Check timers of BFD peer | ||
if not intervals_ok: | ||
failures[peer] = { | ||
vrf: { | ||
"tx_interval": bfd_details.get("operTxInterval"), | ||
"rx_interval": bfd_details.get("operRxInterval"), | ||
"multiplier": bfd_details.get("detectMult"), | ||
} | ||
} | ||
|
||
# Check if any failures | ||
if not failures: | ||
self.result.is_success() | ||
else: | ||
self.result.is_failure(f"Following BFD peers are not configured or timers are not correct:\n{failures}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.