From 29d02e3b654d5ff459b165fb1744cd8dc8acbf17 Mon Sep 17 00:00:00 2001 From: echuawu Date: Tue, 24 Dec 2024 11:33:43 +0800 Subject: [PATCH] Update generic hash test to support dualtor active active topology Update generic hash test to support dualtor active active topology Change-Id: Ifc2b7d3b4af237f779c7f95c90a673e5bee574f9 --- tests/hash/test_generic_hash.py | 222 +++++++++++++++++--------------- 1 file changed, 115 insertions(+), 107 deletions(-) diff --git a/tests/hash/test_generic_hash.py b/tests/hash/test_generic_hash.py index 71d5a0e38b6..4f1e900e586 100644 --- a/tests/hash/test_generic_hash.py +++ b/tests/hash/test_generic_hash.py @@ -19,6 +19,7 @@ from tests.common.reboot import reboot from tests.common.config_reload import config_reload from tests.common.plugins.allure_wrapper import allure_step_wrapper as allure +from tests.common.dualtor.dual_tor_utils import toggle_all_aa_ports_to_rand_selected_tor # noqa F401 DEFAULT_VXLAN_PORT = 4789 PTF_LOG_PATH = "/tmp/generic_hash_test.GenericHashTest.log" @@ -129,12 +130,12 @@ def test_hash_capability(duthost, global_hash_capabilities): # noqa:F811 'The lag hash capability is not as expected.') -def test_ecmp_hash(duthost, tbinfo, ptfhost, fine_params, mg_facts, global_hash_capabilities, # noqa:F811 - restore_vxlan_port, toggle_all_simulator_ports_to_upper_tor): # noqa:F811 +def test_ecmp_hash(rand_selected_dut, tbinfo, ptfhost, fine_params, mg_facts, global_hash_capabilities, # noqa:F811 + restore_vxlan_port, toggle_all_aa_ports_to_rand_selected_tor): # noqa:F811 """ Test case to validate the ecmp hash. The hash field to test is randomly chosen from the supported hash fields. Args: - duthost (AnsibleHost): Device Under Test (DUT) + rand_selected_dut (AnsibleHost): Device Under Test (DUT) ptfhost (AnsibleHost): Packet Test Framework (PTF) mg_facts: minigraph facts hash_algorithm: randomly generated hash algorithm @@ -152,26 +153,27 @@ def test_ecmp_hash(duthost, tbinfo, ptfhost, fine_params, mg_facts, global_hash_ lag_hash_fields = lag_hash_fields[:] lag_hash_fields.remove(ecmp_test_hash_field) if ecmp_test_hash_field in lag_hash_fields else None # Config the hash fields - duthost.set_switch_hash_global('ecmp', [ecmp_test_hash_field]) - duthost.set_switch_hash_global('lag', lag_hash_fields) + rand_selected_dut.set_switch_hash_global('ecmp', [ecmp_test_hash_field]) + rand_selected_dut.set_switch_hash_global('lag', lag_hash_fields) with allure.step(f'Configure ecmp hash algorithm: {hash_algorithm}'): - duthost.set_switch_hash_global_algorithm('ecmp', hash_algorithm) + rand_selected_dut.set_switch_hash_global_algorithm('ecmp', hash_algorithm) with allure.step("Check the config result"): check_global_hash_config( - duthost, ecmp_hash_fields=[ecmp_test_hash_field], lag_hash_fields=lag_hash_fields) - check_global_hash_algorithm(duthost, hash_algorithm) + rand_selected_dut, ecmp_hash_fields=[ecmp_test_hash_field], lag_hash_fields=lag_hash_fields) + check_global_hash_algorithm(rand_selected_dut, hash_algorithm) with allure.step('Prepare test parameters'): # Get the interfaces for the test, downlink interface is selected randomly - uplink_interfaces, downlink_interfaces = get_interfaces_for_test(duthost, mg_facts, ecmp_test_hash_field) + uplink_interfaces, downlink_interfaces = get_interfaces_for_test(rand_selected_dut, mg_facts, + ecmp_test_hash_field) ptf_params = generate_test_params( - duthost, tbinfo, mg_facts, ecmp_test_hash_field, ipver, inner_ipver, encap_type, uplink_interfaces, - downlink_interfaces, ecmp_hash=True, lag_hash=False) + rand_selected_dut, tbinfo, mg_facts, ecmp_test_hash_field, ipver, inner_ipver, encap_type, + uplink_interfaces, downlink_interfaces, ecmp_hash=True, lag_hash=False) if ptf_params.get('vxlan_port') and ptf_params['vxlan_port'] != DEFAULT_VXLAN_PORT: - config_custom_vxlan_port(duthost, ptf_params['vxlan_port']) + config_custom_vxlan_port(rand_selected_dut, ptf_params['vxlan_port']) with allure.step('Start the ptf test, send traffic and check the balancing'): # Check the default route before the ptf test - pytest_assert(check_default_route(duthost, uplink_interfaces.keys()), + pytest_assert(check_default_route(rand_selected_dut, uplink_interfaces.keys()), 'The default route is not available or some nexthops are missing.') ptf_runner( ptfhost, @@ -186,14 +188,13 @@ def test_ecmp_hash(duthost, tbinfo, ptfhost, fine_params, mg_facts, global_hash_ ) -def test_lag_hash(duthost, ptfhost, tbinfo, fine_params, mg_facts, restore_configuration, # noqa:F811 - restore_vxlan_port, global_hash_capabilities, # noqa F811 - toggle_all_simulator_ports_to_upper_tor): # noqa:F811 +def test_lag_hash(rand_selected_dut, ptfhost, tbinfo, fine_params, mg_facts, restore_configuration, # noqa:F811 + restore_vxlan_port, global_hash_capabilities, toggle_all_aa_ports_to_rand_selected_tor): # noqa:F811 """ Test case to validate the lag hash. The hash field to test is randomly chosen from the supported hash fields. When hash field is in [DST_MAC, ETHERTYPE, VLAN_ID], need to re-configure the dut for L2 traffic. Args: - duthost (AnsibleHost): Device Under Test (DUT) + rand_selected_dut (AnsibleHost): Device Under Test (DUT) ptfhost (AnsibleHost): Packet Test Framework (PTF) mg_facts: minigraph facts tbinfo: testbed info fixture @@ -212,18 +213,19 @@ def test_lag_hash(duthost, ptfhost, tbinfo, fine_params, mg_facts, restore_confi ecmp_hash_fields = ecmp_hash_fields[:] ecmp_hash_fields.remove(lag_test_hash_field) if lag_test_hash_field in ecmp_hash_fields else None # Get the interfaces for the test, downlink interface is selected randomly - uplink_interfaces, downlink_interfaces = get_interfaces_for_test(duthost, mg_facts, lag_test_hash_field) + uplink_interfaces, downlink_interfaces = get_interfaces_for_test(rand_selected_dut, mg_facts, + lag_test_hash_field) # If the uplinks are not multi-member portchannels, skip the test skip_single_member_lag_topology(uplink_interfaces, lag_test_hash_field, encap_type) # Config the hash fields - duthost.set_switch_hash_global('ecmp', ecmp_hash_fields) - duthost.set_switch_hash_global('lag', [lag_test_hash_field]) + rand_selected_dut.set_switch_hash_global('ecmp', ecmp_hash_fields) + rand_selected_dut.set_switch_hash_global('lag', [lag_test_hash_field]) with allure.step(f'Configure lag hash algorithm: {hash_algorithm}'): - duthost.set_switch_hash_global_algorithm('lag', hash_algorithm) + rand_selected_dut.set_switch_hash_global_algorithm('lag', hash_algorithm) with allure.step("Check the config result"): check_global_hash_config( - duthost, ecmp_hash_fields=ecmp_hash_fields, lag_hash_fields=[lag_test_hash_field]) - check_global_hash_algorithm(duthost, lag_hash_algo=hash_algorithm) + rand_selected_dut, ecmp_hash_fields=ecmp_hash_fields, lag_hash_fields=[lag_test_hash_field]) + check_global_hash_algorithm(rand_selected_dut, lag_hash_algo=hash_algorithm) with allure.step('Change topology for L2 test if hash field in DST_MAC, ETHERTYPE, VLAN_ID'): # Need to send l2 traffic to validate SRC_MAC, DST_MAC, ETHERTYPE, VLAN_ID keys, changing topology is required is_l2_test = False @@ -233,17 +235,17 @@ def test_lag_hash(duthost, ptfhost, tbinfo, fine_params, mg_facts, restore_confi for _ in range(len(uplink_interfaces) - 1): uplink_interfaces.popitem() remove_ip_interface_and_config_vlan( - duthost, mg_facts, tbinfo, downlink_interfaces[0], uplink_interfaces, lag_test_hash_field) + rand_selected_dut, mg_facts, tbinfo, downlink_interfaces[0], uplink_interfaces, lag_test_hash_field) with allure.step('Prepare test parameters'): ptf_params = generate_test_params( - duthost, tbinfo, mg_facts, lag_test_hash_field, ipver, inner_ipver, encap_type, uplink_interfaces, + rand_selected_dut, tbinfo, mg_facts, lag_test_hash_field, ipver, inner_ipver, encap_type, uplink_interfaces, downlink_interfaces, ecmp_hash=False, lag_hash=True, is_l2_test=is_l2_test) if ptf_params.get('vxlan_port') and ptf_params['vxlan_port'] != DEFAULT_VXLAN_PORT: - config_custom_vxlan_port(duthost, ptf_params['vxlan_port']) + config_custom_vxlan_port(rand_selected_dut, ptf_params['vxlan_port']) with allure.step('Start the ptf test, send traffic and check the balancing'): # Check the default route before the ptf test if not is_l2_test: - pytest_assert(check_default_route(duthost, uplink_interfaces.keys()), + pytest_assert(check_default_route(rand_selected_dut, uplink_interfaces.keys()), 'The default route is not available or some nexthops are missing.') ptf_runner( ptfhost, @@ -268,14 +270,14 @@ def config_all_hash_algorithm(duthost, ecmp_algorithm, lag_algorithm): # noqa:F duthost.set_switch_hash_global_algorithm('lag', lag_algorithm) -def test_ecmp_and_lag_hash(duthost, tbinfo, ptfhost, fine_params, mg_facts, global_hash_capabilities, # noqa:F811 - restore_vxlan_port, get_supported_hash_algorithms, # noqa:F811 - toggle_all_simulator_ports_to_upper_tor): # noqa:F811 +def test_ecmp_and_lag_hash(rand_selected_dut, tbinfo, ptfhost, fine_params, mg_facts, # noqa:F811 + global_hash_capabilities, restore_vxlan_port, get_supported_hash_algorithms, # noqa:F811 + toggle_all_aa_ports_to_rand_selected_tor): # noqa:F811 """ Test case to validate the hash behavior when both ecmp and lag hash are configured with a same field. The hash field to test is randomly chosen from the supported hash fields. Args: - duthost (AnsibleHost): Device Under Test (DUT) + rand_selected_dut (AnsibleHost): Device Under Test (DUT) ptfhost (AnsibleHost): Packet Test Framework (PTF) mg_facts: minigraph facts ecmp_algorithm: randomly generated ecmp hash algorithm @@ -290,24 +292,25 @@ def test_ecmp_and_lag_hash(duthost, tbinfo, ptfhost, fine_params, mg_facts, glob skip_unsupported_field_for_ecmp_test(ecmp_test_hash_field, encap_type) with allure.step('Randomly select an ecmp hash field to test ' 'and configure all supported fields to the global ecmp and lag hash'): - config_all_hash_fields(duthost, global_hash_capabilities) + config_all_hash_fields(rand_selected_dut, global_hash_capabilities) lag_algorithm = get_diff_hash_algorithm(ecmp_algorithm, get_supported_hash_algorithms) with allure.step(f'Configure ecmp hash algorithm: {ecmp_algorithm} - lag hash algorithm: {lag_algorithm}'): - config_all_hash_algorithm(duthost, ecmp_algorithm, lag_algorithm) + config_all_hash_algorithm(rand_selected_dut, ecmp_algorithm, lag_algorithm) with allure.step("Check the config result"): - check_global_hash_config(duthost, global_hash_capabilities['ecmp'], global_hash_capabilities['lag']) - check_global_hash_algorithm(duthost, ecmp_algorithm, lag_algorithm) + check_global_hash_config(rand_selected_dut, global_hash_capabilities['ecmp'], global_hash_capabilities['lag']) + check_global_hash_algorithm(rand_selected_dut, ecmp_algorithm, lag_algorithm) with allure.step('Prepare test parameters'): # Get the interfaces for the test, downlink interface is selected randomly - uplink_interfaces, downlink_interfaces = get_interfaces_for_test(duthost, mg_facts, ecmp_test_hash_field) + uplink_interfaces, downlink_interfaces = get_interfaces_for_test(rand_selected_dut, mg_facts, + ecmp_test_hash_field) ptf_params = generate_test_params( - duthost, tbinfo, mg_facts, ecmp_test_hash_field, ipver, inner_ipver, encap_type, uplink_interfaces, - downlink_interfaces, ecmp_hash=True, lag_hash=True) + rand_selected_dut, tbinfo, mg_facts, ecmp_test_hash_field, ipver, inner_ipver, encap_type, + uplink_interfaces, downlink_interfaces, ecmp_hash=True, lag_hash=True) if ptf_params.get('vxlan_port') and ptf_params['vxlan_port'] != DEFAULT_VXLAN_PORT: - config_custom_vxlan_port(duthost, ptf_params['vxlan_port']) + config_custom_vxlan_port(rand_selected_dut, ptf_params['vxlan_port']) with allure.step('Start the ptf test, send traffic and check the balancing'): # Check the default route before the ptf test - pytest_assert(check_default_route(duthost, uplink_interfaces.keys()), + pytest_assert(check_default_route(rand_selected_dut, uplink_interfaces.keys()), 'The default route is not available or some nexthops are missing.') ptf_runner( ptfhost, @@ -322,14 +325,14 @@ def test_ecmp_and_lag_hash(duthost, tbinfo, ptfhost, fine_params, mg_facts, glob ) -def test_nexthop_flap(duthost, tbinfo, ptfhost, fine_params, mg_facts, restore_interfaces, # noqa:F811 - restore_vxlan_port, global_hash_capabilities, get_supported_hash_algorithms, # noqa:F811 - toggle_all_simulator_ports_to_upper_tor): # noqa:F811 +def test_nexthop_flap(rand_selected_dut, tbinfo, ptfhost, fine_params, mg_facts, restore_interfaces, # noqa:F811 + restore_vxlan_port, global_hash_capabilities, get_supported_hash_algorithms, # noqa:F811 + toggle_all_aa_ports_to_rand_selected_tor): # noqa:F811 """ Test case to validate the ecmp hash when there is nexthop flapping. The hash field to test is randomly chosen from the supported hash fields. Args: - duthost (AnsibleHost): Device Under Test (DUT) + rand_selected_dut (AnsibleHost): Device Under Test (DUT) ptfhost (AnsibleHost): Packet Test Framework (PTF) mg_facts: minigraph facts restore_interfaces: fixture to restore the interfaces used in the test @@ -345,24 +348,25 @@ def test_nexthop_flap(duthost, tbinfo, ptfhost, fine_params, mg_facts, restore_i skip_unsupported_field_for_ecmp_test(ecmp_test_hash_field, encap_type) with allure.step('Randomly select an ecmp hash field to test ' 'and configure all supported fields to the global ecmp and lag hash'): - config_all_hash_fields(duthost, global_hash_capabilities) + config_all_hash_fields(rand_selected_dut, global_hash_capabilities) lag_algorithm = get_diff_hash_algorithm(ecmp_algorithm, get_supported_hash_algorithms) with allure.step(f'Configure ecmp hash algorithm: {ecmp_algorithm} - lag hash algorithm: {lag_algorithm}'): - config_all_hash_algorithm(duthost, ecmp_algorithm, lag_algorithm) + config_all_hash_algorithm(rand_selected_dut, ecmp_algorithm, lag_algorithm) with allure.step("Check the config result"): - check_global_hash_config(duthost, global_hash_capabilities['ecmp'], global_hash_capabilities['lag']) - check_global_hash_algorithm(duthost, ecmp_algorithm, lag_algorithm) + check_global_hash_config(rand_selected_dut, global_hash_capabilities['ecmp'], global_hash_capabilities['lag']) + check_global_hash_algorithm(rand_selected_dut, ecmp_algorithm, lag_algorithm) with allure.step('Prepare test parameters'): # Get the interfaces for the test, downlink interface is selected randomly - uplink_interfaces, downlink_interfaces = get_interfaces_for_test(duthost, mg_facts, ecmp_test_hash_field) + uplink_interfaces, downlink_interfaces = get_interfaces_for_test(rand_selected_dut, mg_facts, + ecmp_test_hash_field) ptf_params = generate_test_params( - duthost, tbinfo, mg_facts, ecmp_test_hash_field, ipver, inner_ipver, encap_type, uplink_interfaces, - downlink_interfaces, ecmp_hash=True, lag_hash=True) + rand_selected_dut, tbinfo, mg_facts, ecmp_test_hash_field, ipver, inner_ipver, encap_type, + uplink_interfaces, downlink_interfaces, ecmp_hash=True, lag_hash=True) if ptf_params.get('vxlan_port') and ptf_params['vxlan_port'] != DEFAULT_VXLAN_PORT: - config_custom_vxlan_port(duthost, ptf_params['vxlan_port']) + config_custom_vxlan_port(rand_selected_dut, ptf_params['vxlan_port']) with allure.step('Start the ptf test, send traffic and check the balancing'): # Check the default route before the ptf test - pytest_assert(check_default_route(duthost, uplink_interfaces.keys()), + pytest_assert(check_default_route(rand_selected_dut, uplink_interfaces.keys()), 'The default route is not available or some nexthops are missing.') ptf_runner( ptfhost, @@ -382,7 +386,7 @@ def test_nexthop_flap(duthost, tbinfo, ptfhost, fine_params, mg_facts, restore_i origin_ptf_expected_port_groups = ptf_params['expected_port_groups'] _, ptf_params['expected_port_groups'] = get_ptf_port_indices( mg_facts, downlink_interfaces=[], uplink_interfaces=remaining_uplink_interfaces) - shutdown_interface(duthost, interface) + shutdown_interface(rand_selected_dut, interface) with allure.step('Start the ptf test, send traffic and check the balancing'): ptf_runner( ptfhost, @@ -396,9 +400,9 @@ def test_nexthop_flap(duthost, tbinfo, ptfhost, fine_params, mg_facts, restore_i is_python3=True ) with allure.step('Startup the interface, and then flap it 3 more times'): - startup_interface(duthost, interface) - flap_interfaces(duthost, [interface], times=3) - pytest_assert(wait_until(10, 2, 0, check_default_route, duthost, uplink_interfaces.keys()), + startup_interface(rand_selected_dut, interface) + flap_interfaces(rand_selected_dut, [interface], times=3) + pytest_assert(wait_until(10, 2, 0, check_default_route, rand_selected_dut, uplink_interfaces.keys()), 'The default route is not restored after the flapping.') ptf_params['expected_port_groups'] = origin_ptf_expected_port_groups with allure.step('Start the ptf test, send traffic and check the balancing'): @@ -415,15 +419,15 @@ def test_nexthop_flap(duthost, tbinfo, ptfhost, fine_params, mg_facts, restore_i ) -def test_lag_member_flap(duthost, tbinfo, ptfhost, fine_params, mg_facts, restore_configuration, # noqa F811 - restore_interfaces, global_hash_capabilities, restore_vxlan_port, # noqa F811 - get_supported_hash_algorithms, toggle_all_simulator_ports_to_upper_tor): # noqa F811 +def test_lag_member_flap(rand_selected_dut, tbinfo, ptfhost, fine_params, mg_facts, restore_configuration, # noqa:F811 + restore_interfaces, global_hash_capabilities, restore_vxlan_port, # noqa:F811 + get_supported_hash_algorithms, toggle_all_aa_ports_to_rand_selected_tor): # noqa:F811 """ Test case to validate the lag hash when there is lag member flapping. The hash field to test is randomly chosen from the supported hash fields. When hash field is in [DST_MAC, ETHERTYPE, VLAN_ID], need to re-configure the dut for L2 traffic. Args: - duthost (AnsibleHost): Device Under Test (DUT) + rand_selected_dut (AnsibleHost): Device Under Test (DUT) ptfhost (AnsibleHost): Packet Test Framework (PTF) tbinfo: testbed info fixture mg_facts: minigraph facts @@ -441,16 +445,17 @@ def test_lag_member_flap(duthost, tbinfo, ptfhost, fine_params, mg_facts, restor with allure.step('Randomly select an lag hash field to test ' 'and configure all supported fields to the global ecmp and lag hash'): # Get the interfaces for the test, downlink interface is selected randomly - uplink_interfaces, downlink_interfaces = get_interfaces_for_test(duthost, mg_facts, lag_test_hash_field) + uplink_interfaces, downlink_interfaces = get_interfaces_for_test(rand_selected_dut, mg_facts, + lag_test_hash_field) # If the uplinks are not multi-member portchannels, skip the test skip_single_member_lag_topology(uplink_interfaces, lag_test_hash_field, encap_type) - config_all_hash_fields(duthost, global_hash_capabilities) + config_all_hash_fields(rand_selected_dut, global_hash_capabilities) lag_algorithm = get_diff_hash_algorithm(ecmp_algorithm, get_supported_hash_algorithms) with allure.step(f'Configure ecmp hash algorithm: {ecmp_algorithm} - lag hash algorithm: {lag_algorithm}'): - config_all_hash_algorithm(duthost, ecmp_algorithm, lag_algorithm) + config_all_hash_algorithm(rand_selected_dut, ecmp_algorithm, lag_algorithm) with allure.step("Check the config result"): - check_global_hash_config(duthost, global_hash_capabilities['ecmp'], global_hash_capabilities['lag']) - check_global_hash_algorithm(duthost, ecmp_algorithm, lag_algorithm) + check_global_hash_config(rand_selected_dut, global_hash_capabilities['ecmp'], global_hash_capabilities['lag']) + check_global_hash_algorithm(rand_selected_dut, ecmp_algorithm, lag_algorithm) with allure.step('Change topology for L2 test if hash field in DST_MAC, ETHERTYPE, VLAN_ID'): # Need to send l2 traffic to validate SRC_MAC, DST_MAC, ETHERTYPE, VLAN_ID fields, changing topology is required is_l2_test = False @@ -460,19 +465,19 @@ def test_lag_member_flap(duthost, tbinfo, ptfhost, fine_params, mg_facts, restor is_l2_test = True for _ in range(len(uplink_interfaces) - 1): uplink_interfaces.popitem() - remove_ip_interface_and_config_vlan(duthost, mg_facts, tbinfo, downlink_interfaces[0], + remove_ip_interface_and_config_vlan(rand_selected_dut, mg_facts, tbinfo, downlink_interfaces[0], uplink_interfaces, lag_test_hash_field) with allure.step('Prepare test parameters'): ptf_params = generate_test_params( - duthost, tbinfo, mg_facts, lag_test_hash_field, ipver, inner_ipver, encap_type, uplink_interfaces, + rand_selected_dut, tbinfo, mg_facts, lag_test_hash_field, ipver, inner_ipver, encap_type, uplink_interfaces, downlink_interfaces, ecmp_hash=True, lag_hash=True, is_l2_test=is_l2_test) if ptf_params.get('vxlan_port') and ptf_params['vxlan_port'] != DEFAULT_VXLAN_PORT: - config_custom_vxlan_port(duthost, ptf_params['vxlan_port']) + config_custom_vxlan_port(rand_selected_dut, ptf_params['vxlan_port']) with allure.step('Start the ptf test, send traffic and check the balancing'): # Check the default route before the ptf test if not is_l2_test: - pytest_assert(check_default_route(duthost, uplink_interfaces.keys()), + pytest_assert(check_default_route(rand_selected_dut, uplink_interfaces.keys()), 'The default route is not available or some nexthops are missing.') ptf_runner( ptfhost, @@ -493,11 +498,11 @@ def test_lag_member_flap(duthost, tbinfo, ptfhost, fine_params, mg_facts, restor interface = random.choice(uplink_interfaces[portchannel]) interfaces.append(interface) # Flap the members 3 more times - flap_interfaces(duthost, interfaces, uplink_interfaces.keys(), times=3) + flap_interfaces(rand_selected_dut, interfaces, uplink_interfaces.keys(), times=3) if not is_l2_test: with allure.step('Wait for the default route to recover'): - pytest_assert(wait_until(30, 5, 0, check_default_route, duthost, uplink_interfaces.keys()), + pytest_assert(wait_until(30, 5, 0, check_default_route, rand_selected_dut, uplink_interfaces.keys()), 'The default route is not available or some nexthops are missing.') with allure.step('Start the ptf test, send traffic and check the balancing'): ptf_runner( @@ -513,16 +518,17 @@ def test_lag_member_flap(duthost, tbinfo, ptfhost, fine_params, mg_facts, restor ) -def test_lag_member_remove_add(duthost, tbinfo, ptfhost, fine_params, mg_facts, restore_configuration, # noqa F811 - restore_interfaces, global_hash_capabilities, restore_vxlan_port, # noqa F811 - get_supported_hash_algorithms, toggle_all_simulator_ports_to_upper_tor): # noqa F811 +def test_lag_member_remove_add(rand_selected_dut, tbinfo, ptfhost, fine_params, mg_facts, # noqa:F811 + restore_configuration, restore_interfaces, # noqa:F811 + global_hash_capabilities, restore_vxlan_port, # noqa:F811 + get_supported_hash_algorithms, toggle_all_aa_ports_to_rand_selected_tor): # noqa:F811 """ Test case to validate the lag hash when a lag member is removed from the lag and added back for a few times. The hash field to test is randomly chosen from the supported hash fields. When hash field is in [DST_MAC, ETHERTYPE, VLAN_ID], need to re-configure the dut for L2 traffic. Args: - duthost (AnsibleHost): Device Under Test (DUT) + rand_selected_dut (AnsibleHost): Device Under Test (DUT) ptfhost (AnsibleHost): Packet Test Framework (PTF) tbinfo: testbed info fixture mg_facts: minigraph facts @@ -540,16 +546,17 @@ def test_lag_member_remove_add(duthost, tbinfo, ptfhost, fine_params, mg_facts, with allure.step('Randomly select an lag hash field to test ' 'and configure all supported fields to the global ecmp and lag hash'): # Get the interfaces for the test, downlink interface is selected randomly - uplink_interfaces, downlink_interfaces = get_interfaces_for_test(duthost, mg_facts, lag_test_hash_field) + uplink_interfaces, downlink_interfaces = get_interfaces_for_test(rand_selected_dut, mg_facts, + lag_test_hash_field) # If the uplinks are not multi-member portchannels, skip the test skip_single_member_lag_topology(uplink_interfaces, lag_test_hash_field, encap_type) - config_all_hash_fields(duthost, global_hash_capabilities) + config_all_hash_fields(rand_selected_dut, global_hash_capabilities) lag_algorithm = get_diff_hash_algorithm(ecmp_algorithm, get_supported_hash_algorithms) with allure.step(f'Configure ecmp hash algorithm: {ecmp_algorithm} - lag hash algorithm: {lag_algorithm}'): - config_all_hash_algorithm(duthost, ecmp_algorithm, lag_algorithm) + config_all_hash_algorithm(rand_selected_dut, ecmp_algorithm, lag_algorithm) with allure.step("Check the config result"): - check_global_hash_config(duthost, global_hash_capabilities['ecmp'], global_hash_capabilities['lag']) - check_global_hash_algorithm(duthost, ecmp_algorithm, lag_algorithm) + check_global_hash_config(rand_selected_dut, global_hash_capabilities['ecmp'], global_hash_capabilities['lag']) + check_global_hash_algorithm(rand_selected_dut, ecmp_algorithm, lag_algorithm) with allure.step('Change topology for L2 test if hash field in DST_MAC, ETHERTYPE, VLAN_ID'): # Need to send l2 traffic to validate SRC_MAC, DST_MAC, ETHERTYPE, VLAN_ID fields, changing topology is required is_l2_test = False @@ -559,19 +566,19 @@ def test_lag_member_remove_add(duthost, tbinfo, ptfhost, fine_params, mg_facts, is_l2_test = True for _ in range(len(uplink_interfaces) - 1): uplink_interfaces.popitem() - remove_ip_interface_and_config_vlan(duthost, mg_facts, tbinfo, downlink_interfaces[0], + remove_ip_interface_and_config_vlan(rand_selected_dut, mg_facts, tbinfo, downlink_interfaces[0], uplink_interfaces, lag_test_hash_field) with allure.step('Prepare test parameters'): ptf_params = generate_test_params( - duthost, tbinfo, mg_facts, lag_test_hash_field, ipver, inner_ipver, encap_type, uplink_interfaces, + rand_selected_dut, tbinfo, mg_facts, lag_test_hash_field, ipver, inner_ipver, encap_type, uplink_interfaces, downlink_interfaces, ecmp_hash=True, lag_hash=True, is_l2_test=is_l2_test) if ptf_params.get('vxlan_port') and ptf_params['vxlan_port'] != DEFAULT_VXLAN_PORT: - config_custom_vxlan_port(duthost, ptf_params['vxlan_port']) + config_custom_vxlan_port(rand_selected_dut, ptf_params['vxlan_port']) with allure.step('Start the ptf test, send traffic and check the balancing'): # Check the default route before the ptf test if not is_l2_test: - pytest_assert(check_default_route(duthost, uplink_interfaces.keys()), + pytest_assert(check_default_route(rand_selected_dut, uplink_interfaces.keys()), 'The default route is not available or some nexthops are missing.') ptf_runner( ptfhost, @@ -589,11 +596,11 @@ def test_lag_member_remove_add(duthost, tbinfo, ptfhost, fine_params, mg_facts, # Randomly choose the members to remove/add for portchannel in uplink_interfaces: interface = random.choice(uplink_interfaces[portchannel]) - remove_add_portchannel_member(duthost, interface, portchannel) + remove_add_portchannel_member(rand_selected_dut, interface, portchannel) if not is_l2_test: with allure.step('Wait for the default route to recover'): - pytest_assert(wait_until(30, 5, 0, check_default_route, duthost, uplink_interfaces.keys()), + pytest_assert(wait_until(30, 5, 0, check_default_route, rand_selected_dut, uplink_interfaces.keys()), 'The default route is not available or some nexthops are missing.') with allure.step('Start the ptf test, send traffic and check the balancing'): @@ -611,14 +618,14 @@ def test_lag_member_remove_add(duthost, tbinfo, ptfhost, fine_params, mg_facts, @pytest.mark.disable_loganalyzer -def test_reboot(duthost, tbinfo, ptfhost, localhost, fine_params, mg_facts, restore_vxlan_port, # noqa F811 - global_hash_capabilities, reboot_type, get_supported_hash_algorithms, # noqa F811 - toggle_all_simulator_ports_to_upper_tor): # noqa F811 +def test_reboot(rand_selected_dut, tbinfo, ptfhost, localhost, fine_params, mg_facts, restore_vxlan_port, # noqa:F811 + global_hash_capabilities, reboot_type, get_supported_hash_algorithms, # noqa:F811 + toggle_all_aa_ports_to_rand_selected_tor): # noqa:F811 """ Test case to validate the hash behavior after fast/warm/cold reboot. The hash field to test is randomly chosen from the supported hash fields. Args: - duthost (AnsibleHost): Device Under Test (DUT) + rand_selected_dut (AnsibleHost): Device Under Test (DUT) ptfhost (AnsibleHost): Packet Test Framework (PTF) mg_facts: minigraph facts localhost: local host object @@ -634,24 +641,25 @@ def test_reboot(duthost, tbinfo, ptfhost, localhost, fine_params, mg_facts, rest skip_unsupported_field_for_ecmp_test(ecmp_test_hash_field, encap_type) with allure.step('Randomly select an ecmp hash field to test ' 'and configure all supported fields to the global ecmp and lag hash'): - config_all_hash_fields(duthost, global_hash_capabilities) + config_all_hash_fields(rand_selected_dut, global_hash_capabilities) lag_algorithm = get_diff_hash_algorithm(ecmp_algorithm, get_supported_hash_algorithms) with allure.step(f'Configure ecmp hash algorithm: {ecmp_algorithm} - lag hash algorithm: {lag_algorithm}'): - config_all_hash_algorithm(duthost, ecmp_algorithm, lag_algorithm) + config_all_hash_algorithm(rand_selected_dut, ecmp_algorithm, lag_algorithm) with allure.step("Check the config result"): - check_global_hash_config(duthost, global_hash_capabilities['ecmp'], global_hash_capabilities['lag']) - check_global_hash_algorithm(duthost, ecmp_algorithm, lag_algorithm) + check_global_hash_config(rand_selected_dut, global_hash_capabilities['ecmp'], global_hash_capabilities['lag']) + check_global_hash_algorithm(rand_selected_dut, ecmp_algorithm, lag_algorithm) with allure.step('Prepare test parameters'): # Get the interfaces for the test, downlink interface is selected randomly - uplink_interfaces, downlink_interfaces = get_interfaces_for_test(duthost, mg_facts, ecmp_test_hash_field) + uplink_interfaces, downlink_interfaces = get_interfaces_for_test(rand_selected_dut, mg_facts, + ecmp_test_hash_field) ptf_params = generate_test_params( - duthost, tbinfo, mg_facts, ecmp_test_hash_field, ipver, inner_ipver, encap_type, uplink_interfaces, - downlink_interfaces, ecmp_hash=True, lag_hash=True) + rand_selected_dut, tbinfo, mg_facts, ecmp_test_hash_field, ipver, inner_ipver, encap_type, + uplink_interfaces, downlink_interfaces, ecmp_hash=True, lag_hash=True) if ptf_params.get('vxlan_port') and ptf_params['vxlan_port'] != DEFAULT_VXLAN_PORT: - config_custom_vxlan_port(duthost, ptf_params['vxlan_port']) + config_custom_vxlan_port(rand_selected_dut, ptf_params['vxlan_port']) with allure.step('Start the ptf test, send traffic and check the balancing'): # Check the default route before the ptf test - pytest_assert(check_default_route(duthost, uplink_interfaces.keys()), + pytest_assert(check_default_route(rand_selected_dut, uplink_interfaces.keys()), 'The default route is not available or some nexthops are missing.') ptf_runner( ptfhost, @@ -668,21 +676,21 @@ def test_reboot(duthost, tbinfo, ptfhost, localhost, fine_params, mg_facts, rest with allure.step(f'Randomly choose a reboot type: {reboot_type}, and reboot'): # Save config if reboot type is config reload or cold reboot if reboot_type in ['cold', 'reload']: - duthost.shell('config save -y') + rand_selected_dut.shell('config save -y') # Reload/Reboot the dut if reboot_type == 'reload': - config_reload(duthost, safe_reload=True, check_intf_up_ports=True) + config_reload(rand_selected_dut, safe_reload=True, check_intf_up_ports=True) else: - reboot(duthost, localhost, reboot_type=reboot_type) + reboot(rand_selected_dut, localhost, reboot_type=reboot_type) # Wait for the dut to recover - pytest_assert(wait_until(300, 20, 0, duthost.critical_services_fully_started), + pytest_assert(wait_until(300, 20, 0, rand_selected_dut.critical_services_fully_started), "Not all critical services are fully started.") with allure.step('Check the generic hash config after the reboot'): - check_global_hash_config(duthost, global_hash_capabilities['ecmp'], global_hash_capabilities['lag']) + check_global_hash_config(rand_selected_dut, global_hash_capabilities['ecmp'], global_hash_capabilities['lag']) if ptf_params.get('vxlan_port') and ptf_params['vxlan_port'] != DEFAULT_VXLAN_PORT: - config_custom_vxlan_port(duthost, ptf_params['vxlan_port']) + config_custom_vxlan_port(rand_selected_dut, ptf_params['vxlan_port']) with allure.step('Check the route is established'): - pytest_assert(wait_until(60, 10, 0, check_default_route, duthost, uplink_interfaces.keys()), + pytest_assert(wait_until(60, 10, 0, check_default_route, rand_selected_dut, uplink_interfaces.keys()), "The default route is not established after the cold reboot.") with allure.step('Start the ptf test, send traffic and check the balancing'): ptf_runner(