Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions tests/common/fixtures/duthost_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,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:
pytest_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:
pytest_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):
Expand Down
10 changes: 6 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2740,8 +2740,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):
Expand All @@ -2766,7 +2768,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

Expand All @@ -2776,7 +2778,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
Expand Down
14 changes: 9 additions & 5 deletions tests/pc/test_po_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down