diff --git a/tests/common/fixtures/duthost_utils.py b/tests/common/fixtures/duthost_utils.py index c60d0fa162b..383e03ce805 100755 --- a/tests/common/fixtures/duthost_utils.py +++ b/tests/common/fixtures/duthost_utils.py @@ -93,12 +93,31 @@ def backup_and_restore_config_db_session(duthosts): yield func -def stop_route_checker_on_duthost(duthost): +def _is_route_checker_in_status(duthost, expected_status_substrings): + """ + Check if routeCheck service status contains any expected substring. + """ + route_checker_status = duthost.get_monit_services_status().get("routeCheck", {}) + status = route_checker_status.get("service_status", "").lower() + return any(status_fragment in status for status_fragment in expected_status_substrings) + + +def stop_route_checker_on_duthost(duthost, wait_for_status=False): duthost.command("sudo monit stop routeCheck", module_ignore_errors=True) + if wait_for_status: + pt_assert( + wait_until(600, 15, 0, _is_route_checker_in_status, duthost, ("not monitored",)), + "routeCheck service did not stop on {}".format(duthost.hostname), + ) -def start_route_checker_on_duthost(duthost): +def start_route_checker_on_duthost(duthost, wait_for_status=False): duthost.command("sudo monit start routeCheck", module_ignore_errors=True) + if wait_for_status: + pt_assert( + wait_until(900, 20, 0, _is_route_checker_in_status, duthost, ("status ok",)), + "routeCheck service did not start on {}".format(duthost.hostname), + ) def _disable_route_checker(duthost): diff --git a/tests/conftest.py b/tests/conftest.py index 1b72e9d02b6..2537b8b16f8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3022,8 +3022,10 @@ def temporarily_disable_route_check(request, tbinfo, duthosts): check_flag = True break - if 't2' not in tbinfo['topo']['name']: - logger.info("Topology is not T2, skipping temporarily_disable_route_check fixture") + allowed_topologies = {"t2", "ut2", "lt2"} + topo_name = tbinfo['topo']['name'] + if check_flag and topo_name not in allowed_topologies: + logger.info("Topology {} is not allowed for temporarily_disable_route_check fixture".format(topo_name)) check_flag = False def wait_for_route_check_to_pass(dut): @@ -3048,7 +3050,7 @@ def run_route_check(): with SafeThreadPoolExecutor(max_workers=8) as executor: for duthost in duthosts.frontend_nodes: - executor.submit(stop_route_checker_on_duthost, duthost) + executor.submit(stop_route_checker_on_duthost, duthost, wait_for_status=True) yield @@ -3058,7 +3060,7 @@ def run_route_check(): finally: with SafeThreadPoolExecutor(max_workers=8) as executor: for duthost in duthosts.frontend_nodes: - executor.submit(start_route_checker_on_duthost, duthost) + executor.submit(start_route_checker_on_duthost, duthost, wait_for_status=True) else: logger.info("Skipping temporarily_disable_route_check fixture") yield diff --git a/tests/pc/test_po_cleanup.py b/tests/pc/test_po_cleanup.py index 907ad83281b..abaf08ff77c 100644 --- a/tests/pc/test_po_cleanup.py +++ b/tests/pc/test_po_cleanup.py @@ -2,6 +2,7 @@ import logging from tests.common.fixtures.duthost_utils import stop_route_checker_on_duthost +from tests.common.helpers.multi_thread_utils import SafeThreadPoolExecutor from tests.common.utilities import wait_until from tests.common import config_reload from tests.common.plugins.loganalyzer.loganalyzer import LogAnalyzer @@ -41,12 +42,15 @@ def ignore_expected_loganalyzer_exceptions(enum_rand_one_per_hwsku_frontend_host @pytest.fixture(autouse=True) def disable_route_check_for_duthost(tbinfo, duthosts, enum_rand_one_per_hwsku_frontend_hostname): - if 't2' not in tbinfo['topo']['name']: - logging.info("Topology is not T2, skipping disabling route check") + allowed_topologies = {"t2", "ut2", "lt2"} + topo_name = tbinfo['topo']['name'] + if topo_name in allowed_topologies: + logging.info("Stopping route check monitor before test case") + with SafeThreadPoolExecutor(max_workers=8) as executor: + for duthost in duthosts.frontend_nodes: + executor.submit(stop_route_checker_on_duthost, duthost, wait_for_status=True) else: - duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] - logging.info("Stopping route check on DUT {}".format(duthost.hostname)) - stop_route_checker_on_duthost(duthost) + logging.info("Topology {} is not allowed for disable_route_check_for_duthost fixture".format(topo_name)) yield