diff --git a/tests/vxlan/conftest.py b/tests/vxlan/conftest.py index 7a6697b7db9..7645137f915 100644 --- a/tests/vxlan/conftest.py +++ b/tests/vxlan/conftest.py @@ -20,6 +20,8 @@ NUM_INTF_PER_VNET_KEY, TEMPLATE_DIR ) +from tests.common.fixtures.duthost_utils import backup_and_restore_config_db_on_duts # noqa F401 +from tests.common.config_reload import config_reload logger = logging.getLogger(__name__) @@ -307,7 +309,7 @@ def vnet_test_params(duthost, request): @pytest.fixture(scope="module") -def minigraph_facts(duthosts, rand_one_dut_hostname, tbinfo): +def minigraph_facts(duthosts, rand_one_dut_hostname, tbinfo, backup_and_restore_config_db_on_duts): # noqa F811 """ Fixture to get minigraph facts Args: @@ -347,3 +349,11 @@ def vnet_config(minigraph_facts, vnet_test_params, scaled_vnet_params): return yaml.safe_load( safe_open_template( join(TEMPLATE_DIR, "vnet_config.j2")).render(combined_args)) + + +@pytest.fixture(scope="module", autouse=True) +def restore_config_by_config_reload(duthosts, rand_one_dut_hostname): + yield + duthost = duthosts[rand_one_dut_hostname] + logger.info("Restore config after running tests") + config_reload(duthost, safe_reload=True) diff --git a/tests/vxlan/test_vxlan_bfd_tsa.py b/tests/vxlan/test_vxlan_bfd_tsa.py index 9e704a509c0..8756716bd3d 100644 --- a/tests/vxlan/test_vxlan_bfd_tsa.py +++ b/tests/vxlan/test_vxlan_bfd_tsa.py @@ -16,7 +16,6 @@ from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # noqa F401 from tests.ptf_runner import ptf_runner from tests.common.vxlan_ecmp_utils import Ecmp_Utils -from tests.common.fixtures.duthost_utils import backup_and_restore_config_db_on_duts # noqa F401 from tests.common.config_reload import config_reload Logger = logging.getLogger(__name__) ecmp_utils = Ecmp_Utils() @@ -70,8 +69,7 @@ def fixture_setUp(duthosts, rand_one_dut_hostname, minigraph_facts, tbinfo, - encap_type, - backup_and_restore_config_db_on_duts): # noqa F811 + encap_type): ''' Setup for the entire script. The basic steps in VxLAN configs are: @@ -233,14 +231,6 @@ def fixture_setUp(duthosts, ecmp_utils.stop_bfd_responder(data['ptfhost']) -@pytest.fixture(scope="module", autouse=True) -def restore_config_by_config_reload(duthosts, rand_one_dut_hostname, localhost): - yield - duthost = duthosts[rand_one_dut_hostname] - - config_reload(duthost, safe_reload=True) - - def is_vnet_route_configured_on_asic(duthost, dest): ''' Function to check if a VNET route to dest is configured on ASIC DB. @@ -248,7 +238,7 @@ def is_vnet_route_configured_on_asic(duthost, dest): PTF tests. ''' result = duthost.shell(f"sonic-db-cli ASIC_DB KEYS \ - 'ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY*{dest}*'")["stdout_lines"] + 'ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY*{dest}*'")["stdout_lines"] # noqa: E231 return bool(result) diff --git a/tests/vxlan/test_vxlan_crm.py b/tests/vxlan/test_vxlan_crm.py index 1a7d8fe6349..83404e9e641 100644 --- a/tests/vxlan/test_vxlan_crm.py +++ b/tests/vxlan/test_vxlan_crm.py @@ -4,7 +4,6 @@ from functools import reduce from tests.common.helpers.assertions import pytest_assert -from tests.common.fixtures.duthost_utils import backup_and_restore_config_db_on_duts # noqa F401 from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # noqa: F401 from tests.common.vxlan_ecmp_utils import Ecmp_Utils from tests.vxlan.test_vxlan_ecmp import ( # noqa: F401 diff --git a/tests/vxlan/test_vxlan_ecmp.py b/tests/vxlan/test_vxlan_ecmp.py index 0c1acca8045..cc488ab84d9 100644 --- a/tests/vxlan/test_vxlan_ecmp.py +++ b/tests/vxlan/test_vxlan_ecmp.py @@ -60,8 +60,6 @@ from tests.common.helpers.assertions import pytest_assert from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # noqa F401 -from tests.common.fixtures.duthost_utils import backup_and_restore_config_db_on_duts # noqa F401 -from tests.common.config_reload import config_reload from tests.common.utilities import wait_until from tests.ptf_runner import ptf_runner from tests.common.vxlan_ecmp_utils import Ecmp_Utils @@ -142,8 +140,7 @@ def fixture_setUp(duthosts, rand_one_dut_hostname, minigraph_facts, tbinfo, - encap_type, - backup_and_restore_config_db_on_duts): # noqa F811 + encap_type): # noqa F811 ''' Setup for the entire script. The basic steps in VxLAN configs are: @@ -342,14 +339,6 @@ def fixture_setUp(duthosts, setup_crm_interval(data['duthost'], int(data['original_crm_interval'])) -@pytest.fixture(scope="module", autouse=True) -def restore_config_by_config_reload(duthosts, rand_one_dut_hostname, localhost): - yield - duthost = duthosts[rand_one_dut_hostname] - - config_reload(duthost, safe_reload=True) - - @pytest.fixture(scope="module") def default_routes(setUp, encap_type): vnet = list(setUp[encap_type]['vnet_vni_map'].keys())[0]