Skip to content
4 changes: 2 additions & 2 deletions tests/common/devices/multi_asic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions tests/common/devices/sonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions tests/telemetry/events/bgp_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
14 changes: 8 additions & 6 deletions tests/telemetry/events/dhcp-relay_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)

Expand All @@ -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"]
Expand Down
23 changes: 15 additions & 8 deletions tests/telemetry/events/event_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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 {}
Expand Down
15 changes: 11 additions & 4 deletions tests/telemetry/events/run_events_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
6 changes: 3 additions & 3 deletions tests/telemetry/telemetry_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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.
Expand Down
Loading