|
| 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