Skip to content

Commit

Permalink
[dualtor][sanity] Restart mux simulator if sanity fails to get mux st…
Browse files Browse the repository at this point in the history
…atus (sonic-net#14884)

Signed-off-by: Longxiang <[email protected]>
  • Loading branch information
lolyu authored Oct 17, 2024
1 parent caa0ce1 commit 05bcfdd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
19 changes: 15 additions & 4 deletions tests/common/dualtor/mux_simulator_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
__all__ = [
'mux_server_info',
'restart_mux_simulator',
'restart_mux_simulator_session',
'mux_server_url',
'url',
'get_mux_status',
Expand Down Expand Up @@ -72,8 +73,14 @@ def mux_server_info(request, tbinfo):
return None, None, None


def _restart_mux_simulator(vmhost, vmset_name, ip, port):
if ip is not None and port is not None and vmset_name is not None:
vmhost.command('systemctl restart mux-simulator-{}'.format(port))
time.sleep(5)


@pytest.fixture(scope='session', autouse=True)
def restart_mux_simulator(mux_server_info, vmhost):
def restart_mux_simulator_session(mux_server_info, vmhost):
"""Session level fixture restart mux simulator server
For dualtor testbed, it would be better to restart the mux simulator server to ensure that it is running in a
Expand All @@ -86,9 +93,13 @@ def restart_mux_simulator(mux_server_info, vmhost):
vmhost (obj): The test server object.
"""
ip, port, vmset_name = mux_server_info
if ip is not None and port is not None and vmset_name is not None:
vmhost.command('systemctl restart mux-simulator-{}'.format(port))
time.sleep(5) # Wait for the mux simulator to initialize
_restart_mux_simulator(vmhost, vmset_name, ip, port)


@pytest.fixture(scope="module")
def restart_mux_simulator(mux_server_info, vmhost):
ip, port, vmset_name = mux_server_info
return lambda: _restart_mux_simulator(vmhost, vmset_name, ip, port)


@pytest.fixture(scope='session')
Expand Down
11 changes: 10 additions & 1 deletion tests/common/plugins/sanity_check/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from tests.common.utilities import wait, wait_until
from tests.common.dualtor.mux_simulator_control import get_mux_status, reset_simulator_port # noqa F401
from tests.common.dualtor.mux_simulator_control import restart_mux_simulator # noqa F401
from tests.common.dualtor.nic_simulator_control import restart_nic_simulator # noqa F401
from tests.common.dualtor.constants import UPPER_TOR, LOWER_TOR, NIC
from tests.common.dualtor.dual_tor_common import CableType, active_standby_ports # noqa F401
Expand Down Expand Up @@ -639,7 +640,7 @@ def _check_mux_status_helper():
@pytest.fixture(scope='module')
def check_mux_simulator(tbinfo, duthosts, duts_minigraph_facts, get_mux_status, # noqa F811
reset_simulator_port, restart_nic_simulator, # noqa F811
active_standby_ports): # noqa F811
restart_mux_simulator, active_standby_ports): # noqa F811
def _recover():
duthosts.shell('config muxcable mode auto all; config save -y')
if active_standby_ports:
Expand Down Expand Up @@ -678,6 +679,14 @@ def _check(*args, **kwargs):
return results

mux_simulator_status = get_mux_status()
if active_standby_ports and mux_simulator_status is None:
err_msg = "Failed to get mux status from mux simulator."
logger.warning(err_msg)
results['failed'] = True
results['failed_reason'] = err_msg
results['hosts'] = [dut.hostname for dut in duthosts]
results['action'] = restart_mux_simulator
return results
upper_tor_mux_status = duts_mux_status[duthosts[0].hostname]

for status in list(mux_simulator_status.values()):
Expand Down

0 comments on commit 05bcfdd

Please sign in to comment.