Skip to content

Commit

Permalink
Refactor the VerifyBFDPeersIntervals test to add detection time
Browse files Browse the repository at this point in the history
  • Loading branch information
VitthalMagadum authored and vitthalmagadum committed Dec 2, 2024
1 parent d2c8218 commit 926c3bc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
25 changes: 17 additions & 8 deletions anta/tests/bfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,13 @@ class VerifyBFDPeersIntervals(AntaTest):
tx_interval: 1200
rx_interval: 1200
multiplier: 3
detection_time: 3600
- peer_address: 192.0.255.7
vrf: default
tx_interval: 1200
rx_interval: 1200
multiplier: 3
detection_time: 3600
```
"""

Expand All @@ -145,12 +147,13 @@ def test(self) -> None:
self.result.is_success()

# Iterating over BFD peers
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
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

# Check if BFD peer configured
bfd_output = get_value(
Expand All @@ -166,10 +169,16 @@ def test(self) -> None:
bfd_details = bfd_output.get("peerStatsDetail", {})
op_tx_interval = bfd_details.get("operTxInterval") // 1000
op_rx_interval = bfd_details.get("operRxInterval") // 1000
op_detection_time = bfd_details.get("detectTime") // 1000
detect_multiplier = bfd_details.get("detectMult")

if op_tx_interval != tx_interval:
self.result.is_failure(f"{bfd_peer} - Incorrect Transmit interval - Expected: {tx_interval} Actual: {op_tx_interval}")
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_rx_interval != rx_interval:
self.result.is_failure(f"{bfd_peer} - Incorrect Receive interval - Expected: {rx_interval} Actual: {op_rx_interval}")
Expand Down
2 changes: 2 additions & 0 deletions examples/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ anta.tests.bfd:
tx_interval: 1200
rx_interval: 1200
multiplier: 3
detection_time: 3600
- peer_address: 192.0.255.7
vrf: default
tx_interval: 1200
rx_interval: 1200
multiplier: 3
detection_time: 3600
- VerifyBFDPeersHealth:
down_threshold: 2
- VerifyBFDPeersRegProtocols:
Expand Down
18 changes: 12 additions & 6 deletions tests/units/anta_tests/test_bfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"operTxInterval": 1200000,
"operRxInterval": 1200000,
"detectMult": 3,
"detectTime": 3600000,
}
}
}
Expand All @@ -42,6 +43,7 @@
"operTxInterval": 1200000,
"operRxInterval": 1200000,
"detectMult": 3,
"detectTime": 3600000,
}
}
}
Expand All @@ -53,8 +55,8 @@
],
"inputs": {
"bfd_peers": [
{"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},
{"peer_address": "192.0.255.7", "vrf": "default", "tx_interval": 1200, "rx_interval": 1200, "multiplier": 3, "detection_time": 3600},
{"peer_address": "192.0.255.70", "vrf": "MGMT", "tx_interval": 1200, "rx_interval": 1200, "multiplier": 3, "detection_time": 3600},
]
},
"expected": {"result": "success"},
Expand All @@ -74,6 +76,7 @@
"operTxInterval": 1200000,
"operRxInterval": 1200000,
"detectMult": 3,
"detectTime": 3600000,
}
}
}
Expand All @@ -89,6 +92,7 @@
"operTxInterval": 1200000,
"operRxInterval": 1200000,
"detectMult": 3,
"detectTime": 3600000,
}
}
}
Expand All @@ -100,8 +104,8 @@
],
"inputs": {
"bfd_peers": [
{"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},
{"peer_address": "192.0.255.7", "vrf": "CS", "tx_interval": 1200, "rx_interval": 1200, "multiplier": 3, "detection_time": 3600},
{"peer_address": "192.0.255.70", "vrf": "MGMT", "tx_interval": 1200, "rx_interval": 1200, "multiplier": 3, "detection_time": 3600},
]
},
"expected": {
Expand All @@ -127,6 +131,7 @@
"operTxInterval": 1300000,
"operRxInterval": 1200000,
"detectMult": 4,
"detectTime": 4000000,
}
}
}
Expand All @@ -142,6 +147,7 @@
"operTxInterval": 120000,
"operRxInterval": 120000,
"detectMult": 5,
"detectTime": 4000000,
}
}
}
Expand All @@ -153,8 +159,8 @@
],
"inputs": {
"bfd_peers": [
{"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},
{"peer_address": "192.0.255.7", "vrf": "default", "tx_interval": 1200, "rx_interval": 1200, "multiplier": 3, "detection_time": 3600},
{"peer_address": "192.0.255.70", "vrf": "MGMT", "tx_interval": 1200, "rx_interval": 1200, "multiplier": 3, "detection_time": 3600},
]
},
"expected": {
Expand Down

0 comments on commit 926c3bc

Please sign in to comment.