diff --git a/tests/common/devices/multi_asic.py b/tests/common/devices/multi_asic.py index 9350f68640a..7f1e7caf0b3 100644 --- a/tests/common/devices/multi_asic.py +++ b/tests/common/devices/multi_asic.py @@ -424,8 +424,8 @@ def is_container_running(self, service): return False - def is_bgp_state_idle(self): - return self.sonichost.is_bgp_state_idle() + def is_bgp_state_idle(self, ipv6=False): + return self.sonichost.is_bgp_state_idle(ipv6) def is_service_running(self, service_name, docker_name=None): docker_name = service_name if docker_name is None else docker_name diff --git a/tests/common/devices/sonic.py b/tests/common/devices/sonic.py index d9e5e48ccbc..17c7229e573 100644 --- a/tests/common/devices/sonic.py +++ b/tests/common/devices/sonic.py @@ -2223,16 +2223,18 @@ def no_shutdown_bgp_neighbors(self, asn, neighbors=[]): logging.info('No shut BGP neighbors: {}'.format(json.dumps(neighbors))) return self.command(command) - def is_bgp_state_idle(self): + def is_bgp_state_idle(self, ipv6=False): """ Check if all BGP peers are in IDLE state. Returns: True or False """ - bgp_summary_v4 = self.command("show ip bgp summary")["stdout_lines"] bgp_summary_v6 = self.command("show ipv6 bgp summary")["stdout_lines"] - bgp_summary = bgp_summary_v4 + bgp_summary_v6 + bgp_summary = bgp_summary_v6 + if not ipv6: + bgp_summary_v4 = self.command("show ip bgp summary")["stdout_lines"] + bgp_summary = bgp_summary_v4 + bgp_summary_v6 idle_count = 0 expected_idle_count = 0 diff --git a/tests/telemetry/events/bgp_events.py b/tests/telemetry/events/bgp_events.py index b2836b0986c..2966a60e996 100644 --- a/tests/telemetry/events/bgp_events.py +++ b/tests/telemetry/events/bgp_events.py @@ -4,8 +4,8 @@ import time import ipaddress -from run_events_test import run_test from tests.common.utilities import is_ipv6_only_topology +from run_events_test import run_test logger = logging.getLogger(__name__) tag = "sonic-events-bgp" @@ -75,7 +75,8 @@ def drop_tcp_packets(duthost, tbinfo): def shutdown_bgp_neighbors(duthost, tbinfo): logger.info("Shutting down bgp neighbors to test bgp-state event") - assert duthost.is_service_running("bgpcfgd", "bgp") is True and duthost.is_bgp_state_idle() is False + is_ipv6_only = tbinfo and is_ipv6_only_topology(tbinfo) + assert duthost.is_service_running("bgpcfgd", "bgp") is True and duthost.is_bgp_state_idle(is_ipv6_only) is False logger.info("Start all bgp sessions") ret = duthost.shell("config bgp startup all") assert ret["rc"] == 0, "Failing to startup" diff --git a/tests/telemetry/events/dhcp-relay_events.py b/tests/telemetry/events/dhcp-relay_events.py index 3bab339df6c..ffdea09e61d 100644 --- a/tests/telemetry/events/dhcp-relay_events.py +++ b/tests/telemetry/events/dhcp-relay_events.py @@ -16,6 +16,7 @@ def test_event(duthost, tbinfo, gnxi_path, ptfhost, ptfadapter, data_dir, validate_yang): + is_ipv6_only = tbinfo and is_ipv6_only_topology(tbinfo) if duthost.dut_basic_facts()['ansible_facts']['dut_basic_facts'].get("is_smartswitch") and \ duthost.facts.get("router_type") == 'leafrouter': pytest.skip("Skipping dhcp_relay events for smartswitch t1 topologies") @@ -29,10 +30,12 @@ def test_event(duthost, tbinfo, gnxi_path, ptfhost, ptfadapter, data_dir, valida if is_ipv6_only_topology(tbinfo): pytest.skip("Skipping dhcp_relay events for IPv6-only topologies") logger.info("Beginning to test dhcp-relay events") - run_test(duthost, tbinfo, gnxi_path, ptfhost, data_dir, validate_yang, trigger_dhcp_relay_discard, - "dhcp_relay_discard.json", "sonic-events-dhcp-relay:dhcp-relay-discard", tag, False, 30, ptfadapter) - run_test(duthost, tbinfo, gnxi_path, ptfhost, data_dir, validate_yang, trigger_dhcp_relay_disparity, - "dhcp_relay_disparity.json", "sonic-events-dhcp-relay:dhcp-relay-disparity", tag, False, 30, ptfadapter) + if not is_ipv6_only: + run_test(duthost, tbinfo, gnxi_path, ptfhost, data_dir, validate_yang, trigger_dhcp_relay_discard, + "dhcp_relay_discard.json", "sonic-events-dhcp-relay:dhcp-relay-discard", tag, False, 30, ptfadapter) + run_test(duthost, tbinfo, gnxi_path, ptfhost, data_dir, validate_yang, trigger_dhcp_relay_disparity, + "dhcp_relay_disparity.json", "sonic-events-dhcp-relay:dhcp-relay-disparity", tag, + False, 30, ptfadapter) run_test(duthost, tbinfo, gnxi_path, ptfhost, data_dir, validate_yang, trigger_dhcp_relay_bind_failure, "dhcp_relay_bind_failure.json", "sonic-events-dhcp-relay:dhcp-relay-bind-failure", tag, False, 30) @@ -55,9 +58,8 @@ def trigger_dhcp_relay_bind_failure(duthost, tbinfo): # Flush ipv6 vlan address and restart dhc6relay process py_assert(wait_until(100, 10, 0, duthost.is_service_fully_started, "dhcp_relay"), "dhcp_relay container not started") - # Get Vlan with IPv6 address configured - dhcp_test_info = find_test_vlan(duthost) + dhcp_test_info = find_test_vlan(duthost, tbinfo) py_assert(len(dhcp_test_info) != 0, "Unable to find vlan for test") vlan = dhcp_test_info["vlan"] diff --git a/tests/telemetry/events/event_utils.py b/tests/telemetry/events/event_utils.py index 7cae368f651..c00a542cbbe 100644 --- a/tests/telemetry/events/event_utils.py +++ b/tests/telemetry/events/event_utils.py @@ -4,7 +4,7 @@ import ptf.packet as scapy import ptf.testutils as testutils -from tests.common.utilities import wait_until +from tests.common.utilities import wait_until, is_ipv6_only_topology from tests.common.helpers.assertions import pytest_assert logger = logging.getLogger(__name__) @@ -114,31 +114,38 @@ def verify_counter_increase(duthost, current_value, increase, stat): return current_stat_counter >= current_value + increase -def find_test_vlan(duthost): +def find_test_vlan(duthost, tbinfo=None): """Returns vlan information for dhcp_relay tests Returns dictionary of vlan port name, dhcrelay process name, ipv4 address, dhc6relay process name, ipv6 address, and member interfaces """ + is_ipv6_only = tbinfo and is_ipv6_only_topology(tbinfo) vlan_brief = duthost.get_vlan_brief() for vlan in vlan_brief: + dhcrelay_process = None + interface_ipv4 = None # Find dhcrelay process - dhcrelay_process = duthost.shell("docker exec dhcp_relay supervisorctl status \ - | grep isc-dhcpv4-relay-%s | awk '{print $1}'" % vlan)['stdout'] + if not is_ipv6_only: + dhcrelay_process = duthost.shell("docker exec dhcp_relay supervisorctl status \ + | grep isc-dhcpv4-relay-%s | awk '{print $1}'" % vlan)['stdout'] + interface_ipv4 = vlan_brief[vlan]['interface_ipv4'] dhcp6relay_process = duthost.shell("docker exec dhcp_relay supervisorctl status \ | grep dhcp6relay | awk '{print $1}'")['stdout'] - interface_ipv4 = vlan_brief[vlan]['interface_ipv4'] interface_ipv6 = vlan_brief[vlan]['interface_ipv6'] members = vlan_brief[vlan]['members'] # Check all returning fields are non empty - results = [dhcrelay_process, interface_ipv4, dhcp6relay_process, interface_ipv6, members] + if is_ipv6_only: + results = [dhcp6relay_process, interface_ipv6, members] + else: + results = [dhcrelay_process, interface_ipv4, dhcp6relay_process, interface_ipv6, members] if all(result for result in results): return { "vlan": vlan, "dhcrelay_process": dhcrelay_process, - "ipv4_address": interface_ipv4[0], + "ipv4_address": interface_ipv4[0] if interface_ipv4 else None, "dhcp6relay_process": dhcp6relay_process, - "ipv6_address": interface_ipv6[0], + "ipv6_address": interface_ipv6[0] if interface_ipv6 else None, "member_interface": members } return {} diff --git a/tests/telemetry/events/run_events_test.py b/tests/telemetry/events/run_events_test.py index edc8bf175de..a1b0ae1f0ed 100644 --- a/tests/telemetry/events/run_events_test.py +++ b/tests/telemetry/events/run_events_test.py @@ -14,10 +14,17 @@ def run_test(duthost, tbinfo, gnxi_path, ptfhost, data_dir, validate_yang, trigg filter_event_regex, tag, heartbeat=False, timeout=30, ptfadapter=None): op_file = os.path.join(data_dir, json_file) if trigger is not None: # no trigger for heartbeat - if ptfadapter is None: - trigger(duthost, tbinfo) # add events to cache - else: - trigger(duthost, tbinfo, ptfadapter) + try: + if ptfadapter is None: + trigger(duthost, tbinfo=tbinfo) # add events to cache + else: + trigger(duthost, ptfadapter=ptfadapter, tbinfo=tbinfo) + except TypeError: + if ptfadapter is None: + trigger(duthost) + else: + trigger(duthost, ptfadapter) + listen_for_events(duthost, gnxi_path, ptfhost, filter_event_regex, op_file, timeout) # listen from cache data = {} diff --git a/tests/telemetry/telemetry_utils.py b/tests/telemetry/telemetry_utils.py index ea93888d9f7..faedbf84708 100644 --- a/tests/telemetry/telemetry_utils.py +++ b/tests/telemetry/telemetry_utils.py @@ -75,10 +75,10 @@ def fetch_json_ptf_output(regex, output, match_no): def listen_for_events(duthost, gnxi_path, ptfhost, filter_event_regex, op_file, timeout, update_count=1, - match_number=0): + match_number=0, tbinfo=None): cmd = generate_client_cli(duthost=duthost, gnxi_path=gnxi_path, method=METHOD_SUBSCRIBE, submode=SUBMODE_ONCHANGE, update_count=update_count, xpath="all[heartbeat=2]", - target="EVENTS", filter_event_regex=filter_event_regex, timeout=timeout) + target="EVENTS", filter_event_regex=filter_event_regex, timeout=timeout, tbinfo=tbinfo) result = ptfhost.shell(cmd) assert result["rc"] == 0, "PTF command failed with non zero return code" output = result["stdout"] @@ -109,7 +109,7 @@ def trigger_logger(duthost, log, process, container="", priority="local0.notice" def generate_client_cli(duthost, gnxi_path, method=METHOD_GET, xpath="COUNTERS/Ethernet0", target="COUNTERS_DB", subscribe_mode=SUBSCRIBE_MODE_STREAM, submode=SUBMODE_SAMPLE, intervalms=0, update_count=3, create_connections=1, filter_event_regex="", namespace=None, - timeout=-1, polling_interval=10, max_sync_count=-1): + timeout=-1, polling_interval=10, max_sync_count=-1, tbinfo=None): """ Generate the py_gnmicli command line based on the given params. This version ensures the command runs from the correct directory and within the activated virtual environment to resolve dependency issues.