Skip to content

Commit b53a8a9

Browse files
netpickerSanjay Kumar
andauthored
Update example2 final (#130)
* Add examples_extended folder for additional test cases * Add SNMP trap host validation test for Cisco IOS * Add SNMP trap host validation test for Cisco IOS * Add SNMP trap host validation test for Cisco IOS * Add HA BGP prefix consistency test for Fortinet --------- Co-authored-by: Sanjay Kumar <sanjay.kumar@netyce.com>
1 parent 1d24cad commit b53a8a9

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""
2+
Test Name: HA BGP Prefix Consistency
3+
Platform: fortinet
4+
Tags: fw_test
5+
6+
Description:
7+
This test ensures that all BGP neighbors on a Fortinet firewall advertise
8+
the same set of prefixes — useful in HA firewall pairs where consistency
9+
between neighbors is required.
10+
11+
The test does the following:
12+
- Runs "get router info bgp summary" to get neighbor IPs
13+
- Fetches "received-routes" from each neighbor
14+
- Compares the received prefixes to ensure they are identical
15+
"""
16+
17+
import re
18+
from comfy import medium
19+
20+
21+
@medium(
22+
name='ha_bgp_prefix_consistency',
23+
platform=['fortinet'],
24+
device_tags='fw_test',
25+
)
26+
def ha_bgp_prefix_consistency(configuration, commands, device):
27+
summary_output = device.cli("get router info bgp summary")
28+
neighbor_ips = []
29+
30+
for line in summary_output.splitlines():
31+
match = re.match(r'\s*(\d{1,3}(?:\.\d{1,3}){3})\s+\d+', line)
32+
if match:
33+
neighbor_ips.append(match.group(1))
34+
35+
assert len(neighbor_ips) >= 2, f"Expected at least 2 neighbors, found {len(neighbor_ips)}"
36+
37+
neighbor_prefixes = {}
38+
39+
for neighbor in neighbor_ips:
40+
received_output = device.cli(f"get router info bgp neighbors {neighbor} received-routes")
41+
prefixes = set()
42+
43+
for line in received_output.splitlines():
44+
match = re.search(r'(\d{1,3}(?:\.\d{1,3}){3}/\d+)', line)
45+
if match:
46+
prefixes.add(match.group(1))
47+
48+
assert prefixes, f"No prefixes received from neighbor {neighbor}"
49+
neighbor_prefixes[neighbor] = prefixes
50+
51+
reference_neighbor = neighbor_ips[0]
52+
reference_prefixes = neighbor_prefixes[reference_neighbor]
53+
54+
for neighbor, prefixes in neighbor_prefixes.items():
55+
if prefixes != reference_prefixes:
56+
raise AssertionError(
57+
f"Prefixes from {neighbor} do not match {reference_neighbor}.\n"
58+
f"{reference_neighbor} has: {sorted(reference_prefixes)}\n"
59+
f"{neighbor} has: {sorted(prefixes)}"
60+
)

0 commit comments

Comments
 (0)