Skip to content

Commit

Permalink
issue-499: Stricted input intervals and multiplier
Browse files Browse the repository at this point in the history
  • Loading branch information
MaheshGSLAB committed Jan 25, 2024
1 parent 383d5f0 commit aac9f07
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 32 deletions.
2 changes: 2 additions & 0 deletions anta/custom_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,5 @@ def bgp_multiprotocol_capabilities_abbreviations(value: str) -> str:
RsaKeySize = Literal[2048, 3072, 4096]
EcdsaKeySize = Literal[256, 384, 521]
MultiProtocolCaps = Annotated[str, BeforeValidator(bgp_multiprotocol_capabilities_abbreviations)]
BfdInterval = Annotated[int, Field(ge=50, le=60000)]
BfdMultiplier = Annotated[int, Field(ge=3, le=50)]
43 changes: 23 additions & 20 deletions anta/tests/bfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,36 @@

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 BFD peer's sessions are UP and remote disc is non-zero in the specified VRF.
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 BFD peers are up and remote disc is non-zero in the specified VRF.
* failure: The test will fail if BFD peers are not found, the status is not UP or remote disc is zero in the specified VRF.
* 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 BFD peer's sessions and remote disc in the specified VRF."
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 testcase.
This class defines the input parameters of the test case.
"""

bfd_peers: List[BFDPeers]
"""List of BFD peers"""
"""List of IPv4 BFD peers"""

class BFDPeers(BaseModel):
"""
This class defines the details of a BFD peer.
This class defines the details of an IPv4 BFD peer.
"""

peer_address: IPv4Address
Expand Down Expand Up @@ -76,40 +77,40 @@ def test(self) -> None:

class VerifyBFDPeersIntervals(AntaTest):
"""
This class verifies the timers of the BFD peers in the specified VRF.
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 BFD peers are correct in the specified VRF.
* failure: The test will fail if the BFD peers are not found or their timers are incorrect in the specified VRF.
* 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 BFD peers in the specified VRF."
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 testcase.
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 a BFD peer.
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: int
"""Tx interval of BFD peer"""
rx_interval: int
"""Rx interval of BFD peer"""
multiplier: int
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
Expand All @@ -120,8 +121,10 @@ def test(self) -> None:
for bfd_peers in self.inputs.bfd_peers:
peer = str(bfd_peers.peer_address)
vrf = bfd_peers.vrf
tx_interval = bfd_peers.tx_interval
rx_interval = bfd_peers.rx_interval

# 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="..")

Expand Down
8 changes: 4 additions & 4 deletions examples/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ anta.tests.bfd:
bfd_peers:
- peer_address: 192.0.255.8
vrf: default
tx_interval: 1200000
rx_interval: 1200000
tx_interval: 1200
rx_interval: 1200
multiplier: 3
- peer_address: 192.0.255.7
vrf: default
tx_interval: 1200000
rx_interval: 1200000
tx_interval: 1200
rx_interval: 1200
multiplier: 3

anta.tests.configuration:
Expand Down
16 changes: 8 additions & 8 deletions tests/units/anta_tests/test_bfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
],
"inputs": {
"bfd_peers": [
{"peer_address": "192.0.255.7", "vrf": "default", "tx_interval": 1200000, "rx_interval": 1200000, "multiplier": 3},
{"peer_address": "192.0.255.70", "vrf": "MGMT", "tx_interval": 1200000, "rx_interval": 1200000, "multiplier": 3},
{"peer_address": "192.0.255.7", "vrf": "default", "tx_interval": 1200, "rx_interval": 1200, "multiplier": 3},
{"peer_address": "192.0.255.70", "vrf": "MGMT", "tx_interval": 1200, "rx_interval": 1200, "multiplier": 3},
]
},
"expected": {"result": "success"},
Expand Down Expand Up @@ -103,8 +103,8 @@
],
"inputs": {
"bfd_peers": [
{"peer_address": "192.0.255.7", "vrf": "CS", "tx_interval": 1200000, "rx_interval": 1200000, "multiplier": 3},
{"peer_address": "192.0.255.70", "vrf": "MGMT", "tx_interval": 1200000, "rx_interval": 1200000, "multiplier": 3},
{"peer_address": "192.0.255.7", "vrf": "CS", "tx_interval": 1200, "rx_interval": 1200, "multiplier": 3},
{"peer_address": "192.0.255.70", "vrf": "MGMT", "tx_interval": 1200, "rx_interval": 1200, "multiplier": 3},
]
},
"expected": {
Expand All @@ -127,7 +127,7 @@
"peerStats": {
"": {
"peerStatsDetail": {
"operTxInterval": 1200001,
"operTxInterval": 1300000,
"operRxInterval": 1200000,
"detectMult": 4,
}
Expand Down Expand Up @@ -156,15 +156,15 @@
],
"inputs": {
"bfd_peers": [
{"peer_address": "192.0.255.7", "vrf": "default", "tx_interval": 1200000, "rx_interval": 1200000, "multiplier": 3},
{"peer_address": "192.0.255.70", "vrf": "MGMT", "tx_interval": 1200000, "rx_interval": 1200000, "multiplier": 3},
{"peer_address": "192.0.255.7", "vrf": "default", "tx_interval": 1200, "rx_interval": 1200, "multiplier": 3},
{"peer_address": "192.0.255.70", "vrf": "MGMT", "tx_interval": 1200, "rx_interval": 1200, "multiplier": 3},
]
},
"expected": {
"result": "failure",
"messages": [
"Following BFD peers are not configured or timers are not correct:\n"
"{'192.0.255.7': {'default': {'tx_interval': 1200001, 'rx_interval': 1200000, 'multiplier': 4}}, "
"{'192.0.255.7': {'default': {'tx_interval': 1300000, 'rx_interval': 1200000, 'multiplier': 4}}, "
"'192.0.255.70': {'MGMT': {'tx_interval': 120000, 'rx_interval': 120000, 'multiplier': 5}}}"
],
},
Expand Down

0 comments on commit aac9f07

Please sign in to comment.