Skip to content

Commit

Permalink
Updated input model refacoring
Browse files Browse the repository at this point in the history
  • Loading branch information
vitthalmagadum committed Dec 2, 2024
1 parent 926c3bc commit e953dd1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
3 changes: 3 additions & 0 deletions anta/input_models/bfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class BFDPeer(BaseModel):
"""Multiplier of BFD peer. Required field in the `VerifyBFDPeersIntervals` test."""
protocols: list[BfdProtocol] | None = None
"""List of protocols to be verified. Required field in the `VerifyBFDPeersRegProtocols` test."""
detection_time: int | None = None
"""Detection time of BFD peer in milliseconds. The period of time without receiving BFD packets
after which the session is determined to have failed."""

def __str__(self) -> str:
"""Return a human-readable string representation of the BFDPeer for reporting."""
Expand Down
32 changes: 15 additions & 17 deletions anta/tests/bfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ class VerifyBFDPeersIntervals(AntaTest):
1. Confirms that the specified VRF is configured.
2. Verifies that the peer exists in the BFD configuration.
3. Confirms that BFD peer is correctly configured with the `Transmit interval, Receive interval and Multiplier`.
3. Confirms that BFD peer is correctly configured with the `Transmit interval, Receive interval, Detection time and Multiplier`.
Expected Results
----------------
* Success: If all of the following conditions are met:
- All specified peers are found in the BFD configuration within the specified VRF.
- All BFD peers are correctly configured with the `Transmit interval, Receive interval and Multiplier`.
- All BFD peers are correctly configured with the `Transmit interval, Receive interval, Detection time and Multiplier`.
* Failure: If any of the following occur:
- A specified peer is not found in the BFD configuration within the specified VRF.
- Any BFD peer not correctly configured with the `Transmit interval, Receive interval and Multiplier`.
- Any BFD peer not correctly configured with the `Transmit interval, Receive interval, Detection time and Multiplier`.
Examples
--------
Expand Down Expand Up @@ -147,13 +147,13 @@ def test(self) -> None:
self.result.is_success()

# Iterating over BFD peers
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
multiplier = bfd_peers.multiplier
detect_time = bfd_peers.detection_time
for bfd_peer in self.inputs.bfd_peers:
peer = str(bfd_peer.peer_address)
vrf = bfd_peer.vrf
tx_interval = bfd_peer.tx_interval
rx_interval = bfd_peer.rx_interval
multiplier = bfd_peer.multiplier
detect_time = bfd_peer.detection_time

# Check if BFD peer configured
bfd_output = get_value(
Expand All @@ -172,20 +172,18 @@ def test(self) -> None:
op_detection_time = bfd_details.get("detectTime") // 1000
detect_multiplier = bfd_details.get("detectMult")

intervals_ok = op_tx_interval == tx_interval and op_rx_interval == rx_interval and detect_multiplier == multiplier and op_detection_time == detect_time

# Check timers of BFD peer
if not intervals_ok:
failures[peer] = {
vrf: {"tx_interval": op_tx_interval, "rx_interval": op_rx_interval, "multiplier": detect_multiplier, "detection_time": op_detection_time}
}
if op_tx_interval != tx_interval:
self.result.is_failure(f"{bfd_peer} - Incorrect Transmit interval - Expected: {tx_interval} Actual: {op_tx_interval}")

if op_rx_interval != rx_interval:
self.result.is_failure(f"{bfd_peer} - Incorrect Receive interval - Expected: {rx_interval} Actual: {op_rx_interval}")

if detect_multiplier != multiplier:
self.result.is_failure(f"{bfd_peer} - Incorrect Multiplier - Expected: {multiplier} Actual: {detect_multiplier}")

if op_detection_time != detect_time:
self.result.is_failure(f"{bfd_peer} - Incorrect Detection Time - Expected: {detect_time} Actual: {op_detection_time}")


class VerifyBFDPeersHealth(AntaTest):
"""Verifies the health of IPv4 BFD peers across all VRFs.
Expand Down
2 changes: 2 additions & 0 deletions tests/units/anta_tests/test_bfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,11 @@
"messages": [
"Peer: 192.0.255.7 VRF: default - Incorrect Transmit interval - Expected: 1200 Actual: 1300",
"Peer: 192.0.255.7 VRF: default - Incorrect Multiplier - Expected: 3 Actual: 4",
"Peer: 192.0.255.7 VRF: default - Incorrect Detection Time - Expected: 3600 Actual: 4000",
"Peer: 192.0.255.70 VRF: MGMT - Incorrect Transmit interval - Expected: 1200 Actual: 120",
"Peer: 192.0.255.70 VRF: MGMT - Incorrect Receive interval - Expected: 1200 Actual: 120",
"Peer: 192.0.255.70 VRF: MGMT - Incorrect Multiplier - Expected: 3 Actual: 5",
"Peer: 192.0.255.70 VRF: MGMT - Incorrect Detection Time - Expected: 3600 Actual: 4000",
],
},
},
Expand Down

0 comments on commit e953dd1

Please sign in to comment.