Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dualtor]: Make force_active_tor a fixture #3096

Merged
merged 3 commits into from
Mar 5, 2021
Merged
Changes from 1 commit
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
30 changes: 21 additions & 9 deletions tests/common/dualtor/dual_tor_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from tests.common.helpers.assertions import pytest_assert as pt_assert
from tests.common.helpers.dut_ports import encode_dut_port_name

__all__ = ['tor_mux_intf', 'ptf_server_intf', 't1_upper_tor_intfs', 't1_lower_tor_intfs', 'upper_tor_host', 'lower_tor_host']
__all__ = ['tor_mux_intf', 'ptf_server_intf', 't1_upper_tor_intfs', 't1_lower_tor_intfs', 'upper_tor_host', 'lower_tor_host', 'force_active_tor']

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -185,19 +185,31 @@ def update_mux_configs_and_config_reload(dut, state):
dut.file(path=TMP_FILE, state='absent')


def force_active_tor(dut, intf):
@pytest.fixture
def force_active_tor():
"""
@summary: Manually set dut host to the active tor for intf
@param dut: The duthost for which to toggle mux
@param intf: One or a list of names of interface or 'all' for all interfaces
"""
if type(intf) == str:
cmds = ["config muxcable mode active {}".format(intf)]
else:
cmds = []
for i in intf:
cmds.append("config muxcable mode active {}".format(i))
dut.shell_cmds(cmds=cmds)
forced_intfs = []
def _force_active_tor(dut, intf):
vaibhavhd marked this conversation as resolved.
Show resolved Hide resolved
if type(intf) == str:
cmds = ["config muxcable mode active {}; true".format(intf)]
forced_intfs.append((dut, intf))
else:
cmds = []
for i in intf:
forced_intfs.append((dut, i))
cmds.append("config muxcable mode active {}; true".format(i))
dut.shell_cmds(cmds=cmds, continue_on_fail=True)

yield _force_active_tor

if bool(forced_intfs):
vaibhavhd marked this conversation as resolved.
Show resolved Hide resolved
for x in forced_intfs:
x[0].shell("config muxcable mode auto {}; true".format(x[1]))



def _get_tor_fanouthosts(tor_host, fanouthosts):
Expand Down