diff --git a/tests/platform_tests/link_flap/conftest.py b/tests/platform_tests/link_flap/conftest.py index 1c71b8708bc..9f84096de5f 100644 --- a/tests/platform_tests/link_flap/conftest.py +++ b/tests/platform_tests/link_flap/conftest.py @@ -4,12 +4,6 @@ Teardowns used by the link flap tests. """ -import time - -import pytest - -from tests.platform_tests.link_flap.link_flap_utils import build_test_candidates - def pytest_addoption(parser): """ Adds options to pytest that are used by the Link flap tests. @@ -23,22 +17,3 @@ def pytest_addoption(parser): help="Orchagent CPU threshold", ) - -@pytest.fixture() -def bring_up_fanout_interfaces(request, duthosts, fanouthosts): - """ - Bring up outer interfaces on the DUT. - - Args: - request: pytest request object - duthosts: Fixture for interacting with the DUT list. - fanouthosts: Fixture for interacting with the fanouts. - """ - yield - if request.node.rep_call.failed: - for dut in duthosts: - candidates = build_test_candidates(dut, fanouthosts, "all_ports") - for _, fanout, fanout_port in candidates: - fanout.no_shutdown(fanout_port) - - time.sleep(60) diff --git a/tests/platform_tests/link_flap/link_flap_utils.py b/tests/platform_tests/link_flap/link_flap_utils.py index b39a4291b88..436fc49f589 100644 --- a/tests/platform_tests/link_flap/link_flap_utils.py +++ b/tests/platform_tests/link_flap/link_flap_utils.py @@ -129,16 +129,24 @@ def toggle_one_link(dut, dut_port, fanout, fanout_port, watch=False): pytest_assert(__check_if_status(dut, dut_port, 'up', verbose=True), "Fail: dut port {}: link operational down".format(dut_port)) logger.info("Shutting down fanout switch %s port %s connecting to %s", fanout.hostname, fanout_port, dut_port) - fanout.shutdown(fanout_port) - pytest_assert(wait_until(30, 1, __check_if_status, dut, dut_port, 'down', True), "dut port {} didn't go down as expected".format(dut_port)) - if watch: - time.sleep(1) - watch_system_status(dut) - - logger.info("Bring up fanout switch %s port %s connecting to %s", fanout.hostname, fanout_port, dut_port) - fanout.no_shutdown(fanout_port) - pytest_assert(wait_until(30, 1, __check_if_status, dut, dut_port, 'up', True), "dut port {} didn't go up as expected".format(dut_port)) + need_recovery = True + try: + fanout.shutdown(fanout_port) + pytest_assert(wait_until(30, 1, __check_if_status, dut, dut_port, 'down', True), "dut port {} didn't go down as expected".format(dut_port)) + + if watch: + time.sleep(1) + watch_system_status(dut) + + logger.info("Bring up fanout switch %s port %s connecting to %s", fanout.hostname, fanout_port, dut_port) + fanout.no_shutdown(fanout_port) + need_recovery = False + pytest_assert(wait_until(30, 1, __check_if_status, dut, dut_port, 'up', True), "dut port {} didn't go up as expected".format(dut_port)) + finally: + if need_recovery: + fanout.no_shutdown(fanout_port) + wait_until(30, 1, __check_if_status, dut, dut_port, 'up', True) def watch_system_status(dut): diff --git a/tests/platform_tests/link_flap/test_cont_link_flap.py b/tests/platform_tests/link_flap/test_cont_link_flap.py index 6f6cdaa1f80..d441b149745 100644 --- a/tests/platform_tests/link_flap/test_cont_link_flap.py +++ b/tests/platform_tests/link_flap/test_cont_link_flap.py @@ -10,7 +10,7 @@ import time import pytest -from tests.common.helpers.assertions import pytest_assert +from tests.common.helpers.assertions import pytest_assert, pytest_require from tests.common import port_toggle from tests.platform_tests.link_flap.link_flap_utils import build_test_candidates, toggle_one_link, check_orch_cpu_utilization, check_bgp_routes from tests.common.utilities import wait_until @@ -26,7 +26,7 @@ class TestContLinkFlap(object): TestContLinkFlap class for continuous link flap """ - def test_cont_link_flap(self, request, duthost, fanouthosts, bring_up_fanout_interfaces, bring_up_dut_interfaces): + def test_cont_link_flap(self, request, duthost, fanouthosts, bring_up_dut_interfaces): """ Validates that continuous link flap works as expected @@ -75,8 +75,7 @@ def test_cont_link_flap(self, request, duthost, fanouthosts, bring_up_fanout_int logging.info("%d Iteration flap all interfaces one by one on Peer Device", iteration + 1) candidates = build_test_candidates(duthost, fanouthosts, 'all_ports') - if not candidates: - pytest.skip("Didn't find any port that is admin up and present in the connection graph") + pytest_require(candidates, "Didn't find any port that is admin up and present in the connection graph") for dut_port, fanout, fanout_port in candidates: toggle_one_link(duthost, dut_port, fanout, fanout_port, watch=True) diff --git a/tests/platform_tests/link_flap/test_link_flap.py b/tests/platform_tests/link_flap/test_link_flap.py index cdca6855e4b..b12324eb8f2 100644 --- a/tests/platform_tests/link_flap/test_link_flap.py +++ b/tests/platform_tests/link_flap/test_link_flap.py @@ -49,7 +49,7 @@ def run_link_flap_test(self, dut, fanouthosts, port): @pytest.mark.platform('physical') -def test_link_flap(request, duthosts, enum_dut_portname, fanouthosts, bring_up_fanout_interfaces): +def test_link_flap(request, duthosts, enum_dut_portname, fanouthosts): """ Validates that link flap works as expected """