From 2f2a41cec66a0cac1a0a835aaac419a82d037811 Mon Sep 17 00:00:00 2001 From: bingwang Date: Mon, 14 Sep 2020 00:32:32 -0700 Subject: [PATCH] Add an autouse fixture to disable and enable container autorestart. The autorestart of containers may hide errors in tests. This commit add an autouse fixture to disable and enable autouse feature. For module with marker enable_container_restart, this fixture is skipped. --- tests/conftest.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 76ebb65037b..f4d57b2c4d5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -427,3 +427,29 @@ def tag_test_report(request, pytestconfig, testbed, duthost, record_testsuite_pr record_testsuite_property("os_version", duthost.os_version) __report_metadata_added = True + +@pytest.fixture(scope="module", autouse=True) +def disable_container_autorestart(duthost, request): + skip = False + for m in request.node.iter_markers(): + if m.name == "enable_container_autorestart": + skip = True + break + if skip: + yield + return + container_autorestart_states = duthost.get_container_autorestart_states() + # Disable autorestart for all containers + logging.info("Disable container autorestart") + cmd_disable = "config feature autorestart {} disabled" + for name, state in container_autorestart_states.items(): + if state == "enabled": + duthost.command(cmd_disable.format(name)) + yield + # Recover autorestart states + logging.info("Recover container autorestart") + cmd_enable = "config feature autorestart {} enabled" + for name, state in container_autorestart_states.items(): + if state == "enabled": + duthost.command(cmd_enable.format(name)) +