From b228ece57bf0477c1cd5fa6d982f784e021bef3b Mon Sep 17 00:00:00 2001 From: Zhaohui Sun Date: Wed, 28 May 2025 06:14:46 +0000 Subject: [PATCH 1/3] Restore configuration after test in test_vxlan_crm Signed-off-by: Zhaohui Sun --- tests/vxlan/test_vxlan_crm.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/vxlan/test_vxlan_crm.py b/tests/vxlan/test_vxlan_crm.py index 1a7d8fe6349..892009d8d8a 100644 --- a/tests/vxlan/test_vxlan_crm.py +++ b/tests/vxlan/test_vxlan_crm.py @@ -2,7 +2,7 @@ import pytest import ipaddress from functools import reduce - +from tests.common.config_reload import config_reload 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 @@ -129,6 +129,14 @@ def fixture_setup_neighbors(setUp, encap_type, minigraph_facts): intf)) +@pytest.fixture(scope="module", autouse=True) +def restore_config_by_config_reload(setUp): + yield + duthost = setUp['duthost'] + + config_reload(duthost, safe_reload=True) + + class Test_VxLAN_Crm(Test_VxLAN): ''' Class for all testcases that verify Critical Resource Monitoring From 56b99c77cef8054c6d4bfda3a4d001c6093c10a3 Mon Sep 17 00:00:00 2001 From: Zhaohui Sun Date: Wed, 28 May 2025 07:39:26 +0000 Subject: [PATCH 2/3] move restore function to conftest.py Signed-off-by: Zhaohui Sun --- tests/vxlan/conftest.py | 10 ++++++++++ tests/vxlan/test_vxlan_crm.py | 10 +--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/vxlan/conftest.py b/tests/vxlan/conftest.py index 7a6697b7db9..46cf1f15b89 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__) @@ -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] + + config_reload(duthost, safe_reload=True) diff --git a/tests/vxlan/test_vxlan_crm.py b/tests/vxlan/test_vxlan_crm.py index 892009d8d8a..1a7d8fe6349 100644 --- a/tests/vxlan/test_vxlan_crm.py +++ b/tests/vxlan/test_vxlan_crm.py @@ -2,7 +2,7 @@ import pytest import ipaddress from functools import reduce -from tests.common.config_reload import config_reload + 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 @@ -129,14 +129,6 @@ def fixture_setup_neighbors(setUp, encap_type, minigraph_facts): intf)) -@pytest.fixture(scope="module", autouse=True) -def restore_config_by_config_reload(setUp): - yield - duthost = setUp['duthost'] - - config_reload(duthost, safe_reload=True) - - class Test_VxLAN_Crm(Test_VxLAN): ''' Class for all testcases that verify Critical Resource Monitoring From d19119b876909fea637f27e714db25fab31a1991 Mon Sep 17 00:00:00 2001 From: Zhaohui Sun Date: Thu, 29 May 2025 10:25:19 +0000 Subject: [PATCH 3/3] move restore function to conftest.py Signed-off-by: Zhaohui Sun --- tests/vxlan/conftest.py | 4 ++-- tests/vxlan/test_vxlan_bfd_tsa.py | 14 ++------------ tests/vxlan/test_vxlan_crm.py | 1 - tests/vxlan/test_vxlan_ecmp.py | 13 +------------ 4 files changed, 5 insertions(+), 27 deletions(-) diff --git a/tests/vxlan/conftest.py b/tests/vxlan/conftest.py index 46cf1f15b89..7645137f915 100644 --- a/tests/vxlan/conftest.py +++ b/tests/vxlan/conftest.py @@ -309,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: @@ -355,5 +355,5 @@ def vnet_config(minigraph_facts, vnet_test_params, scaled_vnet_params): 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]