From 9a87e9ef1b8dc7105aa3ae1c55784827515f2ab3 Mon Sep 17 00:00:00 2001 From: Zhaohui Sun Date: Fri, 17 May 2024 06:59:30 +0000 Subject: [PATCH 1/4] Fix test_cacl failure on dualtor testbed Signed-off-by: Zhaohui Sun --- tests/generic_config_updater/test_cacl.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/generic_config_updater/test_cacl.py b/tests/generic_config_updater/test_cacl.py index b9a8e3fcd47..65924ec21f0 100644 --- a/tests/generic_config_updater/test_cacl.py +++ b/tests/generic_config_updater/test_cacl.py @@ -43,7 +43,7 @@ def get_iptable_rules(duthost): @pytest.fixture(autouse=True) -def setup_env(duthosts, rand_one_dut_hostname): +def setup_env(duthosts, rand_one_dut_hostname, tbinfo): """ Setup/teardown fixture for acl config Args: @@ -51,6 +51,13 @@ def setup_env(duthosts, rand_one_dut_hostname): rand_selected_dut: The fixture returns a randomly selected DuT. """ duthost = duthosts[rand_one_dut_hostname] + # Set mux mode to manual for dualtor testbed, + # in case that dualtor oscillation feature will toggle the port + # and cause iptables rules to change + if "dualtor" in tbinfo['topo']['name']: + for dut in duthosts: + dut.shell("sudo config mux mode manual all") + time.sleep(3) original_iptable_rules = get_iptable_rules(duthost) original_cacl_tables = get_cacl_tables(duthost) create_checkpoint(duthost) @@ -90,6 +97,10 @@ def setup_env(duthosts, rand_one_dut_hostname): ) finally: delete_checkpoint(duthost) + # change mux mode back to auto + if "dualtor" in tbinfo['topo']['name']: + for dut in duthosts: + dut.shell("sudo config mux mode manual all") def expect_acl_table_match(duthost, table_name, expected_content_list): From 54dd6e1e6801d521edffd3e0d1833dfe9e0c40c7 Mon Sep 17 00:00:00 2001 From: Zhaohui Sun Date: Fri, 17 May 2024 08:15:34 +0000 Subject: [PATCH 2/4] fix test_cacl_application Signed-off-by: Zhaohui Sun --- tests/cacl/test_cacl_application.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/cacl/test_cacl_application.py b/tests/cacl/test_cacl_application.py index 6df1fc743f9..69aaf71d446 100644 --- a/tests/cacl/test_cacl_application.py +++ b/tests/cacl/test_cacl_application.py @@ -28,9 +28,12 @@ def duthost_dualtor(request, upper_tor_host, lower_tor_host): # noqa F811 else: logger.info("Select upper tor...") dut = upper_tor_host - dut.shell("sudo config mux mode manual all") + # set mux mode to manual on both TORs to avoid port state change during test + upper_tor_host.shell("sudo config mux mode manual all") + lower_tor_host.shell("sudo config mux mode manual all") yield dut - dut.shell("sudo config mux mode auto all") + upper_tor_host.shell("sudo config mux mode auto all") + lower_tor_host.shell("sudo config mux mode auto all") @pytest.fixture From ff96e262c1aef41c34b16ce00ae495bedd3869c5 Mon Sep 17 00:00:00 2001 From: Zhaohui Sun Date: Fri, 17 May 2024 09:19:13 +0000 Subject: [PATCH 3/4] Introduce an autouse module fixture instead Signed-off-by: Zhaohui Sun --- tests/cacl/test_cacl_application.py | 19 +++++++++++++------ tests/generic_config_updater/test_cacl.py | 23 ++++++++++++----------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/tests/cacl/test_cacl_application.py b/tests/cacl/test_cacl_application.py index 69aaf71d446..78efab36960 100644 --- a/tests/cacl/test_cacl_application.py +++ b/tests/cacl/test_cacl_application.py @@ -17,6 +17,18 @@ ] +@pytest.fixture(scope="module", autouse=True) +def disable_port_toggle(duthosts, tbinfo): + # set mux mode to manual on both TORs to avoid port state change during test + if "dualtor" in tbinfo['topo']['name']: + for dut in duthosts: + dut.shell("sudo config mux mode manual all") + yield + if "dualtor" in tbinfo['topo']['name']: + for dut in duthosts: + dut.shell("sudo config mux mode auto all") + + @pytest.fixture(scope="function", params=["active_tor", "standby_tor"]) def duthost_dualtor(request, upper_tor_host, lower_tor_host): # noqa F811 which_tor = request.param @@ -28,12 +40,7 @@ def duthost_dualtor(request, upper_tor_host, lower_tor_host): # noqa F811 else: logger.info("Select upper tor...") dut = upper_tor_host - # set mux mode to manual on both TORs to avoid port state change during test - upper_tor_host.shell("sudo config mux mode manual all") - lower_tor_host.shell("sudo config mux mode manual all") - yield dut - upper_tor_host.shell("sudo config mux mode auto all") - lower_tor_host.shell("sudo config mux mode auto all") + return dut @pytest.fixture diff --git a/tests/generic_config_updater/test_cacl.py b/tests/generic_config_updater/test_cacl.py index 65924ec21f0..36cf60b5e9c 100644 --- a/tests/generic_config_updater/test_cacl.py +++ b/tests/generic_config_updater/test_cacl.py @@ -42,6 +42,18 @@ def get_iptable_rules(duthost): return rules_chain +@pytest.fixture(scope="module", autouse=True) +def disable_port_toggle(duthosts, tbinfo): + # set mux mode to manual on both TORs to avoid port state change during test + if "dualtor" in tbinfo['topo']['name']: + for dut in duthosts: + dut.shell("sudo config mux mode manual all") + yield + if "dualtor" in tbinfo['topo']['name']: + for dut in duthosts: + dut.shell("sudo config mux mode auto all") + + @pytest.fixture(autouse=True) def setup_env(duthosts, rand_one_dut_hostname, tbinfo): """ @@ -51,13 +63,6 @@ def setup_env(duthosts, rand_one_dut_hostname, tbinfo): rand_selected_dut: The fixture returns a randomly selected DuT. """ duthost = duthosts[rand_one_dut_hostname] - # Set mux mode to manual for dualtor testbed, - # in case that dualtor oscillation feature will toggle the port - # and cause iptables rules to change - if "dualtor" in tbinfo['topo']['name']: - for dut in duthosts: - dut.shell("sudo config mux mode manual all") - time.sleep(3) original_iptable_rules = get_iptable_rules(duthost) original_cacl_tables = get_cacl_tables(duthost) create_checkpoint(duthost) @@ -97,10 +102,6 @@ def setup_env(duthosts, rand_one_dut_hostname, tbinfo): ) finally: delete_checkpoint(duthost) - # change mux mode back to auto - if "dualtor" in tbinfo['topo']['name']: - for dut in duthosts: - dut.shell("sudo config mux mode manual all") def expect_acl_table_match(duthost, table_name, expected_content_list): From 6236e97b6159e760a8dbecbcc0524e408ef1969a Mon Sep 17 00:00:00 2001 From: Zhaohui Sun Date: Fri, 17 May 2024 09:30:41 +0000 Subject: [PATCH 4/4] Remove unused fixture Signed-off-by: Zhaohui Sun --- tests/generic_config_updater/test_cacl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/generic_config_updater/test_cacl.py b/tests/generic_config_updater/test_cacl.py index 36cf60b5e9c..5764bb01f2f 100644 --- a/tests/generic_config_updater/test_cacl.py +++ b/tests/generic_config_updater/test_cacl.py @@ -55,7 +55,7 @@ def disable_port_toggle(duthosts, tbinfo): @pytest.fixture(autouse=True) -def setup_env(duthosts, rand_one_dut_hostname, tbinfo): +def setup_env(duthosts, rand_one_dut_hostname): """ Setup/teardown fixture for acl config Args: