Skip to content

Commit

Permalink
Merge branch 'sonic-net:master' into longlink_xoff_reduction
Browse files Browse the repository at this point in the history
  • Loading branch information
sreejithsreekumaran authored Jan 17, 2025
2 parents 1ded477 + 5054d0a commit 7032718
Show file tree
Hide file tree
Showing 16 changed files with 197 additions and 22 deletions.
4 changes: 2 additions & 2 deletions ansible/library/announce_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def wait_for_http(host_ip, http_port, timeout=10):

def get_topo_type(topo_name):
pattern = re.compile(
r'^(t0-mclag|t0|t1|ptf|fullmesh|dualtor|t2|mgmttor|m0|mc0|mx|dpu)')
r'^(t0-mclag|t0|t1|ptf|fullmesh|dualtor|t2|mgmttor|m0|mc0|mx|dpu|smartswitch-t1)')
match = pattern.match(topo_name)
if not match:
return "unsupported"
Expand Down Expand Up @@ -1072,7 +1072,7 @@ def main():
if topo_type == "t0":
fib_t0(topo, ptf_ip, no_default_route=is_storage_backend, action=action)
module.exit_json(changed=True)
elif topo_type == "t1":
elif topo_type == "t1" or topo_type == "smartswitch-t1":
fib_t1_lag(
topo, ptf_ip, no_default_route=is_storage_backend, action=action)
module.exit_json(changed=True)
Expand Down
6 changes: 1 addition & 5 deletions tests/acl/test_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1321,8 +1321,7 @@ def post_setup_hook(self, dut, localhost, populate_vlan_arp_entries, tbinfo, con
"""
dut.command("config save -y")
up_bgp_neighbors = dut.get_bgp_neighbors_per_asic("established")
reboot(dut, localhost, safe_reboot=True, check_intf_up_ports=True)
reboot(dut, localhost, safe_reboot=True, check_intf_up_ports=True, wait_for_bgp=True)
# We need some additional delay on e1031
if dut.facts["platform"] == "x86_64-cel_e1031-r0":
time.sleep(240)
Expand All @@ -1338,9 +1337,6 @@ def post_setup_hook(self, dut, localhost, populate_vlan_arp_entries, tbinfo, con
assert result, "Not all transceivers are detected or interfaces are up in {} seconds".format(
MAX_WAIT_TIME_FOR_INTERFACES)

pytest_assert(
wait_until(300, 10, 0, dut.check_bgp_session_state_all_asics, up_bgp_neighbors, "established"),
"All BGP sessions are not up after reboot, no point in continuing the test")
# Delay 10 seconds for route convergence
time.sleep(10)

Expand Down
28 changes: 28 additions & 0 deletions tests/common/devices/multi_asic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from tests.common.devices.sonic_asic import SonicAsic
from tests.common.helpers.assertions import pytest_assert
from tests.common.helpers.constants import DEFAULT_ASIC_ID, DEFAULT_NAMESPACE, ASICS_PRESENT
from tests.common.platform.interface_utils import get_dut_interfaces_status

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -856,3 +857,30 @@ def ports_list(self):
"""
mg_facts = self.sonichost.minigraph_facts(host=self.sonichost.hostname)
return list(mg_facts['ansible_facts']['minigraph_ports'].keys())

def get_admin_up_ports(self):
intf_status = get_dut_interfaces_status(self.sonichost)
admin_up_ports = [k for k, v in intf_status.items() if v['admin'] == "up"]
return admin_up_ports

def shutdown_interface(self, port):
"""
This function works for both multi/single-asic dut
"""
logging.info("Shutting down {}".format(port))
if self.sonichost.is_multi_asic:
asic_ns = self.get_port_asic_instance(port).namespace
return self.command(f"sudo config interface -n {asic_ns} shutdown {port}")
else:
return self.command(f"sudo config interface shutdown {port}")

def no_shutdown_interface(self, port):
"""
This function works for both multi/single-asic dut
"""
logging.info("Bring up {}".format(port))
if self.sonichost.is_multi_asic:
asic_ns = self.get_port_asic_instance(port).namespace
return self.command(f"sudo config interface -n {asic_ns} startup {port}")
else:
return self.command(f"sudo config interface startup {port}")
14 changes: 7 additions & 7 deletions tests/common/dualtor/data_plane_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ def run_test(
return tor_IO


def cleanup(ptfadapter, duthosts_list):
print_logs(duthosts_list, print_dual_tor_logs=True)
def cleanup(ptfadapter, duthosts_list, ptfhost):
print_logs(duthosts_list, ptfhost, print_dual_tor_logs=True)
# cleanup torIO
ptfadapter.dataplane.flush()
for duthost in duthosts_list:
Expand Down Expand Up @@ -303,7 +303,7 @@ def t1_to_server_io_test(activehost, tor_vlan_port=None,

yield t1_to_server_io_test

cleanup(ptfadapter, duthosts)
cleanup(ptfadapter, duthosts, ptfhost)


@pytest.fixture
Expand Down Expand Up @@ -373,7 +373,7 @@ def server_to_t1_io_test(activehost, tor_vlan_port=None,

yield server_to_t1_io_test

cleanup(ptfadapter, duthosts)
cleanup(ptfadapter, duthosts, ptfhost)


@pytest.fixture
Expand Down Expand Up @@ -402,7 +402,7 @@ def soc_to_t1_io_test(activehost, tor_vlan_port=None,

yield soc_to_t1_io_test

cleanup(ptfadapter, duthosts)
cleanup(ptfadapter, duthosts, ptfhost)


@pytest.fixture
Expand Down Expand Up @@ -433,7 +433,7 @@ def t1_to_soc_io_test(activehost, tor_vlan_port=None,

yield t1_to_soc_io_test

cleanup(ptfadapter, duthosts)
cleanup(ptfadapter, duthosts, ptfhost)


@pytest.fixture
Expand Down Expand Up @@ -479,4 +479,4 @@ def server_to_server_io_test(activehost, test_mux_ports, delay=0,

yield server_to_server_io_test

cleanup(ptfadapter, duthosts)
cleanup(ptfadapter, duthosts, ptfhost)
6 changes: 6 additions & 0 deletions tests/common/platform/interface_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ def parse_intf_status(lines):
return result


def get_dut_interfaces_status(duthost):
output = duthost.command("show interface description")
intf_status = parse_intf_status(output["stdout_lines"][2:])
return intf_status


def check_interface_status_of_up_ports(duthost):
if duthost.facts['asic_type'] == 'vs' and duthost.is_supervisor_node():
return True
Expand Down
2 changes: 2 additions & 0 deletions tests/common/platform/transceiver_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import re
from copy import deepcopy

I2C_WAIT_TIME_AFTER_SFP_RESET = 5 # in seconds


def parse_transceiver_info(output_lines):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,18 @@ platform_tests/test_advanced_reboot.py::test_warm_reboot:
conditions:
- "asic_type in ['vs'] and 't0' not in topo_name"

platform_tests/test_advanced_reboot.py::test_warm_reboot_mac_jump:
skip:
reason: "Skip in PR testing as taking too much time."
conditions:
- "asic_type in ['vs']"

platform_tests/test_advanced_reboot.py::test_warm_reboot_sad:
skip:
reason: "Skip in PR testing as taking too much time."
conditions:
- "asic_type in ['vs']"

#######################################
##### test_cont_warm_reboot.py #####
#######################################
Expand Down
13 changes: 11 additions & 2 deletions tests/common/plugins/sanity_check/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _update_check_items(old_items, new_items, supported_items):
return updated_items


def print_logs(duthosts, print_dual_tor_logs=False):
def print_logs(duthosts, ptfhost, print_dual_tor_logs=False):
for dut in duthosts:
logger.info("Run commands to print logs")

Expand All @@ -90,6 +90,15 @@ def print_logs(duthosts, print_dual_tor_logs=False):
cmds.remove(constants.PRINT_LOGS['mux_status'])
cmds.remove(constants.PRINT_LOGS['mux_config'])

# check PTF device reachability
if ptfhost.mgmt_ip:
cmds.append("ping {} -c 1 -W 3".format(ptfhost.mgmt_ip))
cmds.append("traceroute {}".format(ptfhost.mgmt_ip))

if ptfhost.mgmt_ipv6:
cmds.append("ping6 {} -c 1 -W 3".format(ptfhost.mgmt_ipv6))
cmds.append("traceroute6 {}".format(ptfhost.mgmt_ipv6))

results = dut.shell_cmds(cmds=cmds, module_ignore_errors=True, verbose=False)['results']
outputs = []
for res in results:
Expand Down Expand Up @@ -285,7 +294,7 @@ def sanity_check_full(ptfhost, prepare_parallel_run, localhost, duthosts, reques
for item in set(pre_check_items):
request.fixturenames.append(item)
dual_tor = 'dualtor' in tbinfo['topo']['name']
print_logs(duthosts, print_dual_tor_logs=dual_tor)
print_logs(duthosts, ptfhost, print_dual_tor_logs=dual_tor)

check_results = do_checks(request, pre_check_items, stage=STAGE_PRE_TEST)
logger.debug("Pre-test sanity check results:\n%s" %
Expand Down
1 change: 1 addition & 0 deletions tests/common/port_toggle.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
logger = logging.getLogger(__name__)

BASE_PORT_COUNT = 28.0 # default t0 topology has 28 ports to toggle
WAIT_TIME_AFTER_INTF_SHUTDOWN = 5 # in seconds


def port_toggle(duthost, tbinfo, ports=None, wait_time_getter=None, wait_after_ports_up=60, watch=False):
Expand Down
13 changes: 11 additions & 2 deletions tests/common/reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def execute_reboot_helper():
def reboot(duthost, localhost, reboot_type='cold', delay=10,
timeout=0, wait=0, wait_for_ssh=True, wait_warmboot_finalizer=False, warmboot_finalizer_timeout=0,
reboot_helper=None, reboot_kwargs=None, return_after_reconnect=False,
safe_reboot=False, check_intf_up_ports=False):
safe_reboot=False, check_intf_up_ports=False, wait_for_bgp=False):
"""
reboots DUT
:param duthost: DUT host object
Expand All @@ -237,11 +237,13 @@ def reboot(duthost, localhost, reboot_type='cold', delay=10,
:param wait: time to wait for DUT to initialize
:param wait_for_ssh: Wait for SSH startup
:param return_after_reconnect: Return from function as soon as SSH reconnects
:param wait_warmboot_finalizer=True: Wait for WARMBOOT_FINALIZER done
:param wait_warmboot_finalizer: Wait for WARMBOOT_FINALIZER done
:param warmboot_finalizer_timeout: Timeout for waiting WARMBOOT_FINALIZER
:param reboot_helper: helper function to execute the power toggling
:param reboot_kwargs: arguments to pass to the reboot_helper
:param safe_reboot: arguments to wait DUT ready after reboot
:param check_intf_up_ports: arguments to check interface after reboot
:param wait_for_bgp: arguments to wait for BGP after reboot
:return:
"""
assert not (safe_reboot and return_after_reconnect)
Expand Down Expand Up @@ -351,6 +353,13 @@ def reboot(duthost, localhost, reboot_type='cold', delay=10,
assert float(dut_uptime.strftime("%s")) > float(dut_datetime.strftime("%s")), "Device {} did not reboot". \
format(hostname)

if wait_for_bgp:
bgp_neighbors = duthost.get_bgp_neighbors_per_asic(state="all")
pytest_assert(
wait_until(wait + 300, 10, 0, duthost.check_bgp_session_state_all_asics, bgp_neighbors),
"Not all bgp sessions are established after reboot",
)


def positive_uptime(duthost, dut_datetime):
dut_uptime = duthost.get_up_time()
Expand Down
2 changes: 1 addition & 1 deletion tests/common/testbed.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def _generate_sai_ptf_topo(self, tb_dict):

def get_testbed_type(self, topo_name):
pattern = re.compile(
r'^(wan|t0|t1|ptf|fullmesh|dualtor|ciscovs|t2|tgen|mgmttor|m0|mc0|mx|dpu|ptp)'
r'^(wan|t0|t1|ptf|fullmesh|dualtor|ciscovs|t2|tgen|mgmttor|m0|mc0|mx|dpu|ptp|smartswitch)'
)
match = pattern.match(topo_name)
if match is None:
Expand Down
5 changes: 4 additions & 1 deletion tests/fdb/test_fdb_mac_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from tests.ptf_runner import ptf_runner
from .utils import fdb_table_has_dummy_mac_for_interface
from tests.common.helpers.ptf_tests_helper import upstream_links # noqa F401
from tests.common.dualtor.mux_simulator_control import toggle_all_simulator_ports_to_rand_selected_tor_m # noqa F401


pytestmark = [
pytest.mark.topology('t0')
Expand Down Expand Up @@ -234,7 +236,8 @@ def bringup_uplink_ports(self, duthost, upstream_links): # noqa F811
duthost.shell("sudo config interface startup {}".format(uplink_intf))

def testFdbMacLearning(self, ptfadapter, duthosts, rand_one_dut_hostname, ptfhost, tbinfo, request, prepare_test,
upstream_links, setup_standby_ports_on_rand_unselected_tor_unconditionally): # noqa F811
upstream_links, setup_standby_ports_on_rand_unselected_tor_unconditionally, # noqa F811
toggle_all_simulator_ports_to_rand_selected_tor_m): # noqa F811
"""
TestFdbMacLearning verifies stale MAC entries are not present in MAC table after doing sonic-clear fdb all
-shut down all ports
Expand Down
54 changes: 54 additions & 0 deletions tests/gnmi/test_gnoi_system.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import pytest
import logging
import json

from .helper import gnoi_request
from tests.common.helpers.assertions import pytest_assert
import re

pytestmark = [
pytest.mark.topology('any')
]


"""
This module contains tests for the gNOI System API.
"""


def test_gnoi_system_time(duthosts, rand_one_dut_hostname, localhost):
"""
Verify the gNOI System Time API returns the current system time in valid JSON format.
"""
duthost = duthosts[rand_one_dut_hostname]

# Get current time
ret, msg = gnoi_request(duthost, localhost, "Time", "")
pytest_assert(ret == 0, "System.Time API reported failure (rc = {}) with message: {}".format(ret, msg))
logging.info("System.Time API returned msg: {}".format(msg))
# Message should contain a json substring like this {"time":1735921221909617549}
# Extract JSON part from the message
msg_json = extract_first_json_substring(msg)
if not msg_json:
pytest.fail("Failed to extract JSON from System.Time API response")
logging.info("Extracted JSON: {}".format(msg_json))
pytest_assert("time" in msg_json, "System.Time API did not return time")


def extract_first_json_substring(s):
"""
Extract the first JSON substring from a given string.
:param s: The input string containing JSON substring.
:return: The first JSON substring if found, otherwise None.
"""

json_pattern = re.compile(r'\{.*?\}')
match = json_pattern.search(s)
if match:
try:
return json.loads(match.group())
except json.JSONDecodeError:
logging.error("Failed to parse JSON: {}".format(match.group()))
return None
return None
2 changes: 1 addition & 1 deletion tests/ipfwd/test_nhop_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ def test_nhop_group_interface_flap(duthosts, enum_rand_one_per_hwsku_frontend_ho
gather_facts['src_port'][i])
logger.debug("Shut fanout sw: %s, port: %s", fanout, fanout_port)
if is_vs_device(duthost) is False:
fanout.no_shutdown(fanout_port)
fanout.shutdown(fanout_port)
nhop.add_ip_route(ip_prefix, ips)

nhop.program_routes()
Expand Down
Loading

0 comments on commit 7032718

Please sign in to comment.