Skip to content

Commit 4f56f4b

Browse files
Added ping test for bgp neighbors ~TestGap 02/2025 (sonic-net#17266)
What is the motivation for this PR? Currently, sonic-mgmt didn't have ping test for bgp neighbors. How did you do it? Adding a new Testcase to bgp testsuite to verify ping. How did you verify/test it? Ran in Microsoft Lab on T0 and T2 chassis both manually and on Elastic test as well Co-authored-by: yatishkoul <yatishkoul@gmail.com>
1 parent 4750b90 commit 4f56f4b

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/bgp/test_ping_bgp_neighbor.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import pytest
2+
import logging
3+
4+
pytestmark = [
5+
pytest.mark.topology('any')
6+
]
7+
8+
9+
def test_ping_bgp_neighbor(duthosts, enum_frontend_dut_hostname, enum_asic_index):
10+
"""Check ping connectivity to all BGP neighbors across all ASICs of the given DUT"""
11+
12+
duthost = duthosts[enum_frontend_dut_hostname]
13+
if enum_asic_index is None:
14+
pytest.skip(f"Skipping test since {duthost.hostname} is not a multi-ASIC device.")
15+
16+
bgp_facts = duthost.bgp_facts(instance_id=enum_asic_index)['ansible_facts']
17+
namespace = duthost.get_namespace_from_asic_id(enum_asic_index)
18+
asic_info = f"(namespace: {namespace})" if namespace else ""
19+
20+
for neighbor_ip, neighbor_data in bgp_facts['bgp_neighbors'].items():
21+
# Verify that the BGP session is established
22+
error_msg = f"BGP session with {neighbor_ip} is not 'established'"
23+
assert neighbor_data['state'] == 'established', error_msg
24+
logging.info(f"Pinging BGP neighbor {neighbor_ip} from {duthost.hostname} {asic_info}")
25+
if namespace:
26+
ping_cmd = f"sudo ip netns exec {namespace} ping -c 1 {neighbor_ip}"
27+
else:
28+
ping_cmd = f"ping -c 1 {neighbor_ip}"
29+
30+
result = duthost.shell(ping_cmd, module_ignore_errors=True)
31+
# Checking if the ping was successful
32+
if result['rc'] != 0:
33+
logging.error(f"Ping failed to BGP neighbor {neighbor_ip} from {duthost.hostname} {asic_info}")
34+
raise AssertionError(
35+
f"Ping failed to BGP neighbor {neighbor_ip} from {duthost.hostname} "
36+
f"{asic_info}"
37+
)
38+
logging.info(f"Ping to BGP neighbor {neighbor_ip} successful from {duthost.hostname} {asic_info}")
39+
40+
logging.info(f"All BGP neighbors on {duthost.hostname} {asic_info} are reachable via ping.")

0 commit comments

Comments
 (0)