Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
6 changes: 6 additions & 0 deletions tests/common/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -2358,6 +2358,12 @@ def get_vtysh_cmd_for_namespace(self, cmd, namespace):
ns_cmd = cmd.replace('vtysh', 'vtysh -n {}'.format(asic_id))
return ns_cmd

def get_linux_ip_cmd_for_namespace(self, cmd, namespace):
if not namespace:
return cmd
ns_cmd = cmd.replace('ip', 'ip -n {}'.format(namespace))
return ns_cmd

def __getattr__(self, attr):
""" To support calling an ansible module on a MultiAsicSonicHost.

Expand Down
46 changes: 24 additions & 22 deletions tests/pc/test_po_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,38 @@ def ignore_expected_loganalyzer_exceptions(rand_one_dut_hostname, loganalyzer):
]
loganalyzer[rand_one_dut_hostname].ignore_regex.extend(ignoreRegex)
expectRegex = [
".*teamd#teammgrd: :- cleanTeamProcesses.*",
".*teamd#teamsyncd: :- cleanTeamSync.*"
".*teammgrd: :- cleanTeamProcesses.*",
".*teamsyncd: :- cleanTeamSync.*"
]
loganalyzer[rand_one_dut_hostname].expect_regex.extend(expectRegex)


def check_kernel_po_interface_cleaned(duthost):
res = duthost.shell("ip link show | grep -c PortChannel", module_ignore_errors=True)["stdout_lines"][0].decode("utf-8")
def check_kernel_po_interface_cleaned(duthost, asic_index):
namespace = duthost.get_namespace_from_asic_id(asic_index)
res = duthost.shell(duthost.get_linux_ip_cmd_for_namespace("ip link show | grep -c PortChannel", namespace),module_ignore_errors=True)["stdout_lines"][0].decode("utf-8")
return res == '0'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine but would be good to generalize by overriding "shell" (similar to command) in sonic_asic.py and use something like the following. Up to you.

duthost.asic_instance(enum_asic_index).shell(ip link show | grep -c PortChannel", module_ignore_errors=True)



def test_po_cleanup(duthosts, rand_one_dut_hostname, tbinfo):
"""
test port channel are cleaned up correctly and teammgrd and teamsyncd process
handle SIGTERM gracefully
"""
@pytest.fixture(scope="module", autouse=True)
def disable_teamd(duthosts, rand_one_dut_hostname, tbinfo):

duthost = duthosts[rand_one_dut_hostname]
mg_facts = duthost.get_extended_minigraph_facts(tbinfo)

if len(mg_facts['minigraph_portchannels'].keys()) == 0:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would need to check this per namespace/asic_index now ? as the test_po_cleanup is run per asic

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@judyjoseph updated.
Will still check only once and not per asic and for multi-asic it will always run as backend is always port-channel.

pytest.skip("Skip test due to there is no portchannel exists in current topology.")
yield
# Do config reload to restor everything back
logging.info("Reloading config..")
config_reload(duthost)

try:
logging.info("Disable Teamd Feature")
duthost.shell("sudo systemctl stop teamd")
# Check if Linux Kernel Portchannel Interface teamdev are clean up
if not wait_until(10, 1, check_kernel_po_interface_cleaned, duthost):
fail_msg = "PortChannel interface still exists in kernel"
pytest.fail(fail_msg)
finally:
# Do config reload to restor everything back
logging.info("Reloading config..")
config_reload(duthost)
def test_po_cleanup(duthosts, rand_one_dut_hostname, enum_asic_index):
"""
test port channel are cleaned up correctly and teammgrd and teamsyncd process
handle SIGTERM gracefully
"""
duthost = duthosts[rand_one_dut_hostname]
logging.info("Disable Teamd Feature")
duthost.shell("sudo systemctl stop swss{}".format('@' + str(enum_asic_index) if enum_asic_index is not None else ''))
# Check if Linux Kernel Portchannel Interface teamdev are clean up
if not wait_until(10, 1, check_kernel_po_interface_cleaned, duthost, enum_asic_index):
fail_msg = "PortChannel interface still exists in kernel"
pytest.fail(fail_msg)