From 30f731cad7646c9cc3108a8afa94219070e1b11b Mon Sep 17 00:00:00 2001 From: vitthalmagadum <122079046+vitthalmagadum@users.noreply.github.com> Date: Thu, 29 Aug 2024 18:16:23 +0530 Subject: [PATCH] feat(anta): Updated VerifyBFDPeersIntervals for failure message to be in milliseconds like the inputs (#805) --- anta/tests/bfd.py | 24 ++++++++++++------------ tests/units/anta_tests/test_bfd.py | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/anta/tests/bfd.py b/anta/tests/bfd.py index 0b171a6d2..f42d80de7 100644 --- a/anta/tests/bfd.py +++ b/anta/tests/bfd.py @@ -157,34 +157,34 @@ def test(self) -> None: 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 + tx_interval = bfd_peers.tx_interval + rx_interval = bfd_peers.rx_interval multiplier = bfd_peers.multiplier + + # Check if BFD peer configured 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 + # Convert interval timer(s) into milliseconds to be consistent with the inputs. 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 - ) + op_tx_interval = bfd_details.get("operTxInterval") // 1000 + op_rx_interval = bfd_details.get("operRxInterval") // 1000 + detect_multiplier = bfd_details.get("detectMult") + intervals_ok = op_tx_interval == tx_interval and op_rx_interval == rx_interval and detect_multiplier == 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"), + "tx_interval": op_tx_interval, + "rx_interval": op_rx_interval, + "multiplier": detect_multiplier, } } diff --git a/tests/units/anta_tests/test_bfd.py b/tests/units/anta_tests/test_bfd.py index b3ab5609a..3b1b8b86a 100644 --- a/tests/units/anta_tests/test_bfd.py +++ b/tests/units/anta_tests/test_bfd.py @@ -163,8 +163,8 @@ "result": "failure", "messages": [ "Following BFD peers are not configured or timers are not correct:\n" - "{'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}}}" + "{'192.0.255.7': {'default': {'tx_interval': 1300, 'rx_interval': 1200, 'multiplier': 4}}, " + "'192.0.255.70': {'MGMT': {'tx_interval': 120, 'rx_interval': 120, 'multiplier': 5}}}" ], }, },