diff --git a/tests/acl/test_acl.py b/tests/acl/test_acl.py index c77d7c51336..ef11cd6dd0c 100644 --- a/tests/acl/test_acl.py +++ b/tests/acl/test_acl.py @@ -56,7 +56,7 @@ @pytest.fixture(scope="module") -def setup(duthost, tbinfo, ptfadapter): +def setup(duthosts, rand_one_dut_hostname, tbinfo, ptfadapter): """Gather all required test information from DUT and tbinfo. Args: @@ -67,6 +67,7 @@ def setup(duthost, tbinfo, ptfadapter): A Dictionary with required test information. """ + duthost = duthosts[rand_one_dut_hostname] pytest_require( tbinfo["topo"]["name"] != "dualtor", "ACL test not supported on topology: \"{}\"".format(tbinfo["topo"]["name"]) @@ -134,8 +135,9 @@ def setup(duthost, tbinfo, ptfadapter): @pytest.fixture(scope="module") -def populate_vlan_arp_entries(setup, ptfhost, duthost): +def populate_vlan_arp_entries(setup, ptfhost, duthosts, rand_one_dut_hostname): """Set up the ARP responder utility in the PTF container.""" + duthost = duthosts[rand_one_dut_hostname] if setup["topo"] != "t0": def noop(): pass @@ -187,7 +189,7 @@ def populate_arp_table(): @pytest.fixture(scope="module", params=["ingress", "egress"]) -def stage(request, duthost): +def stage(request, duthosts, rand_one_dut_hostname): """Parametrize tests for Ingress/Egress stage testing. Args: @@ -198,6 +200,7 @@ def stage(request, duthost): str: The ACL stage to be tested. """ + duthost = duthosts[rand_one_dut_hostname] pytest_require( request.param == "ingress" or duthost.facts["asic_type"] not in ("broadcom"), "Egress ACLs are not currently supported on \"{}\" ASICs".format(duthost.facts["asic_type"]) @@ -207,7 +210,7 @@ def stage(request, duthost): @pytest.fixture(scope="module") -def acl_table_config(duthost, setup, stage): +def acl_table_config(duthosts, rand_one_dut_hostname, setup, stage): """Generate ACL table configuration files and deploy them to the DUT. Args: @@ -219,6 +222,7 @@ def acl_table_config(duthost, setup, stage): A dictionary containing the table name and the corresponding configuration file. """ + duthost = duthosts[rand_one_dut_hostname] stage_to_name_map = { "ingress": "DATA_INGRESS_TEST", "egress": "DATA_EGRESS_TEST" @@ -250,7 +254,7 @@ def acl_table_config(duthost, setup, stage): @pytest.fixture(scope="module") -def acl_table(duthost, acl_table_config, backup_and_restore_config_db_module): +def acl_table(duthosts, rand_one_dut_hostname, acl_table_config, backup_and_restore_config_db_module): """Apply ACL table configuration and remove after tests. Args: @@ -263,6 +267,7 @@ def acl_table(duthost, acl_table_config, backup_and_restore_config_db_module): The ACL table configuration. """ + duthost = duthosts[rand_one_dut_hostname] table_name = acl_table_config["table_name"] config_file = acl_table_config["config_file"] diff --git a/tests/arp/test_arpall.py b/tests/arp/test_arpall.py index 940dae4274d..ec31c7d821d 100644 --- a/tests/arp/test_arpall.py +++ b/tests/arp/test_arpall.py @@ -12,7 +12,8 @@ ] @pytest.fixture(scope="module") -def common_setup_teardown(duthost, ptfhost): +def common_setup_teardown(duthosts, rand_one_dut_hostname, ptfhost): + duthost = duthosts[rand_one_dut_hostname] mg_facts = duthost.minigraph_facts(host=duthost.hostname)['ansible_facts'] int_facts = duthost.interface_facts()['ansible_facts'] diff --git a/tests/autorestart/test_container_autorestart.py b/tests/autorestart/test_container_autorestart.py index ae3c4dd62b2..7de66b96b5b 100755 --- a/tests/autorestart/test_container_autorestart.py +++ b/tests/autorestart/test_container_autorestart.py @@ -22,7 +22,7 @@ @pytest.fixture(autouse=True) -def ignore_expected_loganalyzer_exception(duthost, loganalyzer): +def ignore_expected_loganalyzer_exception(loganalyzer): """ Ignore expected failure/error messages during testing the autorestart feature. @@ -305,12 +305,13 @@ def postcheck_critical_processes_status(duthost, container_autorestart_states): "Post checking the healthy of critical processes failed.") -def test_containers_autorestart(duthost, tbinfo): +def test_containers_autorestart(duthosts, rand_one_dut_hostname, tbinfo): """ @summary: Test the auto-restart feature of each container against two scenarios: killing a non-critical process to verify the container is still running; killing each critical process to verify the container will be stopped and restarted """ + duthost = duthosts[rand_one_dut_hostname] container_autorestart_states = duthost.get_container_autorestart_states() disabled_containers = get_disabled_container_list(duthost) diff --git a/tests/bgp/conftest.py b/tests/bgp/conftest.py index 699921ff961..3388ca723ff 100644 --- a/tests/bgp/conftest.py +++ b/tests/bgp/conftest.py @@ -9,7 +9,8 @@ logger = logging.getLogger(__name__) @pytest.fixture(scope='module') -def setup_keepalive_and_hold_timer(duthost, nbrhosts): +def setup_keepalive_and_hold_timer(duthosts, rand_one_dut_hostname, nbrhosts): + duthost = duthosts[rand_one_dut_hostname] # incrase the keepalive and hold timer duthost.command("vtysh -c \"configure terminal\" \ -c \"router bgp {}\" \ @@ -40,7 +41,8 @@ def check_results(results): @pytest.fixture(scope='module') -def setup_bgp_graceful_restart(duthost, nbrhosts): +def setup_bgp_graceful_restart(duthosts, rand_one_dut_hostname, nbrhosts): + duthost = duthosts[rand_one_dut_hostname] config_facts = duthost.config_facts(host=duthost.hostname, source="running")['ansible_facts'] bgp_neighbors = config_facts.get('BGP_NEIGHBOR', {}) diff --git a/tests/bgp/test_bgp_gr_helper.py b/tests/bgp/test_bgp_gr_helper.py index 3d089302e18..616e98676e8 100644 --- a/tests/bgp/test_bgp_gr_helper.py +++ b/tests/bgp/test_bgp_gr_helper.py @@ -11,10 +11,11 @@ logger = logging.getLogger(__name__) -def test_bgp_gr_helper_routes_perserved(duthost, nbrhosts, setup_bgp_graceful_restart, tbinfo): +def test_bgp_gr_helper_routes_perserved(duthosts, rand_one_dut_hostname, nbrhosts, setup_bgp_graceful_restart, tbinfo): """ Verify that DUT routes are preserved when peer performed graceful restart """ + duthost = duthosts[rand_one_dut_hostname] config_facts = duthost.config_facts(host=duthost.hostname, source="running")['ansible_facts'] bgp_neighbors = config_facts.get('BGP_NEIGHBOR', {}) diff --git a/tests/bgp/test_bgp_multipath_relax.py b/tests/bgp/test_bgp_multipath_relax.py index 85bf3caa1b5..9d883d5dc18 100644 --- a/tests/bgp/test_bgp_multipath_relax.py +++ b/tests/bgp/test_bgp_multipath_relax.py @@ -60,7 +60,8 @@ def get_bgp_v4_neighbors_from_minigraph(duthost, tbinfo): bgp_v4nei[item['name']] = item['addr'] return bgp_v4nei -def test_bgp_multipath_relax(tbinfo, duthost): +def test_bgp_multipath_relax(tbinfo, duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] logger.info("Starting test_bgp_multipath_relax on topology {}".format(tbinfo['topo']['name'])) topo_config = tbinfo['topo']['properties']['configuration'] diff --git a/tests/bgp/test_bgp_speaker.py b/tests/bgp/test_bgp_speaker.py index 673a3e79641..d481df7d8a9 100644 --- a/tests/bgp/test_bgp_speaker.py +++ b/tests/bgp/test_bgp_speaker.py @@ -50,7 +50,8 @@ def change_route(operation, ptfip, neighbor, route, nexthop, port): assert r.status_code == 200 @pytest.fixture(scope="module") -def common_setup_teardown(duthost, ptfhost, localhost): +def common_setup_teardown(duthosts, rand_one_dut_hostname, ptfhost, localhost): + duthost = duthosts[rand_one_dut_hostname] logging.info("########### Setup for bgp speaker testing ###########") @@ -165,9 +166,10 @@ def common_setup_teardown(duthost, ptfhost, localhost): logging.info("########### Done teardown for bgp speaker testing ###########") -def test_bgp_speaker_bgp_sessions(common_setup_teardown, duthost, ptfhost, collect_techsupport): +def test_bgp_speaker_bgp_sessions(common_setup_teardown, duthosts, rand_one_dut_hostname, ptfhost, collect_techsupport): """Setup bgp speaker on T0 topology and verify bgp sessions are established """ + duthost = duthosts[rand_one_dut_hostname] ptfip, mg_facts, interface_facts, vlan_ips, _, _, speaker_ips, port_num, http_ready = common_setup_teardown assert http_ready @@ -245,18 +247,20 @@ def bgp_speaker_announce_routes_common(common_setup_teardown, tbinfo, duthost, p @pytest.mark.parametrize("ipv4, ipv6, mtu", [pytest.param(True, False, 1514)]) -def test_bgp_speaker_announce_routes(common_setup_teardown, tbinfo, duthost, ptfhost, ipv4, ipv6, mtu, collect_techsupport): +def test_bgp_speaker_announce_routes(common_setup_teardown, tbinfo, duthosts, rand_one_dut_hostname, ptfhost, ipv4, ipv6, mtu, collect_techsupport): """Setup bgp speaker on T0 topology and verify routes advertised by bgp speaker is received by T0 TOR """ + duthost = duthosts[rand_one_dut_hostname] nexthops = common_setup_teardown[3] bgp_speaker_announce_routes_common(common_setup_teardown, tbinfo, duthost, ptfhost, ipv4, ipv6, mtu, "v4", "10.10.10.0/26", nexthops) @pytest.mark.parametrize("ipv4, ipv6, mtu", [pytest.param(False, True, 1514)]) -def test_bgp_speaker_announce_routes_v6(common_setup_teardown, tbinfo, duthost, ptfhost, ipv4, ipv6, mtu, collect_techsupport): +def test_bgp_speaker_announce_routes_v6(common_setup_teardown, tbinfo, duthosts, rand_one_dut_hostname, ptfhost, ipv4, ipv6, mtu, collect_techsupport): """Setup bgp speaker on T0 topology and verify routes advertised by bgp speaker is received by T0 TOR """ + duthost = duthosts[rand_one_dut_hostname] nexthops = common_setup_teardown[4] bgp_speaker_announce_routes_common(common_setup_teardown, tbinfo, duthost, ptfhost, ipv4, ipv6, mtu, "v6", "fc00:10::/64", nexthops) diff --git a/tests/cacl/test_cacl_application.py b/tests/cacl/test_cacl_application.py index 488e58ffc2b..56be5855e10 100644 --- a/tests/cacl/test_cacl_application.py +++ b/tests/cacl/test_cacl_application.py @@ -314,7 +314,7 @@ def generate_expected_rules(duthost): return iptables_rules, ip6tables_rules -def test_cacl_application(duthost, localhost, creds): +def test_cacl_application(duthosts, rand_one_dut_hostname, localhost, creds): """ Test case to ensure caclmgrd is applying control plane ACLs properly @@ -322,6 +322,7 @@ def test_cacl_application(duthost, localhost, creds): rules based on the DuT's configuration and comparing them against the actual iptables/ip6tables rules on the DuT. """ + duthost = duthosts[rand_one_dut_hostname] expected_iptables_rules, expected_ip6tables_rules = generate_expected_rules(duthost) stdout = duthost.shell("sudo iptables -S")["stdout"] diff --git a/tests/cacl/test_cacl_function.py b/tests/cacl/test_cacl_function.py index 4da21f53b78..00b60b81837 100644 --- a/tests/cacl/test_cacl_function.py +++ b/tests/cacl/test_cacl_function.py @@ -10,9 +10,10 @@ SONIC_SSH_REGEX = 'OpenSSH_[\\w\\.]+ Debian' -def test_cacl_function(duthost, localhost, creds): +def test_cacl_function(duthosts, rand_one_dut_hostname, localhost, creds): """Test control plane ACL functionality on a SONiC device """ + duthost = duthosts[rand_one_dut_hostname] dut_mgmt_ip = duthost.setup()['ansible_facts']['ansible_eth0']['ipv4']['address'] # Ensure we can gather basic SNMP facts from the device diff --git a/tests/common/fixtures/advanced_reboot.py b/tests/common/fixtures/advanced_reboot.py index a79f8e6dd2a..931eadf42f2 100644 --- a/tests/common/fixtures/advanced_reboot.py +++ b/tests/common/fixtures/advanced_reboot.py @@ -527,7 +527,7 @@ def tearDown(self): self.__restorePrevImage() @pytest.fixture -def get_advanced_reboot(request, duthost, ptfhost, localhost, tbinfo, creds): +def get_advanced_reboot(request, duthosts, rand_one_dut_hostname, ptfhost, localhost, tbinfo, creds): ''' Pytest test fixture that provides access to AdvancedReboot test fixture @param request: pytest request object @@ -536,6 +536,7 @@ def get_advanced_reboot(request, duthost, ptfhost, localhost, tbinfo, creds): @param localhost: Localhost for interacting with localhost through ansible @param tbinfo: fixture provides information about testbed ''' + duthost = duthosts[rand_one_dut_hostname] instances = [] def get_advanced_reboot(**kwargs): diff --git a/tests/common/fixtures/conn_graph_facts.py b/tests/common/fixtures/conn_graph_facts.py index 94da58d645f..87e2e8db2f5 100644 --- a/tests/common/fixtures/conn_graph_facts.py +++ b/tests/common/fixtures/conn_graph_facts.py @@ -11,7 +11,8 @@ def conn_graph_facts(duthosts, localhost): @pytest.fixture(scope="module") -def fanout_graph_facts(localhost, duthost, conn_graph_facts): +def fanout_graph_facts(localhost, duthosts, rand_one_dut_hostname, conn_graph_facts): + duthost = duthosts[rand_one_dut_hostname] facts = dict() dev_conn = conn_graph_facts.get('device_conn', {}) for intf, val in dev_conn[duthost.hostname].items(): diff --git a/tests/common/fixtures/duthost_utils.py b/tests/common/fixtures/duthost_utils.py index e8e061d95af..683d57c78cb 100644 --- a/tests/common/fixtures/duthost_utils.py +++ b/tests/common/fixtures/duthost_utils.py @@ -23,16 +23,18 @@ def _backup_and_restore_config_db(duthost): @pytest.fixture -def backup_and_restore_config_db(duthost): +def backup_and_restore_config_db(duthosts, rand_one_dut_hostname): """Back up and restore config DB at the function level.""" + duthost = duthosts[rand_one_dut_hostname] # TODO: Use the neater "yield from _function" syntax when we move to python3 for func in _backup_and_restore_config_db(duthost): yield func @pytest.fixture(scope="module") -def backup_and_restore_config_db_module(duthost): +def backup_and_restore_config_db_module(duthosts, rand_one_dut_hostname): """Back up and restore config DB at the module level.""" + duthost = duthosts[rand_one_dut_hostname] # TODO: Use the neater "yield from _function" syntax when we move to python3 for func in _backup_and_restore_config_db(duthost): yield func @@ -53,18 +55,20 @@ def _disable_route_checker(duthost): @pytest.fixture -def disable_route_checker(duthost): +def disable_route_checker(duthosts, rand_one_dut_hostname): """ Wrapper for _disable_route_checker, function level """ + duthost = duthosts[rand_one_dut_hostname] for func in _disable_route_checker(duthost): yield func @pytest.fixture(scope='module') -def disable_route_checker_module(duthost): +def disable_route_checker_module(duthosts, rand_one_dut_hostname): """ Wrapper for _disable_route_checker, module level """ + duthost = duthosts[rand_one_dut_hostname] for func in _disable_route_checker(duthost): yield func diff --git a/tests/common/fixtures/pfc_asym.py b/tests/common/fixtures/pfc_asym.py index 100174d3362..28afc38d0d8 100755 --- a/tests/common/fixtures/pfc_asym.py +++ b/tests/common/fixtures/pfc_asym.py @@ -31,14 +31,16 @@ def get_fanout(fanout_graph_facts, setup): @pytest.fixture(scope="module") -def ansible_facts(duthost): +def ansible_facts(duthosts, rand_one_dut_hostname): """ Ansible facts fixture """ + duthost = duthosts[rand_one_dut_hostname] yield duthost.setup()['ansible_facts'] @pytest.fixture(scope="module") -def minigraph_facts(duthost): +def minigraph_facts(duthosts, rand_one_dut_hostname): """ DUT minigraph facts fixture """ + duthost = duthosts[rand_one_dut_hostname] yield duthost.minigraph_facts(host=duthost.hostname)['ansible_facts'] @@ -139,10 +141,11 @@ def run(self): @pytest.fixture(scope="function") -def enable_pfc_asym(setup, duthost): +def enable_pfc_asym(setup, duthosts, rand_one_dut_hostname): """ Enable/disable asymmetric PFC on all server interfaces """ + duthost = duthosts[rand_one_dut_hostname] get_pfc_mode = "docker exec -i database redis-cli --raw -n 1 HGET ASIC_STATE:SAI_OBJECT_TYPE_PORT:{} SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_MODE" srv_ports = " ".join([port["dut_name"] for port in setup["ptf_test_params"]["server_ports"]]) pfc_asym_enabled = "SAI_PORT_PRIORITY_FLOW_CONTROL_MODE_SEPARATE" @@ -175,7 +178,7 @@ def enable_pfc_asym(setup, duthost): assert setup["pfc_bitmask"]["pfc_mask"] == int(duthost.command(get_asym_pfc.format(port=p_oid, sai_attr=sai_default_asym_pfc))["stdout"]) @pytest.fixture(scope="module") -def setup(tbinfo, duthost, ptfhost, ansible_facts, minigraph_facts, request): +def setup(tbinfo, duthosts, rand_one_dut_hostname, ptfhost, ansible_facts, minigraph_facts, request): """ Fixture performs initial steps which is required for test case execution. Also it compose data which is used as input parameters for PTF test cases, and PFC - RX and TX masks which is used in test case logic. @@ -212,6 +215,7 @@ def setup(tbinfo, duthost, ptfhost, ansible_facts, minigraph_facts, request): - Remove ARP responder - Restore supervisor configuration in PTF container """ + duthost = duthosts[rand_one_dut_hostname] if tbinfo['topo']['name'] != "t0": pytest.skip('Unsupported topology') setup_params = { diff --git a/tests/common/fixtures/populate_fdb.py b/tests/common/fixtures/populate_fdb.py index 490484e52ff..49e144bb1d8 100644 --- a/tests/common/fixtures/populate_fdb.py +++ b/tests/common/fixtures/populate_fdb.py @@ -112,7 +112,7 @@ def run(self): ) @pytest.fixture -def populate_fdb(request, duthost, ptfhost): +def populate_fdb(request, duthosts, rand_one_dut_hostname, ptfhost): """ Populates DUT FDB entries @@ -124,6 +124,7 @@ def populate_fdb(request, duthost, ptfhost): Returns: None """ + duthost = duthosts[rand_one_dut_hostname] populateFdb = PopulateFdb(request, duthost, ptfhost) populateFdb.run() diff --git a/tests/common/fixtures/ptfhost_utils.py b/tests/common/fixtures/ptfhost_utils.py index 995c6c7cb85..e83470e9397 100644 --- a/tests/common/fixtures/ptfhost_utils.py +++ b/tests/common/fixtures/ptfhost_utils.py @@ -123,7 +123,7 @@ def copy_arp_responder_py(ptfhost): ptfhost.file(path=os.path.join(OPT_DIR, ARP_RESPONDER_PY), state="absent") @pytest.fixture(scope='class') -def ptf_portmap_file(duthost, ptfhost): +def ptf_portmap_file(duthosts, rand_one_dut_hostname, ptfhost): """ Prepare and copys port map file to PTF host @@ -135,6 +135,7 @@ def ptf_portmap_file(duthost, ptfhost): Returns: filename (str): returns the filename copied to PTF host """ + duthost = duthosts[rand_one_dut_hostname] intfInfo = duthost.show_interface(command = "status")['ansible_facts']['int_status'] portList = natsorted([port for port in intfInfo if port.startswith('Ethernet') and intfInfo[port]['speed'] != '10G']) portMapFile = "/tmp/default_interface_to_front_map.ini" diff --git a/tests/common/helpers/constants.py b/tests/common/helpers/constants.py index e5e7b94ef38..dde09903a32 100644 --- a/tests/common/helpers/constants.py +++ b/tests/common/helpers/constants.py @@ -3,4 +3,4 @@ DEFAULT_NAMESPACE = None NAMESPACE_PREFIX = 'asic' ASIC_PARAM_TYPE_ALL = 'num_asics' -ASIC_PARAM_TYPE_FRONTEND = 'frontend_asics' \ No newline at end of file +ASIC_PARAM_TYPE_FRONTEND = 'frontend_asics' diff --git a/tests/common/ixia/ixia_fixtures.py b/tests/common/ixia/ixia_fixtures.py index efb265af537..26a8804573f 100644 --- a/tests/common/ixia/ixia_fixtures.py +++ b/tests/common/ixia/ixia_fixtures.py @@ -24,7 +24,7 @@ def ixia_api_serv_ip(tbinfo): @pytest.fixture(scope = "module") -def ixia_api_serv_user(duthost): +def ixia_api_serv_user(duthosts, rand_one_dut_hostname): """ Return the username of Ixia API server. @@ -34,11 +34,12 @@ def ixia_api_serv_user(duthost): Returns: Ixia API server username. """ + duthost = duthosts[rand_one_dut_hostname] return duthost.host.options['variable_manager']._hostvars[duthost.hostname]['secret_group_vars']['ixia_api_server']['user'] @pytest.fixture(scope = "module") -def ixia_api_serv_passwd(duthost): +def ixia_api_serv_passwd(duthosts, rand_one_dut_hostname): """ Return the password of Ixia API server. @@ -48,11 +49,12 @@ def ixia_api_serv_passwd(duthost): Returns: Ixia API server password. """ + duthost = duthosts[rand_one_dut_hostname] return duthost.host.options['variable_manager']._hostvars[duthost.hostname]['secret_group_vars']['ixia_api_server']['password'] @pytest.fixture(scope = "module") -def ixia_api_serv_port(duthost): +def ixia_api_serv_port(duthosts, rand_one_dut_hostname): """ This fixture returns the TCP port for REST API of the ixia API server. @@ -62,11 +64,12 @@ def ixia_api_serv_port(duthost): Returns: Ixia API server REST port. """ + duthost = duthosts[rand_one_dut_hostname] return duthost.host.options['variable_manager']._hostvars[duthost.hostname]['secret_group_vars']['ixia_api_server']['rest_port'] @pytest.fixture(scope = "module") -def ixia_api_serv_session_id(duthost): +def ixia_api_serv_session_id(duthosts, rand_one_dut_hostname): """ Ixia API server can spawn multiple session on the same REST port. Optional for LINUX, required for windows return the session ID. @@ -77,11 +80,12 @@ def ixia_api_serv_session_id(duthost): Returns: Ixia API server session id. """ + duthost = duthosts[rand_one_dut_hostname] return duthost.host.options['variable_manager']._hostvars[duthost.hostname]['secret_group_vars']['ixia_api_server']['session_id'] @pytest.fixture(scope = "module") -def ixia_dev(duthost, fanouthosts): +def ixia_dev(duthosts, rand_one_dut_hostname, fanouthosts): """ Returns the Ixia chassis IP. This fixture can return multiple IPs if multiple Ixia chassis are present in the test topology. @@ -93,6 +97,7 @@ def ixia_dev(duthost, fanouthosts): Returns: Dictionary of Ixia Chassis IP/IPs. """ + duthost = duthosts[rand_one_dut_hostname] result = dict() ixia_dev_hostnames = fanouthosts.keys() for hostname in ixia_dev_hostnames: diff --git a/tests/common/plugins/custom_fixtures/check_dut_asic_type.py b/tests/common/plugins/custom_fixtures/check_dut_asic_type.py index 32f264b608f..0dc2e215c42 100644 --- a/tests/common/plugins/custom_fixtures/check_dut_asic_type.py +++ b/tests/common/plugins/custom_fixtures/check_dut_asic_type.py @@ -2,7 +2,8 @@ from tests.common.helpers.assertions import pytest_require @pytest.fixture(scope="function") -def check_dut_asic_type(request, duthost): +def check_dut_asic_type(request, duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] asic_marks = [mark for mark in request.node.iter_markers(name="asic")] if not asic_marks: return diff --git a/tests/common/plugins/custom_markers/__init__.py b/tests/common/plugins/custom_markers/__init__.py index 57285e99331..0ee7b20ff29 100644 --- a/tests/common/plugins/custom_markers/__init__.py +++ b/tests/common/plugins/custom_markers/__init__.py @@ -133,4 +133,4 @@ def check_test_completeness(item): normalized_completeness_level = test_completeness.normalize_levels(specified_level, defined_levels) normalized_completeness_level = pytest.mark.supported_completeness_level(normalized_completeness_level) - item.add_marker(normalized_completeness_level, append=False) \ No newline at end of file + item.add_marker(normalized_completeness_level, append=False) diff --git a/tests/common/plugins/loganalyzer/__init__.py b/tests/common/plugins/loganalyzer/__init__.py index dce3ae17c02..9df3879a01d 100644 --- a/tests/common/plugins/loganalyzer/__init__.py +++ b/tests/common/plugins/loganalyzer/__init__.py @@ -11,7 +11,8 @@ def pytest_addoption(parser): @pytest.fixture(autouse=True) -def loganalyzer(duthost, request): +def loganalyzer(duthosts, rand_one_dut_hostname, request): + duthost = duthosts[rand_one_dut_hostname] if request.config.getoption("--disable_loganalyzer") or "disable_loganalyzer" in request.keywords: logging.info("Log analyzer is disabled") yield diff --git a/tests/common/plugins/psu_controller/__init__.py b/tests/common/plugins/psu_controller/__init__.py index 3b625341d3b..827701e7697 100644 --- a/tests/common/plugins/psu_controller/__init__.py +++ b/tests/common/plugins/psu_controller/__init__.py @@ -17,13 +17,14 @@ def psu_controller_factory(controller_ip, controller_protocol, dut_hostname, pdu @pytest.fixture(scope="module") -def psu_controller(duthost, pdu): +def psu_controller(duthosts, rand_one_dut_hostname, pdu): """ @summary: Fixture for controlling power supply to PSUs of DUT @param duthost: Fixture duthost defined in sonic-mgmt/tests/conftest.py @returns: Returns a psu controller object implementing the BasePsuController interface defined in controller_base.py. """ + duthost = duthosts[rand_one_dut_hostname] logging.info("Creating psu_controller fixture") inv_mgr = duthost.host.options["inventory_manager"] diff --git a/tests/common/plugins/sanity_check/__init__.py b/tests/common/plugins/sanity_check/__init__.py index bef98a1d94e..dd6bbe1454b 100644 --- a/tests/common/plugins/sanity_check/__init__.py +++ b/tests/common/plugins/sanity_check/__init__.py @@ -41,7 +41,8 @@ def _update_check_items(old_items, new_items, supported_items): @pytest.fixture(scope="module", autouse=True) -def sanity_check(localhost, duthost, request, fanouthosts, tbinfo): +def sanity_check(localhost, duthosts, rand_one_dut_hostname, request, fanouthosts, tbinfo): + duthost = duthosts[rand_one_dut_hostname] logger.info("Start pre-test sanity check") skip_sanity = False diff --git a/tests/common/plugins/tacacs.py b/tests/common/plugins/tacacs.py index 6f86912ec6b..6ef514b6c11 100644 --- a/tests/common/plugins/tacacs.py +++ b/tests/common/plugins/tacacs.py @@ -45,7 +45,8 @@ def cleanup_tacacs(ptfhost, duthost, tacacs_server_ip): duthost.shell("sudo config aaa authentication failthrough default") @pytest.fixture(scope="module") -def test_tacacs(ptfhost, duthost, creds): +def test_tacacs(ptfhost, duthosts, rand_one_dut_hostname, creds): + duthost = duthosts[rand_one_dut_hostname] tacacs_server_ip = ptfhost.host.options['inventory_manager'].get_host(ptfhost.hostname).vars['ansible_host'] configure_tacacs(ptfhost, duthost, creds, tacacs_server_ip) @@ -55,7 +56,8 @@ def test_tacacs(ptfhost, duthost, creds): @pytest.fixture(scope="module") -def test_tacacs_v6(ptfhost, duthost, creds): +def test_tacacs_v6(ptfhost, duthosts, rand_one_dut_hostname, creds): + duthost = duthosts[rand_one_dut_hostname] ptfhost_vars = ptfhost.host.options['inventory_manager'].get_host(ptfhost.hostname).vars if 'ansible_hostv6' not in ptfhost_vars: pytest.skip("Skip IPv6 test. ptf ansible_hostv6 not configured.") diff --git a/tests/common/plugins/test_completeness/__init__.py b/tests/common/plugins/test_completeness/__init__.py index 9b7d1358017..6fae1e8ab61 100644 --- a/tests/common/plugins/test_completeness/__init__.py +++ b/tests/common/plugins/test_completeness/__init__.py @@ -87,4 +87,4 @@ def normalize_levels(specified_level, defined_levels): completeness_level = specified_level logging.info("Setting the completeness level to {}".format(str(CompletenessLevel(completeness_level)))) - return completeness_level \ No newline at end of file + return completeness_level diff --git a/tests/conftest.py b/tests/conftest.py index 3fc79f21085..04abcef627d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -300,12 +300,22 @@ def duthost(duthosts, request): return duthost +@pytest.fixture(scope="module") +def rand_one_dut_hostname(request): + """ + """ + dut_hostnames = generate_params_dut_hostname(request) + if len(dut_hostnames) > 1: + dut_hostnames = random.sample(dut_hostnames, 1) + return dut_hostnames[0] + @pytest.fixture(scope="module", autouse=True) -def reset_critical_services_list(duthost): +def reset_critical_services_list(duthosts, rand_one_dut_hostname): """ Resets the critical services list between test modules to ensure that it is left in a known state after tests finish running. """ + duthost = duthosts[rand_one_dut_hostname] duthost.reset_critical_services_tracking_list() @@ -411,8 +421,9 @@ def pdu(): @pytest.fixture(scope="module") -def creds(duthost): +def creds(duthosts, rand_one_dut_hostname): """ read credential information according to the dut inventory """ + duthost = duthosts[rand_one_dut_hostname] groups = duthost.host.options['inventory_manager'].get_host(duthost.hostname).get_vars()['group_names'] groups.append("fanout") logger.info("dut {} belongs to groups {}".format(duthost.hostname, groups)) @@ -467,7 +478,8 @@ def fetch_dbs(duthost, testname): @pytest.fixture -def collect_techsupport(request, duthost): +def collect_techsupport(request, duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] yield # request.node is an "item" because we use the default # "function" scope @@ -617,11 +629,6 @@ def pytest_generate_tests(metafunc): elif "enum_dut_hostname" in metafunc.fixturenames: dut_hostnames = generate_params_dut_hostname(metafunc) metafunc.parametrize("enum_dut_hostname", dut_hostnames) - elif "rand_one_dut_hostname" in metafunc.fixturenames: - dut_hostnames = generate_params_dut_hostname(metafunc) - if len(dut_hostnames) > 1: - dut_hostnames = random.sample(dut_hostnames, 1) - metafunc.parametrize("rand_one_dut_hostname", dut_hostnames) if "enum_asic_index" in metafunc.fixturenames: metafunc.parametrize("enum_asic_index",generate_param_asic_index(metafunc, dut_indices, ASIC_PARAM_TYPE_ALL)) diff --git a/tests/copp/test_copp.py b/tests/copp/test_copp.py index 2386481ec7c..5efc29c6107 100644 --- a/tests/copp/test_copp.py +++ b/tests/copp/test_copp.py @@ -65,13 +65,14 @@ class TestCOPP(object): "IP2ME", "SNMP", "SSH"]) - def test_policer(self, protocol, duthost, ptfhost, copp_testbed, dut_type): + def test_policer(self, protocol, duthosts, rand_one_dut_hostname, ptfhost, copp_testbed, dut_type): """ Validates that rate-limited COPP groups work as expected. Checks that the policer enforces the rate limit for protocols that have a set rate limit. """ + duthost = duthosts[rand_one_dut_hostname] _copp_runner(duthost, ptfhost, protocol, @@ -83,13 +84,14 @@ def test_policer(self, protocol, duthost, ptfhost, copp_testbed, dut_type): "LACP", "LLDP", "UDLD"]) - def test_no_policer(self, protocol, duthost, ptfhost, copp_testbed, dut_type): + def test_no_policer(self, protocol, duthosts, rand_one_dut_hostname, ptfhost, copp_testbed, dut_type): """ Validates that non-rate-limited COPP groups work as expected. Checks that the policer does not enforce a rate limit for protocols that do not have any set rate limit. """ + duthost = duthosts[rand_one_dut_hostname] _copp_runner(duthost, ptfhost, protocol, @@ -97,7 +99,8 @@ def test_no_policer(self, protocol, duthost, ptfhost, copp_testbed, dut_type): dut_type) @pytest.fixture(scope="class") -def dut_type(duthost): +def dut_type(duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] cfg_facts = json.loads(duthost.shell("sonic-cfggen -d --print-data")['stdout']) # return config db contents(running-config) dut_type = None @@ -109,10 +112,11 @@ def dut_type(duthost): return dut_type @pytest.fixture(scope="class") -def copp_testbed(duthost, creds, ptfhost, tbinfo, request): +def copp_testbed(duthosts, rand_one_dut_hostname, creds, ptfhost, tbinfo, request): """ Pytest fixture to handle setup and cleanup for the COPP tests. """ + duthost = duthosts[rand_one_dut_hostname] test_params = _gather_test_params(tbinfo, duthost, request) if test_params.topo not in (_SUPPORTED_PTF_TOPOS + _SUPPORTED_T1_TOPOS): @@ -123,7 +127,7 @@ def copp_testbed(duthost, creds, ptfhost, tbinfo, request): _teardown_testbed(duthost, creds, ptfhost, test_params) @pytest.fixture(autouse=True) -def ignore_expected_loganalyzer_exceptions(duthost, loganalyzer): +def ignore_expected_loganalyzer_exceptions(loganalyzer): """ Ignore expected failures logs during test execution. diff --git a/tests/crm/conftest.py b/tests/crm/conftest.py index 1fb0fb7ff37..abd6d80c772 100755 --- a/tests/crm/conftest.py +++ b/tests/crm/conftest.py @@ -56,7 +56,8 @@ def pytest_runtest_teardown(item, nextitem): @pytest.fixture(scope="module", autouse=True) -def crm_thresholds(duthost): +def crm_thresholds(duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] cmd = "sonic-db-cli CONFIG_DB hget \"CRM|Config\" {threshold_name}_{type}_threshold" crm_res_list = ["ipv4_route", "ipv6_route", "ipv4_nexthop", "ipv6_nexthop", "ipv4_neighbor", "ipv6_neighbor", "nexthop_group_member", "nexthop_group", "acl_counter", "acl_entry", "fdb_entry"] @@ -72,8 +73,9 @@ def crm_thresholds(duthost): @pytest.fixture(scope="module", autouse=True) -def crm_interface(duthost): +def crm_interface(duthosts, rand_one_dut_hostname): """ Return tuple of two DUT interfaces """ + duthost = duthosts[rand_one_dut_hostname] mg_facts = duthost.minigraph_facts(host=duthost.hostname)["ansible_facts"] if len(mg_facts["minigraph_portchannel_interfaces"]) >= 4: @@ -86,8 +88,9 @@ def crm_interface(duthost): @pytest.fixture(scope="module", autouse=True) -def set_polling_interval(duthost): +def set_polling_interval(duthosts, rand_one_dut_hostname): """ Set CRM polling interval to 1 second """ + duthost = duthosts[rand_one_dut_hostname] wait_time = 2 duthost.command("crm config polling interval {}".format(CRM_POLLING_INTERVAL))["stdout"] logger.info("Waiting {} sec for CRM counters to become updated".format(wait_time)) @@ -95,7 +98,7 @@ def set_polling_interval(duthost): @pytest.fixture(scope="module") -def collector(duthost): +def collector(): """ Fixture for sharing variables beatween test cases """ data = {} yield data diff --git a/tests/crm/test_crm.py b/tests/crm/test_crm.py index 012eea6b01e..e55bc7997e8 100755 --- a/tests/crm/test_crm.py +++ b/tests/crm/test_crm.py @@ -348,7 +348,8 @@ def get_entries_num(used, available): ("6", "ip -6 route add 2001::/126 via {}", "ip -6 route del 2001::/126 via {}")], ids=["ipv4", "ipv6"]) -def test_crm_route(duthost, crm_interface, ip_ver, route_add_cmd, route_del_cmd): +def test_crm_route(duthosts, rand_one_dut_hostname, crm_interface, ip_ver, route_add_cmd, route_del_cmd): + duthost = duthosts[rand_one_dut_hostname] RESTORE_CMDS["crm_threshold_name"] = "ipv{ip_ver}_route".format(ip_ver=ip_ver) # Template used to speedup execution of many similar commands on DUT @@ -440,7 +441,8 @@ def test_crm_route(duthost, crm_interface, ip_ver, route_add_cmd, route_del_cmd) @pytest.mark.parametrize("ip_ver,nexthop", [("4", "2.2.2.2"), ("6", "2001::1")]) -def test_crm_nexthop(duthost, crm_interface, ip_ver, nexthop): +def test_crm_nexthop(duthosts, rand_one_dut_hostname, crm_interface, ip_ver, nexthop): + duthost = duthosts[rand_one_dut_hostname] RESTORE_CMDS["crm_threshold_name"] = "ipv{ip_ver}_nexthop".format(ip_ver=ip_ver) nexthop_add_cmd = "ip neigh replace {nexthop} lladdr 11:22:33:44:55:66 dev {iface}".format(nexthop=nexthop, iface=crm_interface[0]) @@ -507,7 +509,8 @@ def test_crm_nexthop(duthost, crm_interface, ip_ver, nexthop): @pytest.mark.parametrize("ip_ver,neighbor", [("4", "2.2.2.2"), ("6", "2001::1")]) -def test_crm_neighbor(duthost, crm_interface, ip_ver, neighbor): +def test_crm_neighbor(duthosts, rand_one_dut_hostname, crm_interface, ip_ver, neighbor): + duthost = duthosts[rand_one_dut_hostname] RESTORE_CMDS["crm_threshold_name"] = "ipv{ip_ver}_neighbor".format(ip_ver=ip_ver) neighbor_add_cmd = "ip neigh replace {neighbor} lladdr 11:22:33:44:55:66 dev {iface}".format(neighbor=neighbor, iface=crm_interface[0]) neighbor_del_cmd = "ip neigh del {neighbor} lladdr 11:22:33:44:55:66 dev {iface}".format(neighbor=neighbor, iface=crm_interface[0]) @@ -572,7 +575,8 @@ def test_crm_neighbor(duthost, crm_interface, ip_ver, neighbor): @pytest.mark.parametrize("group_member,network", [(False, "2.2.2.0/24"), (True, "2.2.2.0/24")]) -def test_crm_nexthop_group(duthost, crm_interface, group_member, network): +def test_crm_nexthop_group(duthosts, rand_one_dut_hostname, crm_interface, group_member, network): + duthost = duthosts[rand_one_dut_hostname] RESTORE_CMDS["crm_threshold_name"] = "nexthop_group_member" if group_member else "nexthop_group" redis_threshold = "nexthop group member" if group_member else "nexthop group object" get_group_stats = "redis-cli --raw -n 2 HMGET CRM:STATS crm_stats_nexthop_group_used crm_stats_nexthop_group_available" @@ -668,7 +672,8 @@ def test_crm_nexthop_group(duthost, crm_interface, group_member, network): crm_avail=new_nexthop_group_available) -def test_acl_entry(duthost, collector): +def test_acl_entry(duthosts, rand_one_dut_hostname, collector): + duthost = duthosts[rand_one_dut_hostname] apply_acl_config(duthost, "test_acl_entry", collector) acl_tbl_key = collector["acl_tbl_key"] get_acl_entry_stats = "redis-cli --raw -n 2 HMGET {acl_tbl_key} crm_stats_acl_entry_used \ @@ -728,7 +733,8 @@ def test_acl_entry(duthost, collector): "\"crm_stats_acl_entry_available\" counter was not incremented") -def test_acl_counter(duthost, collector): +def test_acl_counter(duthosts, rand_one_dut_hostname, collector): + duthost = duthosts[rand_one_dut_hostname] if not "acl_tbl_key" in collector: pytest.skip("acl_tbl_key is not retrieved") acl_tbl_key = collector["acl_tbl_key"] @@ -799,7 +805,8 @@ def test_acl_counter(duthost, collector): "\"crm_stats_acl_counter_available\" counter is not equal to original value") -def test_crm_fdb_entry(duthost, tbinfo): +def test_crm_fdb_entry(duthosts, rand_one_dut_hostname, tbinfo): + duthost = duthosts[rand_one_dut_hostname] if "t0" not in tbinfo["topo"]["name"].lower(): pytest.skip("Unsupported topology, expected to run only on 'T0*' topology") diff --git a/tests/decap/test_decap.py b/tests/decap/test_decap.py index 8b74f5002ce..873169c8228 100644 --- a/tests/decap/test_decap.py +++ b/tests/decap/test_decap.py @@ -118,7 +118,8 @@ def prepare_ptf(ptfhost, tbinfo, cfg_facts): @pytest.fixture(scope="module") -def setup_teardown(request, tbinfo, duthost, ptfhost): +def setup_teardown(request, tbinfo, duthosts, rand_one_dut_hostname, ptfhost): + duthost = duthosts[rand_one_dut_hostname] # Initialize parameters dscp_mode = "pipe" diff --git a/tests/dhcp_relay/test_dhcp_relay.py b/tests/dhcp_relay/test_dhcp_relay.py index c13f06878b8..e77bb5987c7 100644 --- a/tests/dhcp_relay/test_dhcp_relay.py +++ b/tests/dhcp_relay/test_dhcp_relay.py @@ -28,12 +28,13 @@ def ignore_expected_loganalyzer_exceptions(loganalyzer): @pytest.fixture(scope="module") -def dut_dhcp_relay_data(duthost, ptfhost): +def dut_dhcp_relay_data(duthosts, rand_one_dut_hostname, ptfhost): """ Fixture which returns a list of dictionaries where each dictionary contains data necessary to test one instance of a DHCP relay agent running on the DuT. This fixture is scoped to the module, as the data it gathers can be used by all tests in this module. It does not need to be run before each test. """ + duthost = duthosts[rand_one_dut_hostname] dhcp_relay_data_list = [] mg_facts = duthost.minigraph_facts(host=duthost.hostname)['ansible_facts'] @@ -96,9 +97,10 @@ def dut_dhcp_relay_data(duthost, ptfhost): return dhcp_relay_data_list @pytest.fixture(scope="module") -def validate_dut_routes_exist(duthost, dut_dhcp_relay_data): +def validate_dut_routes_exist(duthosts, rand_one_dut_hostname, dut_dhcp_relay_data): """Fixture to valid a route to each DHCP server exist """ + duthost = duthosts[rand_one_dut_hostname] dhcp_servers = set() for dhcp_relay in dut_dhcp_relay_data: dhcp_servers |= set(dhcp_relay['downlink_vlan_iface']['dhcp_server_addrs']) @@ -108,11 +110,12 @@ def validate_dut_routes_exist(duthost, dut_dhcp_relay_data): assert len(rtInfo["nexthops"]) > 0, "Failed to find route to DHCP server '{0}'".format(dhcp_server) -def test_dhcp_relay_default(duthost, ptfhost, dut_dhcp_relay_data, validate_dut_routes_exist): +def test_dhcp_relay_default(duthosts, rand_one_dut_hostname, ptfhost, dut_dhcp_relay_data, validate_dut_routes_exist): """Test DHCP relay functionality on T0 topology. For each DHCP relay agent running on the DuT, verify DHCP packets are relayed properly """ + duthost = duthosts[rand_one_dut_hostname] for dhcp_relay in dut_dhcp_relay_data: # Run the DHCP relay test on the PTF host ptf_runner(ptfhost, @@ -133,12 +136,13 @@ def test_dhcp_relay_default(duthost, ptfhost, dut_dhcp_relay_data, validate_dut_ log_file="/tmp/dhcp_relay_test.DHCPTest.log") -def test_dhcp_relay_after_link_flap(duthost, ptfhost, dut_dhcp_relay_data, validate_dut_routes_exist): +def test_dhcp_relay_after_link_flap(duthosts, rand_one_dut_hostname, ptfhost, dut_dhcp_relay_data, validate_dut_routes_exist): """Test DHCP relay functionality on T0 topology after uplinks flap For each DHCP relay agent running on the DuT, with relay agent running, flap the uplinks, then test whether the DHCP relay agent relays packets properly. """ + duthost = duthosts[rand_one_dut_hostname] for dhcp_relay in dut_dhcp_relay_data: # Bring all uplink interfaces down for iface in dhcp_relay['uplink_interfaces']: @@ -173,13 +177,14 @@ def test_dhcp_relay_after_link_flap(duthost, ptfhost, dut_dhcp_relay_data, valid log_file="/tmp/dhcp_relay_test.DHCPTest.log") -def test_dhcp_relay_start_with_uplinks_down(duthost, ptfhost, dut_dhcp_relay_data, validate_dut_routes_exist): +def test_dhcp_relay_start_with_uplinks_down(duthosts, rand_one_dut_hostname, ptfhost, dut_dhcp_relay_data, validate_dut_routes_exist): """Test DHCP relay functionality on T0 topology when relay agent starts with uplinks down For each DHCP relay agent running on the DuT, bring the uplinks down, then restart the relay agent while the uplinks are still down. Then test whether the DHCP relay agent relays packets properly. """ + duthost = duthosts[rand_one_dut_hostname] for dhcp_relay in dut_dhcp_relay_data: # Bring all uplink interfaces down for iface in dhcp_relay['uplink_interfaces']: @@ -221,11 +226,12 @@ def test_dhcp_relay_start_with_uplinks_down(duthost, ptfhost, dut_dhcp_relay_dat log_file="/tmp/dhcp_relay_test.DHCPTest.log") -def test_dhcp_relay_unicast_mac(duthost, ptfhost, dut_dhcp_relay_data, validate_dut_routes_exist): +def test_dhcp_relay_unicast_mac(duthosts, rand_one_dut_hostname, ptfhost, dut_dhcp_relay_data, validate_dut_routes_exist): """Test DHCP relay functionality on T0 topology with unicast mac Instead of using broadcast MAC, use unicast MAC of DUT and verify that DHCP relay functionality is entact. """ + duthost = duthosts[rand_one_dut_hostname] for dhcp_relay in dut_dhcp_relay_data: # Run the DHCP relay test on the PTF host ptf_runner(ptfhost, @@ -246,12 +252,13 @@ def test_dhcp_relay_unicast_mac(duthost, ptfhost, dut_dhcp_relay_data, validate_ log_file="/tmp/dhcp_relay_test.DHCPTest.log") -def test_dhcp_relay_random_sport(duthost, ptfhost, dut_dhcp_relay_data, validate_dut_routes_exist): +def test_dhcp_relay_random_sport(duthosts, rand_one_dut_hostname, ptfhost, dut_dhcp_relay_data, validate_dut_routes_exist): """Test DHCP relay functionality on T0 topology with random source port (sport) If the client is SNAT'd, the source port could be changed to a non-standard port (i.e., not 68). Verify that DHCP relay works with random high sport. """ + duthost = duthosts[rand_one_dut_hostname] RANDOM_CLIENT_PORT = random.choice(range(1000, 65535)) for dhcp_relay in dut_dhcp_relay_data: # Run the DHCP relay test on the PTF host diff --git a/tests/drop_packets/drop_packets.py b/tests/drop_packets/drop_packets.py index bfae35433af..f3f406d4a2c 100644 --- a/tests/drop_packets/drop_packets.py +++ b/tests/drop_packets/drop_packets.py @@ -27,7 +27,7 @@ @pytest.fixture -def fanouthost(request, duthost, localhost): +def fanouthost(request, duthosts, rand_one_dut_hostname, localhost): """ Fixture that allows to update Fanout configuration if there is a need to send incorrect packets. Added possibility to create vendor specific logic to handle fanout configuration. @@ -36,6 +36,7 @@ def fanouthost(request, duthost, localhost): By default 'fanouthost' fixture will not instantiate any instance so it will return None, and in such case 'fanouthost' instance should not be used in test case logic. """ + duthost = duthosts[rand_one_dut_hostname] fanout = None # Check that class to handle fanout config is implemented if "mellanox" == duthost.facts["asic_type"]: @@ -53,7 +54,8 @@ def fanouthost(request, duthost, localhost): @pytest.fixture(scope="module") -def pkt_fields(duthost): +def pkt_fields(duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] # Gather ansible facts mg_facts = duthost.minigraph_facts(host=duthost.hostname)['ansible_facts'] ipv4_addr = None @@ -98,12 +100,13 @@ def expected_packet_mask(pkt): @pytest.fixture(scope="module") -def setup(duthost, tbinfo): +def setup(duthosts, rand_one_dut_hostname, tbinfo): """ Setup fixture for collecting PortChannel, VLAN and RIF port members. @return: Dictionary with keys: port_channel_members, vlan_members, rif_members, dut_to_ptf_port_map, neighbor_sniff_ports, vlans, mg_facts """ + duthost = duthosts[rand_one_dut_hostname] port_channel_members = {} vlan_members = {} configured_vlans = [] @@ -146,11 +149,12 @@ def setup(duthost, tbinfo): @pytest.fixture -def rif_port_down(duthost, setup, fanouthosts, loganalyzer): +def rif_port_down(duthosts, rand_one_dut_hostname, setup, fanouthosts, loganalyzer): """Shut RIF interface and return neighbor IP address attached to this interface. The RIF member is shut from the fanout side so that the ARP entry remains in place on the DUT.""" + duthost = duthosts[rand_one_dut_hostname] wait_after_ports_up = 30 if not setup["rif_members"]: @@ -190,7 +194,7 @@ def tx_dut_ports(request, setup): @pytest.fixture -def ports_info(ptfadapter, duthost, setup, tx_dut_ports): +def ports_info(ptfadapter, duthosts, rand_one_dut_hostname, setup, tx_dut_ports): """ Return: dut_iface - DUT interface name expected to receive packtes from PTF @@ -198,6 +202,7 @@ def ports_info(ptfadapter, duthost, setup, tx_dut_ports): dst_mac - DUT interface destination MAC address src_mac - PTF interface source MAC address """ + duthost = duthosts[rand_one_dut_hostname] data = {} data["dut_iface"] = random.choice(tx_dut_ports.keys()) data["ptf_tx_port_id"] = setup["dut_to_ptf_port_map"][data["dut_iface"]] diff --git a/tests/drop_packets/test_configurable_drop_counters.py b/tests/drop_packets/test_configurable_drop_counters.py index 775c6bcea0a..b67bdaec24b 100644 --- a/tests/drop_packets/test_configurable_drop_counters.py +++ b/tests/drop_packets/test_configurable_drop_counters.py @@ -37,7 +37,7 @@ MOCK_DEST_IP = "2.2.2.2" @pytest.mark.parametrize("drop_reason", ["L3_EGRESS_LINK_DOWN"]) -def test_neighbor_link_down(testbed_params, setup_counters, duthost, mock_server, +def test_neighbor_link_down(testbed_params, setup_counters, duthosts, rand_one_dut_hostname, mock_server, send_dropped_traffic, drop_reason): """ Verifies counters that check for a neighbor link being down. @@ -49,6 +49,7 @@ def test_neighbor_link_down(testbed_params, setup_counters, duthost, mock_server Args: drop_reason (str): The drop reason being tested. """ + duthost = duthosts[rand_one_dut_hostname] counter_type = setup_counters([drop_reason]) rx_port = random.choice([port @@ -71,12 +72,13 @@ def test_neighbor_link_down(testbed_params, setup_counters, duthost, mock_server @pytest.fixture(scope="module") -def testbed_params(duthost, tbinfo): +def testbed_params(duthosts, rand_one_dut_hostname, tbinfo): """ Gathers parameters about the testbed for the test cases to use. Returns: A Dictionary with the following information: """ + duthost = duthosts[rand_one_dut_hostname] if tbinfo["topo"]["type"] != "t0": pytest.skip("Unsupported topology {}".format(tbinfo["topo"]["name"])) @@ -98,7 +100,7 @@ def testbed_params(duthost, tbinfo): @pytest.fixture(scope="module") -def device_capabilities(duthost): +def device_capabilities(duthosts, rand_one_dut_hostname): """ Gather information about the DUT's drop counter capabilities. @@ -107,6 +109,7 @@ def device_capabilities(duthost): `configurable_drop_counters` package). """ + duthost = duthosts[rand_one_dut_hostname] capabilities = cdc.get_device_capabilities(duthost) pytest_assert(capabilities, "Error fetching device capabilities") @@ -116,7 +119,7 @@ def device_capabilities(duthost): @pytest.fixture(params=cdc.SUPPORTED_COUNTER_TYPES) -def setup_counters(request, device_capabilities, duthost): +def setup_counters(request, device_capabilities, duthosts, rand_one_dut_hostname): """ Return a method to setup drop counters. @@ -127,6 +130,7 @@ def setup_counters(request, device_capabilities, duthost): A method which, when called, will create a drop counter with the specified drop reasons. """ + duthost = duthosts[rand_one_dut_hostname] if request.param not in device_capabilities["counters"]: pytest.skip("Counter type not supported on target DUT") @@ -155,7 +159,7 @@ def _setup_counters(drop_reasons): @pytest.fixture -def send_dropped_traffic(duthost, ptfadapter, testbed_params): +def send_dropped_traffic(duthosts, rand_one_dut_hostname, ptfadapter, testbed_params): """ Return a method to send traffic to the DUT to be dropped. @@ -164,6 +168,7 @@ def send_dropped_traffic(duthost, ptfadapter, testbed_params): drop counter has been incremented. """ + duthost = duthosts[rand_one_dut_hostname] def _runner(counter_type, pkt, rx_port): duthost.command("sonic-clear dropcounters") @@ -221,7 +226,7 @@ def arp_responder(ptfhost, testbed_params): @pytest.fixture -def mock_server(fanouthosts, testbed_params, arp_responder, ptfadapter, duthost): +def mock_server(fanouthosts, testbed_params, arp_responder, ptfadapter, duthosts, rand_one_dut_hostname): """ Mock the presence of a server beneath a T0. @@ -230,6 +235,7 @@ def mock_server(fanouthosts, testbed_params, arp_responder, ptfadapter, duthost) a server within a VLAN under a T0. """ + duthost = duthosts[rand_one_dut_hostname] server_dst_port = random.choice(arp_responder.keys()) server_dst_addr = random.choice(arp_responder[server_dst_port].keys()) server_dst_intf = testbed_params["physical_port_map"][server_dst_port] diff --git a/tests/drop_packets/test_drop_counters.py b/tests/drop_packets/test_drop_counters.py index 73b133d3897..d48327f4a9b 100755 --- a/tests/drop_packets/test_drop_counters.py +++ b/tests/drop_packets/test_drop_counters.py @@ -34,8 +34,9 @@ @pytest.fixture(autouse=True, scope="module") -def enable_counters(duthost): +def enable_counters(duthosts, rand_one_dut_hostname): """ Fixture which enables RIF and L2 counters """ + duthost = duthosts[rand_one_dut_hostname] cmd_list = ["intfstat -D", "counterpoll port enable", "counterpoll rif enable", "sonic-clear counters", "sonic-clear rifcounters"] cmd_get_cnt_status = "redis-cli -n 4 HGET \"FLEX_COUNTER_TABLE|{}\" \"FLEX_COUNTER_STATUS\"" @@ -52,8 +53,9 @@ def enable_counters(duthost): @pytest.fixture -def acl_setup(duthost, loganalyzer): +def acl_setup(duthosts, rand_one_dut_hostname, loganalyzer): """ Create acl rule defined in config file. Delete rule after test case finished """ + duthost = duthosts[rand_one_dut_hostname] base_dir = os.path.dirname(os.path.realpath(__file__)) template_dir = os.path.join(base_dir, 'acl_templates') acl_rules_template = "acltb_test_rule.json" @@ -87,7 +89,8 @@ def acl_setup(duthost, loganalyzer): @pytest.fixture(scope='module', autouse=True) -def parse_combined_counters(duthost): +def parse_combined_counters(duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] # Get info whether L2 and L3 drop counters are linked # Or ACL and L2 drop counters are linked global COMBINED_L2L3_DROP_COUNTER, COMBINED_ACL_DROP_COUNTER @@ -215,8 +218,9 @@ def base_verification(discard_group, pkt, ptfadapter, duthost, ports_info, tx_du @pytest.fixture -def mtu_config(duthost): +def mtu_config(duthosts, rand_one_dut_hostname): """ Fixture which prepare port MTU configuration for 'test_ip_pkt_with_exceeded_mtu' test case """ + duthost = duthosts[rand_one_dut_hostname] class MTUConfig(object): iface = None mtu = None @@ -278,13 +282,14 @@ def do_counters_test(discard_group, pkt, ptfadapter, duthost, ports_info, sniff_ return do_counters_test -def test_reserved_dmac_drop(do_test, ptfadapter, duthost, setup, fanouthost, pkt_fields, ports_info): +def test_reserved_dmac_drop(do_test, ptfadapter, duthosts, rand_one_dut_hostname, setup, fanouthost, pkt_fields, ports_info): """ @summary: Verify that packet with reserved DMAC is dropped and L2 drop counter incremented @used_mac_address: 01:80:C2:00:00:05 - reserved for future standardization 01:80:C2:00:00:08 - provider Bridge group address """ + duthost = duthosts[rand_one_dut_hostname] if not fanouthost: pytest.skip("Test case requires explicit fanout support") @@ -311,10 +316,11 @@ def test_reserved_dmac_drop(do_test, ptfadapter, duthost, setup, fanouthost, pkt do_test("L2", pkt, ptfadapter, duthost, ports_info, setup["neighbor_sniff_ports"]) -def test_acl_drop(do_test, ptfadapter, duthost, setup, tx_dut_ports, pkt_fields, acl_setup, ports_info): +def test_acl_drop(do_test, ptfadapter, duthosts, rand_one_dut_hostname, setup, tx_dut_ports, pkt_fields, acl_setup, ports_info): """ @summary: Verify that DUT drops packet with SRC IP 20.0.0.0/24 matched by ingress ACL and ACL drop counter incremented """ + duthost = duthosts[rand_one_dut_hostname] if tx_dut_ports[ports_info["dut_iface"]] not in duthost.acl_facts()["ansible_facts"]["ansible_acl_facts"]["DATAACL"]["ports"]: pytest.skip("RX DUT port absent in 'DATAACL' table") @@ -338,10 +344,11 @@ def test_acl_drop(do_test, ptfadapter, duthost, setup, tx_dut_ports, pkt_fields, testutils.verify_no_packet_any(ptfadapter, exp_pkt, ports=setup["neighbor_sniff_ports"]) -def test_egress_drop_on_down_link(do_test, ptfadapter, duthost, setup, tx_dut_ports, pkt_fields, rif_port_down, ports_info): +def test_egress_drop_on_down_link(do_test, ptfadapter, duthosts, rand_one_dut_hostname, setup, tx_dut_ports, pkt_fields, rif_port_down, ports_info): """ @summary: Verify that packets on ingress port are dropped when egress RIF link is down and check that L3 drop counter incremented """ + duthost = duthosts[rand_one_dut_hostname] ip_dst = rif_port_down log_pkt_params(ports_info["dut_iface"], ports_info["dst_mac"], ports_info["src_mac"], ip_dst, pkt_fields["ipv4_src"]) @@ -358,10 +365,11 @@ def test_egress_drop_on_down_link(do_test, ptfadapter, duthost, setup, tx_dut_po do_test("L3", pkt, ptfadapter, duthost, ports_info, setup["neighbor_sniff_ports"], tx_dut_ports) -def test_src_ip_link_local(do_test, ptfadapter, duthost, setup, tx_dut_ports, pkt_fields, ports_info): +def test_src_ip_link_local(do_test, ptfadapter, duthosts, rand_one_dut_hostname, setup, tx_dut_ports, pkt_fields, ports_info): """ @summary: Verify that packet with link-local address "169.254.0.0/16" is dropped and L3 drop counter incremented """ + duthost = duthosts[rand_one_dut_hostname] link_local_ip = "169.254.10.125" @@ -381,10 +389,11 @@ def test_src_ip_link_local(do_test, ptfadapter, duthost, setup, tx_dut_ports, pk do_test("L3", pkt, ptfadapter, duthost, ports_info, setup["neighbor_sniff_ports"], tx_dut_ports) -def test_ip_pkt_with_exceeded_mtu(do_test, ptfadapter, duthost, setup, tx_dut_ports, pkt_fields, mtu_config, ports_info): +def test_ip_pkt_with_exceeded_mtu(do_test, ptfadapter, duthosts, rand_one_dut_hostname, setup, tx_dut_ports, pkt_fields, mtu_config, ports_info): """ @summary: Verify that IP packet with exceeded MTU is dropped and L3 drop counter incremented """ + duthost = duthosts[rand_one_dut_hostname] global L2_COL_KEY if "vlan" in tx_dut_ports[ports_info["dut_iface"]].lower(): diff --git a/tests/ecmp/test_fgnhg.py b/tests/ecmp/test_fgnhg.py index f10068d06bd..36986a2d926 100644 --- a/tests/ecmp/test_fgnhg.py +++ b/tests/ecmp/test_fgnhg.py @@ -307,7 +307,8 @@ def cleanup(duthost): @pytest.fixture(scope="module") -def common_setup_teardown(tbinfo, duthost): +def common_setup_teardown(tbinfo, duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] if tbinfo['topo']['name'] not in SUPPORTED_TOPO: logger.warning("Unsupported topology, currently supports " + str(SUPPORTED_TOPO)) pytest.skip("Unsupported topology") diff --git a/tests/everflow/everflow_test_utilities.py b/tests/everflow/everflow_test_utilities.py index 80f54a3f9d6..faa28f94dd7 100644 --- a/tests/everflow/everflow_test_utilities.py +++ b/tests/everflow/everflow_test_utilities.py @@ -32,7 +32,7 @@ @pytest.fixture(scope="module") -def setup_info(duthost, tbinfo): +def setup_info(duthosts, rand_one_dut_hostname, tbinfo): """ Gather all required test information. @@ -44,6 +44,7 @@ def setup_info(duthost, tbinfo): dict: Required test information """ + duthost = duthosts[rand_one_dut_hostname] tor_ports = [] spine_ports = [] diff --git a/tests/everflow/test_everflow_ipv6.py b/tests/everflow/test_everflow_ipv6.py index fc7746721a7..d41d7422c41 100644 --- a/tests/everflow/test_everflow_ipv6.py +++ b/tests/everflow/test_everflow_ipv6.py @@ -28,8 +28,9 @@ class EverflowIPv6Tests(BaseEverflowTest): DEFAULT_SRC_IP = "ffbe:0225:7c6b:a982:d48b:230e:f271:0000" DEFAULT_DST_IP = "ffbe:0225:7c6b:a982:d48b:230e:f271:0001" - def test_src_ipv6_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthost): + def test_src_ipv6_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthosts, rand_one_dut_hostname): """Verify that we can match on Source IPv6 addresses.""" + duthost = duthosts[rand_one_dut_hostname] test_packet = self._base_tcpv6_packet( ptfadapter, setup_info, @@ -42,8 +43,9 @@ def test_src_ipv6_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthost, test_packet) - def test_dst_ipv6_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthost): + def test_dst_ipv6_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthosts, rand_one_dut_hostname): """Verify that we can match on Destination IPv6 addresses.""" + duthost = duthosts[rand_one_dut_hostname] test_packet = self._base_tcpv6_packet( ptfadapter, setup_info, @@ -56,8 +58,9 @@ def test_dst_ipv6_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthost, test_packet) - def test_next_header_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthost): + def test_next_header_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthosts, rand_one_dut_hostname): """Verify that we can match on the Next Header field.""" + duthost = duthosts[rand_one_dut_hostname] test_packet = self._base_tcpv6_packet(ptfadapter, setup_info, next_header=0x7E) self.send_and_check_mirror_packets(setup_info, @@ -66,8 +69,9 @@ def test_next_header_mirroring(self, setup_info, setup_mirror_session, ptfadapte duthost, test_packet) - def test_l4_src_port_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthost): + def test_l4_src_port_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthosts, rand_one_dut_hostname): """Verify that we can match on the L4 Source Port.""" + duthost = duthosts[rand_one_dut_hostname] test_packet = self._base_tcpv6_packet(ptfadapter, setup_info, sport=9000) self.send_and_check_mirror_packets(setup_info, @@ -76,8 +80,9 @@ def test_l4_src_port_mirroring(self, setup_info, setup_mirror_session, ptfadapte duthost, test_packet) - def test_l4_dst_port_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthost): + def test_l4_dst_port_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthosts, rand_one_dut_hostname): """Verify that we can match on the L4 Destination Port.""" + duthost = duthosts[rand_one_dut_hostname] test_packet = self._base_tcpv6_packet(ptfadapter, setup_info, dport=9001) self.send_and_check_mirror_packets(setup_info, @@ -86,8 +91,9 @@ def test_l4_dst_port_mirroring(self, setup_info, setup_mirror_session, ptfadapte duthost, test_packet) - def test_l4_src_port_range_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthost): + def test_l4_src_port_range_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthosts, rand_one_dut_hostname): """Verify that we can match on a range of L4 Source Ports.""" + duthost = duthosts[rand_one_dut_hostname] test_packet = self._base_tcpv6_packet(ptfadapter, setup_info, sport=10200) self.send_and_check_mirror_packets(setup_info, @@ -96,8 +102,9 @@ def test_l4_src_port_range_mirroring(self, setup_info, setup_mirror_session, ptf duthost, test_packet) - def test_l4_dst_port_range_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthost): + def test_l4_dst_port_range_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthosts, rand_one_dut_hostname): """Verify that we can match on a range of L4 Destination Ports.""" + duthost = duthosts[rand_one_dut_hostname] test_packet = self._base_tcpv6_packet(ptfadapter, setup_info, dport=10700) self.send_and_check_mirror_packets(setup_info, @@ -106,8 +113,9 @@ def test_l4_dst_port_range_mirroring(self, setup_info, setup_mirror_session, ptf duthost, test_packet) - def test_tcp_flags_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthost): + def test_tcp_flags_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthosts, rand_one_dut_hostname): """Verify that we can match on TCP Flags.""" + duthost = duthosts[rand_one_dut_hostname] test_packet = self._base_tcpv6_packet(ptfadapter, setup_info, flags=0x1B) self.send_and_check_mirror_packets(setup_info, @@ -116,8 +124,9 @@ def test_tcp_flags_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthost, test_packet) - def test_dscp_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthost): + def test_dscp_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthosts, rand_one_dut_hostname): """Verify that we can match on DSCP.""" + duthost = duthosts[rand_one_dut_hostname] test_packet = self._base_tcpv6_packet(ptfadapter, setup_info, dscp=37) self.send_and_check_mirror_packets(setup_info, @@ -126,8 +135,9 @@ def test_dscp_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duth duthost, test_packet) - def test_l4_range_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthost): + def test_l4_range_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthosts, rand_one_dut_hostname): """Verify that we can match from a source port to a range of destination ports and vice-versa.""" + duthost = duthosts[rand_one_dut_hostname] test_packet = self._base_tcpv6_packet( ptfadapter, setup_info, @@ -158,8 +168,9 @@ def test_l4_range_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthost, test_packet) - def test_tcp_response_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthost): + def test_tcp_response_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthosts, rand_one_dut_hostname): """Verify that we can match a SYN -> SYN-ACK pattern.""" + duthost = duthosts[rand_one_dut_hostname] test_packet = self._base_tcpv6_packet( ptfadapter, setup_info, @@ -188,8 +199,9 @@ def test_tcp_response_mirroring(self, setup_info, setup_mirror_session, ptfadapt duthost, test_packet) - def test_tcp_application_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthost): + def test_tcp_application_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthosts, rand_one_dut_hostname): """Verify that we can match a TCP handshake between a client and server.""" + duthost = duthosts[rand_one_dut_hostname] test_packet = self._base_tcpv6_packet( ptfadapter, setup_info, @@ -222,8 +234,9 @@ def test_tcp_application_mirroring(self, setup_info, setup_mirror_session, ptfad duthost, test_packet) - def test_udp_application_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthost): + def test_udp_application_mirroring(self, setup_info, setup_mirror_session, ptfadapter, duthosts, rand_one_dut_hostname): """Verify that we can match UDP traffic between a client and server application.""" + duthost = duthosts[rand_one_dut_hostname] test_packet = self._base_udpv6_packet( ptfadapter, setup_info, @@ -255,8 +268,9 @@ def test_udp_application_mirroring(self, setup_info, setup_mirror_session, ptfad duthost, test_packet) - def test_any_protocol(self, setup_info, setup_mirror_session, ptfadapter, duthost): + def test_any_protocol(self, setup_info, setup_mirror_session, ptfadapter, duthosts, rand_one_dut_hostname): """Verify that the protocol number is ignored if it is not specified in the ACL rule.""" + duthost = duthosts[rand_one_dut_hostname] test_packet = self._base_tcpv6_packet( ptfadapter, setup_info, @@ -297,8 +311,9 @@ def test_any_protocol(self, setup_info, setup_mirror_session, ptfadapter, duthos duthost, test_packet) - def test_any_transport_protocol(self, setup_info, setup_mirror_session, ptfadapter, duthost): + def test_any_transport_protocol(self, setup_info, setup_mirror_session, ptfadapter, duthosts, rand_one_dut_hostname): """Verify that src port and dst port rules match regardless of whether TCP or UDP traffic is sent.""" + duthost = duthosts[rand_one_dut_hostname] test_packet = self._base_tcpv6_packet( ptfadapter, setup_info, @@ -329,7 +344,7 @@ def test_any_transport_protocol(self, setup_info, setup_mirror_session, ptfadapt duthost, test_packet) - def test_invalid_tcp_rule(self, setup_info, setup_mirror_session, ptfadapter, duthost): + def test_invalid_tcp_rule(self, setup_info, setup_mirror_session, ptfadapter, duthosts, rand_one_dut_hostname): """Verify that the ASIC does not reject rules with TCP flags if the protocol is not TCP.""" pass @@ -338,8 +353,9 @@ def test_invalid_tcp_rule(self, setup_info, setup_mirror_session, ptfadapter, du # will not crash if such a rule is installed. If this does happen, we expect the whole test # suite + loganaylzer + the sanity check to fail. - def test_source_subnet(self, setup_info, setup_mirror_session, ptfadapter, duthost): + def test_source_subnet(self, setup_info, setup_mirror_session, ptfadapter, duthosts, rand_one_dut_hostname): """Verify that we can match packets with a Source IPv6 Subnet.""" + duthost = duthosts[rand_one_dut_hostname] test_packet = self._base_tcpv6_packet( ptfadapter, setup_info, @@ -355,8 +371,9 @@ def test_source_subnet(self, setup_info, setup_mirror_session, ptfadapter, dutho duthost, test_packet) - def test_dest_subnet(self, setup_info, setup_mirror_session, ptfadapter, duthost): + def test_dest_subnet(self, setup_info, setup_mirror_session, ptfadapter, duthosts, rand_one_dut_hostname): """Verify that we can match packets with a Destination IPv6 Subnet.""" + duthost = duthosts[rand_one_dut_hostname] test_packet = self._base_tcpv6_packet( ptfadapter, setup_info, @@ -372,8 +389,9 @@ def test_dest_subnet(self, setup_info, setup_mirror_session, ptfadapter, duthost duthost, test_packet) - def test_both_subnets(self, setup_info, setup_mirror_session, ptfadapter, duthost): + def test_both_subnets(self, setup_info, setup_mirror_session, ptfadapter, duthosts, rand_one_dut_hostname): """Verify that we can match packets with both source and destination subnets.""" + duthost = duthosts[rand_one_dut_hostname] test_packet = self._base_tcpv6_packet( ptfadapter, setup_info, @@ -389,8 +407,9 @@ def test_both_subnets(self, setup_info, setup_mirror_session, ptfadapter, duthos duthost, test_packet) - def test_fuzzy_subnets(self, setup_info, setup_mirror_session, ptfadapter, duthost): + def test_fuzzy_subnets(self, setup_info, setup_mirror_session, ptfadapter, duthosts, rand_one_dut_hostname): """Verify that we can match packets with non-standard subnet sizes.""" + duthost = duthosts[rand_one_dut_hostname] test_packet = self._base_tcpv6_packet( ptfadapter, setup_info, diff --git a/tests/everflow/test_everflow_testbed.py b/tests/everflow/test_everflow_testbed.py index 745b21cb622..74f24ed4dec 100644 --- a/tests/everflow/test_everflow_testbed.py +++ b/tests/everflow/test_everflow_testbed.py @@ -20,13 +20,14 @@ @pytest.fixture -def partial_ptf_runner(request, duthost, ptfhost): +def partial_ptf_runner(request, duthosts, rand_one_dut_hostname, ptfhost): """ Fixture to run each Everflow PTF test case via ptf_runner. Takes all the necessary arguments to run the test case and returns a handle to the caller to execute the ptf_runner. """ + duthost = duthosts[rand_one_dut_hostname] def _partial_ptf_runner(setup_info, session_info, acl_stage, mirror_type, expect_receive = True, test_name = None, **kwargs): # Some of the arguments are fixed for each Everflow test case and defined here. # Arguments specific to each Everflow test case are passed in by each test via _partial_ptf_runner. @@ -80,7 +81,7 @@ def dest_port_type(self, request): # A better solution might be to have a fixture that receives route updates and then # cleans up any remaining routes at the end. - def test_everflow_basic_forwarding(self, duthost, setup_info, setup_mirror_session, dest_port_type, ptfadapter): + def test_everflow_basic_forwarding(self, duthosts, rand_one_dut_hostname, setup_info, setup_mirror_session, dest_port_type, ptfadapter): """ Verify basic forwarding scenarios for the Everflow feature. @@ -90,6 +91,7 @@ def test_everflow_basic_forwarding(self, duthost, setup_info, setup_mirror_sessi - LPM (longest prefix match) - Route creation and removal """ + duthost = duthosts[rand_one_dut_hostname] try: # Add a route to the mirror session destination IP tx_port = setup_info[dest_port_type]["dest_port"][0] @@ -176,8 +178,9 @@ def test_everflow_basic_forwarding(self, duthost, setup_info, setup_mirror_sessi raise - def test_everflow_neighbor_mac_change(self, duthost, setup_info, setup_mirror_session, dest_port_type, ptfadapter): + def test_everflow_neighbor_mac_change(self, duthosts, rand_one_dut_hostname, setup_info, setup_mirror_session, dest_port_type, ptfadapter): """Verify that session destination MAC address is changed after neighbor MAC address update.""" + duthost = duthosts[rand_one_dut_hostname] try: # Add a route to the mirror session destination IP tx_port = setup_info[dest_port_type]["dest_port"][0] @@ -226,8 +229,9 @@ def test_everflow_neighbor_mac_change(self, duthost, setup_info, setup_mirror_se raise - def test_everflow_remove_unused_ecmp_next_hop(self, duthost, setup_info, setup_mirror_session, dest_port_type, ptfadapter): + def test_everflow_remove_unused_ecmp_next_hop(self, duthosts, rand_one_dut_hostname, setup_info, setup_mirror_session, dest_port_type, ptfadapter): """Verify that session is still active after removal of next hop from ECMP route that was not in use.""" + duthost = duthosts[rand_one_dut_hostname] try: # Create two ECMP next hops tx_port = setup_info[dest_port_type]["dest_port"][0] @@ -309,8 +313,9 @@ def test_everflow_remove_unused_ecmp_next_hop(self, duthost, setup_info, setup_m raise - def test_everflow_remove_used_ecmp_next_hop(self, duthost, setup_info, setup_mirror_session, dest_port_type, ptfadapter): + def test_everflow_remove_used_ecmp_next_hop(self, duthosts, rand_one_dut_hostname, setup_info, setup_mirror_session, dest_port_type, ptfadapter): """Verify that session is still active after removal of next hop from ECMP route that was in use.""" + duthost = duthosts[rand_one_dut_hostname] try: # Add a route to the mirror session destination IP tx_port = setup_info[dest_port_type]["dest_port"][0] diff --git a/tests/fdb/test_fdb.py b/tests/fdb/test_fdb.py index aaa67bc16ba..9b748750a21 100644 --- a/tests/fdb/test_fdb.py +++ b/tests/fdb/test_fdb.py @@ -151,8 +151,9 @@ def setup_fdb(ptfadapter, vlan_table, router_mac, pkt_type): @pytest.fixture -def fdb_cleanup(duthost): +def fdb_cleanup(duthosts, rand_one_dut_hostname): """ cleanup FDB before and after test run """ + duthost = duthosts[rand_one_dut_hostname] try: duthost.command('sonic-clear fdb all') yield @@ -164,11 +165,12 @@ def fdb_cleanup(duthost): @pytest.mark.bsl @pytest.mark.usefixtures('fdb_cleanup') @pytest.mark.parametrize("pkt_type", PKT_TYPES) -def test_fdb(ansible_adhoc, ptfadapter, duthost, ptfhost, pkt_type): +def test_fdb(ansible_adhoc, ptfadapter, duthosts, rand_one_dut_hostname, ptfhost, pkt_type): """ 1. verify fdb forwarding. 2. verify show mac command on DUT for learned mac. """ + duthost = duthosts[rand_one_dut_hostname] host_facts = duthost.setup()['ansible_facts'] conf_facts = duthost.config_facts(host=duthost.hostname, source="persistent")['ansible_facts'] diff --git a/tests/fib/test_fib.py b/tests/fib/test_fib.py index 69451cde55b..626105c7568 100644 --- a/tests/fib/test_fib.py +++ b/tests/fib/test_fib.py @@ -27,12 +27,14 @@ @pytest.fixture(scope="module") -def config_facts(duthost): +def config_facts(duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] return duthost.config_facts(host=duthost.hostname, source="running")['ansible_facts'] @pytest.fixture(scope='module') -def build_fib(duthost, ptfhost, config_facts): +def build_fib(duthosts, rand_one_dut_hostname, ptfhost, config_facts): + duthost = duthosts[rand_one_dut_hostname] timestamp = datetime.now().strftime('%Y-%m-%d-%H:%M:%S') @@ -117,7 +119,8 @@ def get_router_interface_ports(config_facts, tbinfo): @pytest.mark.parametrize("ipv4, ipv6, mtu", [pytest.param(True, True, 1514)]) -def test_basic_fib(tbinfo, duthost, ptfhost, ipv4, ipv6, mtu, config_facts, build_fib): +def test_basic_fib(tbinfo, duthosts, rand_one_dut_hostname, ptfhost, ipv4, ipv6, mtu, config_facts, build_fib): + duthost = duthosts[rand_one_dut_hostname] timestamp = datetime.now().strftime('%Y-%m-%d-%H:%M:%S') @@ -150,7 +153,8 @@ def test_basic_fib(tbinfo, duthost, ptfhost, ipv4, ipv6, mtu, config_facts, buil @pytest.fixture(scope="module") -def setup_hash(tbinfo, duthost, config_facts): +def setup_hash(tbinfo, duthosts, rand_one_dut_hostname, config_facts): + duthost = duthosts[rand_one_dut_hostname] timestamp = datetime.now().strftime('%Y-%m-%d-%H:%M:%S') setup_info = {} diff --git a/tests/iface_namingmode/test_iface_namingmode.py b/tests/iface_namingmode/test_iface_namingmode.py index 8415c88826c..6d9b3c28671 100644 --- a/tests/iface_namingmode/test_iface_namingmode.py +++ b/tests/iface_namingmode/test_iface_namingmode.py @@ -13,7 +13,7 @@ logger = logging.getLogger(__name__) @pytest.fixture(scope='module', autouse=True) -def setup(duthost): +def setup(duthosts, rand_one_dut_hostname): """ Sets up all the parameters needed for the interface naming mode tests @@ -23,6 +23,7 @@ def setup(duthost): setup_info: dictionary containing port alias mappings, list of working interfaces, minigraph facts """ + duthost = duthosts[rand_one_dut_hostname] hwsku = duthost.facts['hwsku'] minigraph_facts = duthost.minigraph_facts(host=duthost.hostname)['ansible_facts'] port_alias_facts = duthost.port_alias(hwsku=hwsku)['ansible_facts'] @@ -78,7 +79,7 @@ def setup(duthost): duthost.command('redis-cli -n 4 HSET "PORT|{}" alias {}'.format(item, port_alias_old)) @pytest.fixture(scope='module', params=['alias', 'default']) -def setup_config_mode(ansible_adhoc, duthost, request): +def setup_config_mode(ansible_adhoc, duthosts, rand_one_dut_hostname, request): """ Creates a guest user and configures the interface naming mode @@ -91,6 +92,7 @@ def setup_config_mode(ansible_adhoc, duthost, request): mode: Interface naming mode to be configured ifmode: Current interface naming mode present in the DUT """ + duthost = duthosts[rand_one_dut_hostname] mode = request.param logger.info('Creating a guest user') @@ -556,7 +558,7 @@ def setup_check_topo(self, tbinfo): pytest.skip('Unsupported topology') @pytest.fixture(scope='class', autouse=True) - def reset_config_interface(self, duthost, sample_intf): + def reset_config_interface(self, duthosts, rand_one_dut_hostname, sample_intf): """ Resets the test interface's configurations on completion of all tests in the enclosing test class. @@ -567,6 +569,7 @@ def reset_config_interface(self, duthost, sample_intf): Yields: None """ + duthost = duthosts[rand_one_dut_hostname] interface = sample_intf['default'] interface_ip = sample_intf['ip'] native_speed = sample_intf['native_speed'] @@ -736,11 +739,12 @@ def setup_check_topo(self, setup, tbinfo): if not setup['physical_interfaces']: pytest.skip('No non-portchannel member interface present') - def test_show_arp(self, duthost, setup, setup_config_mode): + def test_show_arp(self, duthosts, rand_one_dut_hostname, setup, setup_config_mode): """ Checks whether 'show arp' lists the interface names as per the configured naming mode """ + duthost = duthosts[rand_one_dut_hostname] dutHostGuest, mode, ifmode = setup_config_mode arptable = duthost.switch_arptable()['ansible_facts']['arptable'] minigraph_portchannels = setup['minigraph_facts']['minigraph_portchannels'] @@ -755,11 +759,12 @@ def test_show_arp(self, duthost, setup, setup_config_mode): elif mode == 'default': assert re.search(r'{}.*\s+{}'.format(item, arptable['v4'][item]['interface']), arp_output) is not None - def test_show_ndp(self, duthost, setup, setup_config_mode): + def test_show_ndp(self, duthosts, rand_one_dut_hostname, setup, setup_config_mode): """ Checks whether 'show ndp' lists the interface names as per the configured naming mode """ + duthost = duthosts[rand_one_dut_hostname] dutHostGuest, mode, ifmode = setup_config_mode arptable = duthost.switch_arptable()['ansible_facts']['arptable'] minigraph_portchannels = setup['minigraph_facts']['minigraph_portchannels'] diff --git a/tests/ipfwd/test_dip_sip.py b/tests/ipfwd/test_dip_sip.py index 1ff074a1780..c7edab22764 100644 --- a/tests/ipfwd/test_dip_sip.py +++ b/tests/ipfwd/test_dip_sip.py @@ -93,7 +93,8 @@ def port_facts(dut, mg_facts): @pytest.fixture(scope='function') -def gather_facts(tbinfo, duthost): +def gather_facts(tbinfo, duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] facts = {} topo_type = tbinfo['topo']['type'] diff --git a/tests/ipfwd/test_dir_bcast.py b/tests/ipfwd/test_dir_bcast.py index 15aba3f39a6..78b6874368b 100644 --- a/tests/ipfwd/test_dir_bcast.py +++ b/tests/ipfwd/test_dir_bcast.py @@ -8,7 +8,8 @@ pytest.mark.topology('t0') ] -def test_dir_bcast(duthost, ptfhost, tbinfo, fib): +def test_dir_bcast(duthosts, rand_one_dut_hostname, ptfhost, tbinfo, fib): + duthost = duthosts[rand_one_dut_hostname] support_testbed_types = frozenset(['t0', 't0-16', 't0-56', 't0-64', 't0-64-32', 't0-116']) testbed_type = tbinfo['topo']['name'] if testbed_type not in support_testbed_types: diff --git a/tests/ipfwd/test_mtu.py b/tests/ipfwd/test_mtu.py index 9cbbd04adc6..2dcd385234e 100644 --- a/tests/ipfwd/test_mtu.py +++ b/tests/ipfwd/test_mtu.py @@ -11,7 +11,8 @@ ] @pytest.mark.parametrize("mtu", [1514,9114]) -def test_mtu(tbinfo, duthost, ptfhost, mtu): +def test_mtu(tbinfo, duthosts, rand_one_dut_hostname, ptfhost, mtu): + duthost = duthosts[rand_one_dut_hostname] testbed_type = tbinfo['topo']['name'] router_mac = duthost.shell('sonic-cfggen -d -v \'DEVICE_METADATA.localhost.mac\'')["stdout_lines"][0].decode("utf-8") diff --git a/tests/ixia/test_ixia_traffic.py b/tests/ixia/test_ixia_traffic.py index 60cbbbd3f1f..2b8622ce848 100644 --- a/tests/ixia/test_ixia_traffic.py +++ b/tests/ixia/test_ixia_traffic.py @@ -28,8 +28,9 @@ from tests.common.ixia.common_helpers import increment_ip_address -def test_testbed(conn_graph_facts, duthost, fanout_graph_facts, +def test_testbed(conn_graph_facts, duthosts, rand_one_dut_hostname, fanout_graph_facts, ixia_api_server_session, fanouthosts): + duthost = duthosts[rand_one_dut_hostname] logger.info("Connection Graph Facts = %s " %(conn_graph_facts)) logger.info("Fanout Graph facts = %s" %(fanout_graph_facts)) diff --git a/tests/lldp/test_lldp.py b/tests/lldp/test_lldp.py index ef02c8807e7..2946932f721 100644 --- a/tests/lldp/test_lldp.py +++ b/tests/lldp/test_lldp.py @@ -8,8 +8,9 @@ pytest.mark.device_type('vs') ] -def test_lldp(duthost, localhost, collect_techsupport): +def test_lldp(duthosts, rand_one_dut_hostname, localhost, collect_techsupport): """ verify the LLDP message on DUT """ + duthost = duthosts[rand_one_dut_hostname] mg_facts = duthost.minigraph_facts(host=duthost.hostname)['ansible_facts'] lldp_facts = duthost.lldp()['ansible_facts'] @@ -31,9 +32,10 @@ def test_lldp(duthost, localhost, collect_techsupport): assert v['port']['ifname'] == mg_facts['minigraph_neighbors'][k]['port'] -def test_lldp_neighbor(duthost, localhost, eos, +def test_lldp_neighbor(duthosts, rand_one_dut_hostname, localhost, eos, collect_techsupport, loganalyzer): """ verify LLDP information on neighbors """ + duthost = duthosts[rand_one_dut_hostname] if loganalyzer: loganalyzer.ignore_regex.extend([ diff --git a/tests/monit/test_monit_status.py b/tests/monit/test_monit_status.py index d28b47e1ce9..e0aabe0983f 100644 --- a/tests/monit/test_monit_status.py +++ b/tests/monit/test_monit_status.py @@ -14,7 +14,8 @@ ] -def test_monit_status(duthost): +def test_monit_status(duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] monit_status_result = duthost.shell("sudo monit status", module_ignore_errors=True) exit_code = monit_status_result["rc"] diff --git a/tests/mvrf/test_mgmtvrf.py b/tests/mvrf/test_mgmtvrf.py index 5526f92ee88..caf0891210f 100644 --- a/tests/mvrf/test_mgmtvrf.py +++ b/tests/mvrf/test_mgmtvrf.py @@ -28,10 +28,11 @@ def restore_config_db(duthost): @pytest.fixture(scope="module", autouse=True) -def setup_mvrf(duthost, localhost): +def setup_mvrf(duthosts, rand_one_dut_hostname, localhost): """ Setup Management vrf configs before the start of testsuite """ + duthost = duthosts[rand_one_dut_hostname] # Backup the original config_db without mgmt vrf config duthost.shell("cp /etc/sonic/config_db.json /etc/sonic/config_db.json.bak") @@ -138,7 +139,8 @@ def test_ping(self, duthost, ptfhost): command = "ping -c 3 " + ptfhost.mgmt_ip execute_dut_command(duthost, command, mvrf=True) - def test_curl(self, duthost, setup_http_server): + def test_curl(self, duthosts, rand_one_dut_hostname, setup_http_server): + duthost = duthosts[rand_one_dut_hostname] logger.info("Test Curl") url, MAGIC_STRING = setup_http_server @@ -154,7 +156,8 @@ def check_ntp_status(self, duthost): ntp_stat = execute_dut_command(duthost, ntpstat_cmd, mvrf=True, ignore_errors=True) return ntp_stat["rc"] == 0 - def test_ntp(self, duthost): + def test_ntp(self, duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] force_ntp = "ntpd -gq" duthost.service(name="ntp", state="stopped") logger.info("Ntp restart in mgmt vrf") @@ -162,7 +165,8 @@ def test_ntp(self, duthost): duthost.service(name="ntp", state="restarted") pytest_assert(wait_until(100, 10, self.check_ntp_status, duthost), "Ntp not started") - def test_service_acl(self, duthost, localhost): + def test_service_acl(self, duthosts, rand_one_dut_hostname, localhost): + duthost = duthosts[rand_one_dut_hostname] # SSH definitions logger.info("test Service acl") @@ -190,26 +194,29 @@ def basic_check_after_reboot(self, duthost, localhost, ptfhost, creds): verify_show_command(duthost) inbound_test = TestMvrfInbound() outbound_test = TestMvrfOutbound() - outbound_test.test_ping(duthost, ptfhost) - inbound_test.test_ping(duthost) - inbound_test.test_snmp_fact(localhost, duthost, creds) + outbound_test.test_ping(duthost=duthost, ptfhost=ptfhost) + inbound_test.test_ping(duthost=duthost) + inbound_test.test_snmp_fact(localhost=localhost, duthost=duthost, creds=creds) @pytest.mark.disable_loganalyzer - def test_warmboot(self, duthost, localhost, ptfhost, creds): + def test_warmboot(self, duthosts, rand_one_dut_hostname, localhost, ptfhost, creds): + duthost = duthosts[rand_one_dut_hostname] duthost.command("sudo config save -y") # This will override config_db.json with mgmt vrf config reboot(duthost, localhost, reboot_type="warm") pytest_assert(wait_until(120, 20, duthost.critical_services_fully_started), "Not all critical services are fully started") self.basic_check_after_reboot(duthost, localhost, ptfhost, creds) @pytest.mark.disable_loganalyzer - def test_reboot(self, duthost, localhost, ptfhost, creds): + def test_reboot(self, duthosts, rand_one_dut_hostname, localhost, ptfhost, creds): + duthost = duthosts[rand_one_dut_hostname] duthost.command("sudo config save -y") # This will override config_db.json with mgmt vrf config reboot(duthost, localhost) pytest_assert(wait_until(300, 20, duthost.critical_services_fully_started), "Not all critical services are fully started") self.basic_check_after_reboot(duthost, localhost, ptfhost, creds) @pytest.mark.disable_loganalyzer - def test_fastboot(self, duthost, localhost, ptfhost, creds): + def test_fastboot(self, duthosts, rand_one_dut_hostname, localhost, ptfhost, creds): + duthost = duthosts[rand_one_dut_hostname] duthost.command("sudo config save -y") # This will override config_db.json with mgmt vrf config reboot(duthost, localhost, reboot_type="fast") pytest_assert(wait_until(300, 20, duthost.critical_services_fully_started), "Not all critical services are fully started") diff --git a/tests/ntp/test_ntp.py b/tests/ntp/test_ntp.py index ab25c05bfda..60f4b7ea459 100644 --- a/tests/ntp/test_ntp.py +++ b/tests/ntp/test_ntp.py @@ -13,8 +13,9 @@ @pytest.fixture(scope="module") -def setup_ntp(ptfhost, duthost, creds): +def setup_ntp(ptfhost, duthosts, rand_one_dut_hostname, creds): """setup ntp client and server""" + duthost = duthosts[rand_one_dut_hostname] ptfhost.lineinfile(path="/etc/ntp.conf", line="server 127.127.1.0 prefer") @@ -49,8 +50,9 @@ def check_ntp_status(host): return True -def test_ntp(duthost, setup_ntp): +def test_ntp(duthosts, rand_one_dut_hostname, setup_ntp): """ Verify that DUT is synchronized with configured NTP server """ + duthost = duthosts[rand_one_dut_hostname] duthost.service(name='ntp', state='stopped') duthost.command("ntpd -gq") diff --git a/tests/pc/test_po_cleanup.py b/tests/pc/test_po_cleanup.py index 4b1f097c9c0..9ea7d8744d2 100644 --- a/tests/pc/test_po_cleanup.py +++ b/tests/pc/test_po_cleanup.py @@ -9,7 +9,7 @@ ] @pytest.fixture(autouse=True) -def ignore_expected_loganalyzer_exceptions(duthost, loganalyzer): +def ignore_expected_loganalyzer_exceptions(loganalyzer): """ Ignore expected failures logs during test execution. @@ -38,11 +38,12 @@ def check_kernel_po_interface_cleaned(duthost): return res == '0' -def test_po_cleanup(duthost): +def test_po_cleanup(duthosts, rand_one_dut_hostname): """ test port channel are cleaned up correctly and teammgrd and teamsyncd process handle SIGTERM gracefully """ + duthost = duthosts[rand_one_dut_hostname] mg_facts = duthost.minigraph_facts(host=duthost.hostname)['ansible_facts'] if len(mg_facts['minigraph_portchannels'].keys()) == 0: diff --git a/tests/pc/test_po_update.py b/tests/pc/test_po_update.py index aec94e92b86..a69a96d0d65 100644 --- a/tests/pc/test_po_update.py +++ b/tests/pc/test_po_update.py @@ -11,7 +11,7 @@ ] @pytest.fixture(autouse=True) -def ignore_expected_loganalyzer_exceptions(duthost, loganalyzer): +def ignore_expected_loganalyzer_exceptions(loganalyzer): """ Ignore expected failures logs during test execution. @@ -33,10 +33,11 @@ def ignore_expected_loganalyzer_exceptions(duthost, loganalyzer): yield -def test_po_update(duthost): +def test_po_update(duthosts, rand_one_dut_hostname): """ test port channel add/deletion as well ip address configuration """ + duthost = duthosts[rand_one_dut_hostname] mg_facts = duthost.minigraph_facts(host=duthost.hostname)['ansible_facts'] int_facts = duthost.interface_facts()['ansible_facts'] diff --git a/tests/pfc/files/qos_fixtures.py b/tests/pfc/files/qos_fixtures.py index dc32f25433f..784a1e83549 100644 --- a/tests/pfc/files/qos_fixtures.py +++ b/tests/pfc/files/qos_fixtures.py @@ -6,7 +6,7 @@ 1. lossless_prio_dscp_map """ @pytest.fixture(scope = "module") -def lossless_prio_dscp_map(duthost): +def lossless_prio_dscp_map(duthosts, rand_one_dut_hostname): """ This fixture reads the QOS parameters from SONiC DUT, and creates lossless priority Vs. DSCP priority port map (dictionary key = lossless @@ -19,6 +19,7 @@ def lossless_prio_dscp_map(duthost): Lossless priority vs. DSCP map (dictionary, key = lossless priority). Example: {3: [3], 4: [4]} """ + duthost = duthosts[rand_one_dut_hostname] config_facts = duthost.config_facts(host=duthost.hostname, source="persistent")['ansible_facts'] diff --git a/tests/pfc_asym/conftest.py b/tests/pfc_asym/conftest.py index 02bf858f5a3..51846d0d9da 100755 --- a/tests/pfc_asym/conftest.py +++ b/tests/pfc_asym/conftest.py @@ -7,6 +7,7 @@ @pytest.fixture(autouse=True) -def flush_neighbors(duthost): +def flush_neighbors(duthosts, rand_one_dut_hostname): """ Clear ARP table to make sure that neighbors learning will be triggered """ + duthost = duthosts[rand_one_dut_hostname] duthost.command("sonic-clear arp") diff --git a/tests/pfcwd/conftest.py b/tests/pfcwd/conftest.py index dfb1a60d15f..faf8241cdad 100644 --- a/tests/pfcwd/conftest.py +++ b/tests/pfcwd/conftest.py @@ -28,7 +28,7 @@ def pytest_addoption(parser): help='Fake storm for most ports instead of using pfc gen') @pytest.fixture(scope="module") -def setup_pfc_test(duthost, ptfhost, conn_graph_facts): +def setup_pfc_test(duthosts, rand_one_dut_hostname, ptfhost, conn_graph_facts): """ Sets up all the parameters needed for the PFC Watchdog tests @@ -40,6 +40,7 @@ def setup_pfc_test(duthost, ptfhost, conn_graph_facts): Yields: setup_info: dictionary containing pfc timers, generated test ports and selected test ports """ + duthost = duthosts[rand_one_dut_hostname] mg_facts = duthost.minigraph_facts(host=duthost.hostname)['ansible_facts'] port_list = mg_facts['minigraph_ports'].keys() ports = (' ').join(port_list) diff --git a/tests/pfcwd/test_pfc_config.py b/tests/pfcwd/test_pfc_config.py index e8fd6ff83f1..d33ef90dde1 100644 --- a/tests/pfcwd/test_pfc_config.py +++ b/tests/pfcwd/test_pfc_config.py @@ -88,7 +88,7 @@ def cfg_teardown(duthost): duthost.shell("rm -rf {}".format(DUT_RUN_DIR)) @pytest.fixture(scope='class', autouse=True) -def cfg_setup(setup_pfc_test, duthost): +def cfg_setup(setup_pfc_test, duthosts, rand_one_dut_hostname): """ Class level automatic fixture. Prior to the test run, create all the templates needed for each individual test and copy them on the DUT. @@ -98,6 +98,7 @@ def cfg_setup(setup_pfc_test, duthost): setup_pfc_test: module fixture defined in module conftest.py duthost: instance of AnsibleHost class """ + duthost = duthosts[rand_one_dut_hostname] setup_info = setup_pfc_test pfc_wd_test_port = setup_info['test_ports'].keys()[0] logger.info("Creating json templates for all config tests") @@ -113,7 +114,7 @@ def cfg_setup(setup_pfc_test, duthost): @pytest.fixture(scope='function', autouse=True) -def stop_pfcwd(duthost): +def stop_pfcwd(duthosts, rand_one_dut_hostname): """ Fixture that stops PFC Watchdog before each test run @@ -123,6 +124,7 @@ def stop_pfcwd(duthost): Returns: None """ + duthost = duthosts[rand_one_dut_hostname] logger.info("--- Stop Pfcwd --") duthost.command("pfcwd stop") @@ -163,7 +165,7 @@ def execute_test(self, duthost, syslog_marker, ignore_regex=None, expect_regex=N out = duthost.command(cmd) pytest_assert(out["rc"] == 0, "Failed to execute cmd {}: Error: {}".format(cmd, out["stderr"])) - def test_forward_action_cfg(self, duthost): + def test_forward_action_cfg(self, duthosts, rand_one_dut_hostname): """ Tests if the config gets loaded properly for a valid cfg template @@ -173,9 +175,10 @@ def test_forward_action_cfg(self, duthost): Returns: None """ + duthost = duthosts[rand_one_dut_hostname] self.execute_test(duthost, "pfc_wd_fwd_action", "config_test_ignore_messages") - def test_invalid_action_cfg(self, duthost): + def test_invalid_action_cfg(self, duthosts, rand_one_dut_hostname): """ Tests for syslog error when invalid action is configured @@ -185,9 +188,10 @@ def test_invalid_action_cfg(self, duthost): Returns: None """ + duthost = duthosts[rand_one_dut_hostname] self.execute_test(duthost, "pfc_wd_invalid_action", None, [CONFIG_TEST_EXPECT_INVALID_ACTION_RE], True) - def test_invalid_detect_time_cfg(self, duthost): + def test_invalid_detect_time_cfg(self, duthosts, rand_one_dut_hostname): """ Tests for syslog error when invalid detect time is configured @@ -197,9 +201,10 @@ def test_invalid_detect_time_cfg(self, duthost): Returns: None """ + duthost = duthosts[rand_one_dut_hostname] self.execute_test(duthost, "pfc_wd_invalid_detect_time", None, [CONFIG_TEST_EXPECT_INVALID_DETECT_TIME_RE], True) - def test_low_detect_time_cfg(self, duthost): + def test_low_detect_time_cfg(self, duthosts, rand_one_dut_hostname): """ Tests for syslog error when detect time < lower bound is configured @@ -209,9 +214,10 @@ def test_low_detect_time_cfg(self, duthost): Returns: None """ + duthost = duthosts[rand_one_dut_hostname] self.execute_test(duthost, "pfc_wd_low_detect_time", None, [CONFIG_TEST_EXPECT_INVALID_DETECT_TIME_RE], True) - def test_high_detect_time_cfg(self, duthost): + def test_high_detect_time_cfg(self, duthosts, rand_one_dut_hostname): """ Tests for syslog error when detect time > higher bound is configured @@ -221,9 +227,10 @@ def test_high_detect_time_cfg(self, duthost): Returns: None """ + duthost = duthosts[rand_one_dut_hostname] self.execute_test(duthost, "pfc_wd_high_detect_time", None, [CONFIG_TEST_EXPECT_INVALID_DETECT_TIME_RE], True) - def test_invalid_restore_time_cfg(self, duthost): + def test_invalid_restore_time_cfg(self, duthosts, rand_one_dut_hostname): """ Tests for syslog error when invalid restore time is configured @@ -233,9 +240,10 @@ def test_invalid_restore_time_cfg(self, duthost): Returns: None """ + duthost = duthosts[rand_one_dut_hostname] self.execute_test(duthost, "pfc_wd_invalid_restore_time", None, [CONFIG_TEST_EXPECT_INVALID_RESTORE_TIME_RE], True) - def test_low_restore_time_cfg(self, duthost): + def test_low_restore_time_cfg(self, duthosts, rand_one_dut_hostname): """ Tests for syslog error when restore time < lower bound is configured @@ -245,9 +253,10 @@ def test_low_restore_time_cfg(self, duthost): Returns: None """ + duthost = duthosts[rand_one_dut_hostname] self.execute_test(duthost, "pfc_wd_low_restore_time", None, [CONFIG_TEST_EXPECT_INVALID_RESTORE_TIME_RE], True) - def test_high_restore_time_cfg(self, duthost): + def test_high_restore_time_cfg(self, duthosts, rand_one_dut_hostname): """ Tests for syslog error when restore time > higher bound is configured @@ -257,4 +266,5 @@ def test_high_restore_time_cfg(self, duthost): Returns: None """ + duthost = duthosts[rand_one_dut_hostname] self.execute_test(duthost, "pfc_wd_high_restore_time", None, [CONFIG_TEST_EXPECT_INVALID_RESTORE_TIME_RE], True) diff --git a/tests/pfcwd/test_pfcwd_all_port_storm.py b/tests/pfcwd/test_pfcwd_all_port_storm.py index 3ca1d4276e8..794e191b614 100644 --- a/tests/pfcwd/test_pfcwd_all_port_storm.py +++ b/tests/pfcwd/test_pfcwd_all_port_storm.py @@ -19,18 +19,19 @@ logger = logging.getLogger(__name__) @pytest.fixture(scope='class', autouse=True) -def stop_pfcwd(duthost): +def stop_pfcwd(duthosts, rand_one_dut_hostname): """ Fixture that stops PFC Watchdog before each test run Args: duthost (AnsibleHost): DUT instance """ + duthost = duthosts[rand_one_dut_hostname] logger.info("--- Stop Pfcwd --") duthost.command("pfcwd stop") @pytest.fixture(scope='class', autouse=True) -def storm_test_setup_restore(setup_pfc_test, fanout_graph_facts, duthost, fanouthosts): +def storm_test_setup_restore(setup_pfc_test, fanout_graph_facts, duthosts, rand_one_dut_hostname, fanouthosts): """ Fixture that inits the test vars, start PFCwd on ports and cleans up after the test run @@ -43,6 +44,7 @@ def storm_test_setup_restore(setup_pfc_test, fanout_graph_facts, duthost, fanout Yields: storm_hndle (PFCStorm): class PFCStorm instance """ + duthost = duthosts[rand_one_dut_hostname] setup_info = setup_pfc_test neighbors = setup_info['neighbors'] port_list = setup_info['port_list'] @@ -137,7 +139,7 @@ def run_test(self, duthost, storm_hndle, expect_regex, syslog_marker, action): storm_hndle.stop_pfc_storm() time.sleep(5) - def test_all_port_storm_restore(self, duthost, storm_test_setup_restore): + def test_all_port_storm_restore(self, duthosts, rand_one_dut_hostname, storm_test_setup_restore): """ Tests PFC storm/restore on all ports @@ -145,6 +147,7 @@ def test_all_port_storm_restore(self, duthost, storm_test_setup_restore): duthost (AnsibleHost): DUT instance storm_test_setup_restore (fixture): class scoped autouse setup fixture """ + duthost = duthosts[rand_one_dut_hostname] storm_hndle = storm_test_setup_restore logger.info("--- Testing if PFC storm is detected on all ports ---") self.run_test(duthost, storm_hndle, expect_regex=[EXPECT_PFC_WD_DETECT_RE], syslog_marker="all_port_storm", diff --git a/tests/pfcwd/test_pfcwd_function.py b/tests/pfcwd/test_pfcwd_function.py index 6493e6ad310..7c5f6a0a80d 100644 --- a/tests/pfcwd/test_pfcwd_function.py +++ b/tests/pfcwd/test_pfcwd_function.py @@ -27,13 +27,14 @@ logger = logging.getLogger(__name__) @pytest.fixture(scope='function', autouse=True) -def stop_pfcwd(duthost): +def stop_pfcwd(duthosts, rand_one_dut_hostname): """ Fixture that stops PFC Watchdog before each test run Args: duthost(AnsibleHost) : dut instance """ + duthost = duthosts[rand_one_dut_hostname] logger.info("--- Stop Pfcwd --") duthost.command("pfcwd stop") @@ -498,7 +499,7 @@ def run_test(self, dut, port, action): logger.info("--- Verify PFCwd counters for port {} ---".format(port)) self.stats.verify_pkt_cnts(self.pfc_wd['port_type'], self.pfc_wd['test_pkt_count']) - def test_pfcwd_actions(self, request, setup_pfc_test, fanout_graph_facts, ptfhost, duthost, fanouthosts): + def test_pfcwd_actions(self, request, setup_pfc_test, fanout_graph_facts, ptfhost, duthosts, rand_one_dut_hostname, fanouthosts): """ PFCwd functional test @@ -510,6 +511,7 @@ def test_pfcwd_actions(self, request, setup_pfc_test, fanout_graph_facts, ptfhos duthost(AnsibleHost) : DUT instance fanouthosts(AnsibleHost): fanout instance """ + duthost = duthosts[rand_one_dut_hostname] setup_info = setup_pfc_test self.fanout_info = fanout_graph_facts self.ptf = ptfhost diff --git a/tests/pfcwd/test_pfcwd_timer_accuracy.py b/tests/pfcwd/test_pfcwd_timer_accuracy.py index afc20c30ec8..ffb398676ba 100644 --- a/tests/pfcwd/test_pfcwd_timer_accuracy.py +++ b/tests/pfcwd/test_pfcwd_timer_accuracy.py @@ -14,18 +14,19 @@ logger = logging.getLogger(__name__) @pytest.fixture(scope='module', autouse=True) -def stop_pfcwd(duthost): +def stop_pfcwd(duthosts, rand_one_dut_hostname): """ Fixture that stops PFC Watchdog before each test run Args: duthost (AnsibleHost): DUT instance """ + duthost = duthosts[rand_one_dut_hostname] logger.info("--- Stop Pfcwd --") duthost.command("pfcwd stop") @pytest.fixture(autouse=True) -def ignore_loganalyzer_exceptions(duthost, loganalyzer): +def ignore_loganalyzer_exceptions(rand_one_dut_hostname, loganalyzer): """ Fixture that ignores expected failures during test execution. @@ -43,7 +44,7 @@ def ignore_loganalyzer_exceptions(duthost, loganalyzer): yield @pytest.fixture(scope='class', autouse=True) -def pfcwd_timer_setup_restore(setup_pfc_test, fanout_graph_facts, duthost, fanouthosts): +def pfcwd_timer_setup_restore(setup_pfc_test, fanout_graph_facts, duthosts, rand_one_dut_hostname, fanouthosts): """ Fixture that inits the test vars, start PFCwd on ports and cleans up after the test run @@ -57,6 +58,7 @@ def pfcwd_timer_setup_restore(setup_pfc_test, fanout_graph_facts, duthost, fanou timers (dict): pfcwd timer values storm_handle (PFCStorm): class PFCStorm instance """ + duthost = duthosts[rand_one_dut_hostname] logger.info("--- Pfcwd timer test setup ---") setup_info = setup_pfc_test test_ports = setup_info['test_ports'] @@ -202,7 +204,7 @@ def retrieve_timestamp(self, pattern): timestamp_ms = self.dut.shell("date -d {} +%s%3N".format(timestamp))['stdout'] return int(timestamp_ms) - def test_pfcwd_timer_accuracy(self, duthost, pfcwd_timer_setup_restore): + def test_pfcwd_timer_accuracy(self, duthosts, rand_one_dut_hostname, pfcwd_timer_setup_restore): """ Tests PFCwd timer accuracy @@ -210,6 +212,7 @@ def test_pfcwd_timer_accuracy(self, duthost, pfcwd_timer_setup_restore): duthost (AnsibleHost): DUT instance pfcwd_timer_setup_restore (fixture): class scoped autouse setup fixture """ + duthost = duthosts[rand_one_dut_hostname] setup_info = pfcwd_timer_setup_restore self.storm_handle = setup_info['storm_handle'] self.timers = setup_info['timers'] diff --git a/tests/pfcwd/test_pfcwd_warm_reboot.py b/tests/pfcwd/test_pfcwd_warm_reboot.py index 38411d1f193..6277d7f482a 100644 --- a/tests/pfcwd/test_pfcwd_warm_reboot.py +++ b/tests/pfcwd/test_pfcwd_warm_reboot.py @@ -38,13 +38,14 @@ logger = logging.getLogger(__name__) @pytest.fixture(autouse=True) -def setup_pfcwd(duthost): +def setup_pfcwd(duthosts, rand_one_dut_hostname): """ Setup PFCwd before the test run Args: duthost(AnsibleHost) : dut instance """ + duthost = duthosts[rand_one_dut_hostname] logger.info("Setup the default pfcwd config for warm-reboot test") duthost.command("redis-cli -n 4 hset \"DEVICE_METADATA|localhost\" " "default_pfcwd_status enable") @@ -518,7 +519,7 @@ def testcase_action(self, request): """ yield request.param - def test_pfcwd_wb(self, request, testcase_action, setup_pfc_test, fanout_graph_facts, ptfhost, duthost, localhost, fanouthosts): + def test_pfcwd_wb(self, request, testcase_action, setup_pfc_test, fanout_graph_facts, ptfhost, duthosts, rand_one_dut_hostname, localhost, fanouthosts): """ Tests PFCwd warm reboot with various testcase actions @@ -540,6 +541,7 @@ def test_pfcwd_wb(self, request, testcase_action, setup_pfc_test, fanout_graph_f localhost(AnsibleHost) : localhost instance fanouthosts(AnsibleHost): fanout instance """ + duthost = duthosts[rand_one_dut_hostname] logger.info("--- {} ---".format(TESTCASE_INFO[testcase_action]['desc'])) self.pfcwd_wb_helper(request, TESTCASE_INFO[testcase_action]['test_sequence'], setup_pfc_test, fanout_graph_facts, ptfhost, duthost, localhost, fanouthosts) diff --git a/tests/platform_tests/broadcom/test_ser.py b/tests/platform_tests/broadcom/test_ser.py index c4f75c07281..9a3c9b4978f 100644 --- a/tests/platform_tests/broadcom/test_ser.py +++ b/tests/platform_tests/broadcom/test_ser.py @@ -48,7 +48,8 @@ def enable_ssh_timout(dut): @pytest.fixture(scope="module", autouse=True) -def test_setup_teardown(duthost, localhost): +def test_setup_teardown(duthosts, rand_one_dut_hostname, localhost): + duthost = duthosts[rand_one_dut_hostname] disable_ssh_timout(duthost) # There must be a better way to do this. # Reboot the DUT so that we guaranteed to login without ssh timeout. @@ -66,7 +67,7 @@ def test_setup_teardown(duthost, localhost): @pytest.mark.disable_loganalyzer @pytest.mark.broadcom -def test_ser(duthost): +def test_ser(duthosts, rand_one_dut_hostname): ''' @summary: Broadcom SER injection test use Broadcom SER injection utility to insert SER into different memory tables. Before the SER injection, Broadcom mem/sram scanners @@ -76,6 +77,7 @@ def test_ser(duthost): --host-pattern=vms12-t0-s6000-1 --module-path=../ansible/library @param duthost: Ansible framework testbed DUT device ''' + duthost = duthosts[rand_one_dut_hostname] asic_type = duthost.facts["asic_type"] if "broadcom" not in asic_type: pytest.skip('Skipping SER test for asic_type: %s' % asic_type) diff --git a/tests/platform_tests/cli/test_show_platform.py b/tests/platform_tests/cli/test_show_platform.py index 2728b18ecbb..19775ef240e 100644 --- a/tests/platform_tests/cli/test_show_platform.py +++ b/tests/platform_tests/cli/test_show_platform.py @@ -30,10 +30,11 @@ THERMAL_CONTROL_TEST_CHECK_INTERVAL = 5 -def test_show_platform_summary(duthost): +def test_show_platform_summary(duthosts, rand_one_dut_hostname): """ @summary: Verify output of `show platform summary` """ + duthost = duthosts[rand_one_dut_hostname] cmd = " ".join([CMD_SHOW_PLATFORM, "summary"]) logging.info("Verifying output of '{}' ...".format(cmd)) @@ -53,10 +54,11 @@ def test_show_platform_summary(duthost): pytest_assert(summary_dict[key], "Missing value for '{}'".format(key)) -def test_show_platform_syseeprom(duthost): +def test_show_platform_syseeprom(duthosts, rand_one_dut_hostname): """ @summary: Verify output of `show platform syseeprom` """ + duthost = duthosts[rand_one_dut_hostname] cmd = " ".join([CMD_SHOW_PLATFORM, "syseeprom"]) logging.info("Verifying output of '{}' ...".format(cmd)) @@ -91,10 +93,11 @@ def test_show_platform_syseeprom(duthost): pytest_assert(line in syseeprom_output, "Line '{}' was not found in output".format(line)) -def test_show_platform_psustatus(duthost): +def test_show_platform_psustatus(duthosts, rand_one_dut_hostname): """ @summary: Verify output of `show platform psustatus` """ + duthost = duthosts[rand_one_dut_hostname] cmd = " ".join([CMD_SHOW_PLATFORM, "psustatus"]) logging.info("Verifying output of '{}' ...".format(cmd)) @@ -122,10 +125,11 @@ def verify_show_platform_fan_output(raw_output_lines): pytest_assert(len(field_ranges) == NUM_EXPECTED_COLS, "Output should consist of {} columns".format(NUM_EXPECTED_COLS)) -def test_show_platform_fan(duthost): +def test_show_platform_fan(duthosts, rand_one_dut_hostname): """ @summary: Verify output of `show platform fan` """ + duthost = duthosts[rand_one_dut_hostname] cmd = " ".join([CMD_SHOW_PLATFORM, "fan"]) logging.info("Verifying output of '{}' ...".format(cmd)) @@ -152,10 +156,11 @@ def verify_show_platform_temperature_output(raw_output_lines): pytest_assert(len(field_ranges) == NUM_EXPECTED_COLS, "Output should consist of {} columns".format(NUM_EXPECTED_COLS)) -def test_show_platform_temperature(duthost): +def test_show_platform_temperature(duthosts, rand_one_dut_hostname): """ @summary: Verify output of `show platform temperature` """ + duthost = duthosts[rand_one_dut_hostname] cmd = " ".join([CMD_SHOW_PLATFORM, "temperature"]) logging.info("Verifying output of '{}' ...".format(cmd)) @@ -165,10 +170,11 @@ def test_show_platform_temperature(duthost): # TODO: Test values against platform-specific expected data -def test_show_platform_ssdhealth(duthost): +def test_show_platform_ssdhealth(duthosts, rand_one_dut_hostname): """ @summary: Verify output of `show platform ssdhealth` """ + duthost = duthosts[rand_one_dut_hostname] cmd = " ".join([CMD_SHOW_PLATFORM, "ssdhealth"]) logging.info("Verifying output of '{}' ...".format(cmd)) @@ -201,10 +207,11 @@ def verify_show_platform_firmware_status_output(raw_output_lines): pytest_assert(len(field_ranges) == NUM_EXPECTED_COLS, "Output should consist of {} columns".format(NUM_EXPECTED_COLS)) -def test_show_platform_firmware_status(duthost): +def test_show_platform_firmware_status(duthosts, rand_one_dut_hostname): """ @summary: Verify output of `show platform firmware status` """ + duthost = duthosts[rand_one_dut_hostname] cmd = " ".join([CMD_SHOW_PLATFORM, "firmware", "status"]) logging.info("Verifying output of '{}' ...".format(cmd)) diff --git a/tests/platform_tests/conftest.py b/tests/platform_tests/conftest.py index e8b4b88e209..b9903086cba 100644 --- a/tests/platform_tests/conftest.py +++ b/tests/platform_tests/conftest.py @@ -7,14 +7,15 @@ @pytest.fixture(autouse=True, scope="module") -def skip_on_simx(duthost): +def skip_on_simx(duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] platform = duthost.facts["platform"] if "simx" in platform: pytest.skip('skipped on this platform: {}'.format(platform)) @pytest.fixture() -def bring_up_dut_interfaces(request, duthost): +def bring_up_dut_interfaces(request, duthosts, rand_one_dut_hostname): """ Bring up outer interfaces on the DUT. @@ -22,6 +23,7 @@ def bring_up_dut_interfaces(request, duthost): request: pytest request object duthost: Fixture for interacting with the DUT. """ + duthost = duthosts[rand_one_dut_hostname] yield if request.node.rep_call.failed: mg_facts = duthost.minigraph_facts(host=duthost.hostname)['ansible_facts'] 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 d441b149745..6804165c398 100644 --- a/tests/platform_tests/link_flap/test_cont_link_flap.py +++ b/tests/platform_tests/link_flap/test_cont_link_flap.py @@ -26,7 +26,7 @@ class TestContLinkFlap(object): TestContLinkFlap class for continuous link flap """ - def test_cont_link_flap(self, request, duthost, fanouthosts, bring_up_dut_interfaces): + def test_cont_link_flap(self, request, duthosts, rand_one_dut_hostname, fanouthosts, bring_up_dut_interfaces): """ Validates that continuous link flap works as expected @@ -41,6 +41,7 @@ def test_cont_link_flap(self, request, duthost, fanouthosts, bring_up_dut_interf Pass Criteria: All routes must be re-learned with < 5% increase in Redis and ORCH agent CPU consumption below threshold after 3 mins after stopping flaps. """ + duthost = duthosts[rand_one_dut_hostname] orch_cpu_threshold = request.config.getoption("--orch_cpu_threshold") # Record memory status at start diff --git a/tests/platform_tests/mellanox/test_check_sfp_presence.py b/tests/platform_tests/mellanox/test_check_sfp_presence.py index 622ed6fef33..2ed37e17896 100644 --- a/tests/platform_tests/mellanox/test_check_sfp_presence.py +++ b/tests/platform_tests/mellanox/test_check_sfp_presence.py @@ -13,9 +13,10 @@ pytest.mark.topology('any') ] -def test_check_sfp_presence(duthost, conn_graph_facts): +def test_check_sfp_presence(duthosts, rand_one_dut_hostname, conn_graph_facts): """This test case is to check SFP presence status with CLI and sysfs. """ + duthost = duthosts[rand_one_dut_hostname] ports_config = json.loads(duthost.command("sudo sonic-cfggen -d --var-json PORT")["stdout"]) check_intf_presence_command = 'show interface transceiver presence {}' diff --git a/tests/platform_tests/mellanox/test_check_sfp_using_ethtool.py b/tests/platform_tests/mellanox/test_check_sfp_using_ethtool.py index 1229b516eba..d8cf4029cc8 100644 --- a/tests/platform_tests/mellanox/test_check_sfp_using_ethtool.py +++ b/tests/platform_tests/mellanox/test_check_sfp_using_ethtool.py @@ -17,9 +17,10 @@ pytest.mark.topology('any') ] -def test_check_sfp_using_ethtool(duthost, conn_graph_facts): +def test_check_sfp_using_ethtool(duthosts, rand_one_dut_hostname, conn_graph_facts): """This test case is to check SFP using the ethtool. """ + duthost = duthosts[rand_one_dut_hostname] ports_config = json.loads(duthost.command("sudo sonic-cfggen -d --var-json PORT")["stdout"]) logging.info("Use the ethtool to check SFP information") diff --git a/tests/platform_tests/mellanox/test_check_sysfs.py b/tests/platform_tests/mellanox/test_check_sysfs.py index a7ca62e0ebf..cde45c430e7 100644 --- a/tests/platform_tests/mellanox/test_check_sysfs.py +++ b/tests/platform_tests/mellanox/test_check_sysfs.py @@ -13,15 +13,17 @@ pytest.mark.topology('any') ] -def test_check_hw_mgmt_sysfs(duthost): +def test_check_hw_mgmt_sysfs(duthosts, rand_one_dut_hostname): """This test case is to check the symbolic links under /var/run/hw-management """ + duthost = duthosts[rand_one_dut_hostname] check_sysfs(duthost) -def test_hw_mgmt_sysfs_mapped_to_pmon(duthost): +def test_hw_mgmt_sysfs_mapped_to_pmon(duthosts, rand_one_dut_hostname): """This test case is to verify that the /var/run/hw-management folder is mapped to pmon container """ + duthost = duthosts[rand_one_dut_hostname] logging.info("Verify that the /var/run/hw-management folder is mapped to the pmon container") files_under_dut = set(duthost.command("find /var/run/hw-management")["stdout_lines"]) files_under_pmon = set(duthost.command("docker exec pmon find /var/run/hw-management")["stdout_lines"]) diff --git a/tests/platform_tests/mellanox/test_hw_management_service.py b/tests/platform_tests/mellanox/test_hw_management_service.py index edb95c1de9b..d973997a328 100644 --- a/tests/platform_tests/mellanox/test_hw_management_service.py +++ b/tests/platform_tests/mellanox/test_hw_management_service.py @@ -12,7 +12,8 @@ pytest.mark.topology('any') ] -def test_hw_management_service_status(duthost): +def test_hw_management_service_status(duthosts, rand_one_dut_hostname): """This test case is to verify that the hw-management service is running properly """ + duthost = duthosts[rand_one_dut_hostname] check_hw_management_service(duthost) diff --git a/tests/platform_tests/mellanox/test_thermal_control.py b/tests/platform_tests/mellanox/test_thermal_control.py index 7db7eb376ae..bcc8f8c0645 100644 --- a/tests/platform_tests/mellanox/test_thermal_control.py +++ b/tests/platform_tests/mellanox/test_thermal_control.py @@ -28,7 +28,8 @@ @pytest.mark.disable_loganalyzer -def test_dynamic_minimum_table(duthost, mocker_factory): +def test_dynamic_minimum_table(duthosts, rand_one_dut_hostname, mocker_factory): + duthost = duthosts[rand_one_dut_hostname] air_flow_dirs = ['p2c', 'c2p', 'unk'] max_temperature = 45000 # 45 C cooling_cur_state = get_cooling_cur_state(duthost) @@ -62,7 +63,8 @@ def test_dynamic_minimum_table(duthost, mocker_factory): @pytest.mark.disable_loganalyzer -def test_set_psu_fan_speed(duthost, mocker_factory): +def test_set_psu_fan_speed(duthosts, rand_one_dut_hostname, mocker_factory): + duthost = duthosts[rand_one_dut_hostname] platform_data = get_platform_data(duthost) psu_num = platform_data['psus']['number'] hot_swappable = platform_data['psus']['hot_swappable'] diff --git a/tests/platform_tests/test_cont_warm_reboot.py b/tests/platform_tests/test_cont_warm_reboot.py index d867f29dcae..e79350be453 100644 --- a/tests/platform_tests/test_cont_warm_reboot.py +++ b/tests/platform_tests/test_cont_warm_reboot.py @@ -429,7 +429,7 @@ def test_teardown(self): format(self.test_failures, self.reboot_count)) -def test_continuous_reboot(request, duthost, ptfhost, localhost, conn_graph_facts, tbinfo, creds): +def test_continuous_reboot(request, duthosts, rand_one_dut_hostname, ptfhost, localhost, conn_graph_facts, tbinfo, creds): """ @summary: This test performs continuous reboot cycles on images that are provided as an input. Supported parameters for this test can be modified at runtime: @@ -450,6 +450,7 @@ def test_continuous_reboot(request, duthost, ptfhost, localhost, conn_graph_fact Status of transceivers - ports in lab_connection_graph should be present Status of BGP neighbors - should be established """ + duthost = duthosts[rand_one_dut_hostname] continuous_reboot = ContinuousReboot(request, duthost, ptfhost, localhost, conn_graph_facts) continuous_reboot.start_continuous_reboot(request, duthost, ptfhost, localhost, tbinfo, creds) continuous_reboot.test_teardown() diff --git a/tests/platform_tests/test_cpu_memory_usage.py b/tests/platform_tests/test_cpu_memory_usage.py index 8212d004224..cb17e3fac0c 100644 --- a/tests/platform_tests/test_cpu_memory_usage.py +++ b/tests/platform_tests/test_cpu_memory_usage.py @@ -11,7 +11,8 @@ @pytest.fixture(scope='module') -def setup_thresholds(duthost): +def setup_thresholds(duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] cpu_threshold = 50 memory_threshold = 60 if duthost.facts['platform'] in ('x86_64-arista_7050_qx32', 'x86_64-kvm_x86_64-r0'): @@ -19,8 +20,9 @@ def setup_thresholds(duthost): return memory_threshold, cpu_threshold -def test_cpu_memory_usage(duthost, setup_thresholds): +def test_cpu_memory_usage(duthosts, rand_one_dut_hostname, setup_thresholds): """Check DUT memory usage and process cpu usage are within threshold.""" + duthost = duthosts[rand_one_dut_hostname] MonitResult = namedtuple('MonitResult', ['processes', 'memory']) monit_results = duthost.monit_process(iterations=12)['monit_results'] diff --git a/tests/platform_tests/test_platform_info.py b/tests/platform_tests/test_platform_info.py index 9ff1e14ca8b..b8740e1a4ce 100644 --- a/tests/platform_tests/test_platform_info.py +++ b/tests/platform_tests/test_platform_info.py @@ -77,12 +77,13 @@ def stop_pmon_sensord_task(ans_host): @pytest.fixture(scope="module") -def psu_test_setup_teardown(duthost): +def psu_test_setup_teardown(duthosts, rand_one_dut_hostname): """ @summary: Sensord task will print out error msg when detect PSU offline, which can cause log analyzer fail the test. So stop sensord task before test and restart it after all test finished. """ + duthost = duthosts[rand_one_dut_hostname] logging.info("Starting psu test setup") stop_pmon_sensord_task(duthost) @@ -156,10 +157,11 @@ def check_all_psu_on(dut, psu_test_results): @pytest.mark.disable_loganalyzer -def test_turn_on_off_psu_and_check_psustatus(duthost, psu_controller): +def test_turn_on_off_psu_and_check_psustatus(duthosts, rand_one_dut_hostname, psu_controller): """ @summary: Turn off/on PSU and check PSU status using 'show platform psustatus' """ + duthost = duthosts[rand_one_dut_hostname] loganalyzer = LogAnalyzer(ansible_host=duthost, marker_prefix='turn_on_off_psu_and_check_psustatus') loganalyzer.load_common_config() @@ -226,10 +228,11 @@ def test_turn_on_off_psu_and_check_psustatus(duthost, psu_controller): loganalyzer.analyze(marker) -def test_show_platform_fanstatus_mocked(duthost, mocker_factory): +def test_show_platform_fanstatus_mocked(duthosts, rand_one_dut_hostname, mocker_factory): """ @summary: Check output of 'show platform fan'. """ + duthost = duthosts[rand_one_dut_hostname] # Mock data and check mocker = mocker_factory(duthost, 'FanStatusMocker') if mocker is None: @@ -243,10 +246,11 @@ def test_show_platform_fanstatus_mocked(duthost, mocker_factory): assert result, 'FAN mock data mismatch' -def test_show_platform_temperature_mocked(duthost, mocker_factory): +def test_show_platform_temperature_mocked(duthosts, rand_one_dut_hostname, mocker_factory): """ @summary: Check output of 'show platform temperature' """ + duthost = duthosts[rand_one_dut_hostname] # Mock data and check mocker = mocker_factory(duthost, 'ThermalStatusMocker') if mocker is None: @@ -261,21 +265,23 @@ def test_show_platform_temperature_mocked(duthost, mocker_factory): @pytest.mark.disable_loganalyzer -def test_thermal_control_load_invalid_format_json(duthost): +def test_thermal_control_load_invalid_format_json(duthosts, rand_one_dut_hostname): """ @summary: Load a thermal policy file with invalid format, check thermal control daemon is up and there is an error log printed """ + duthost = duthosts[rand_one_dut_hostname] logging.info('Loading invalid format policy file...') check_thermal_control_load_invalid_file(duthost, THERMAL_POLICY_INVALID_FORMAT_FILE) @pytest.mark.disable_loganalyzer -def test_thermal_control_load_invalid_value_json(duthost): +def test_thermal_control_load_invalid_value_json(duthosts, rand_one_dut_hostname): """ @summary: Load a thermal policy file with invalid value, check thermal control daemon is up and there is an error log printed """ + duthost = duthosts[rand_one_dut_hostname] logging.info('Loading invalid value policy file...') check_thermal_control_load_invalid_file(duthost, THERMAL_POLICY_INVALID_VALUE_FILE) @@ -292,10 +298,11 @@ def check_thermal_control_load_invalid_file(duthost, file_name): restart_thermal_control_daemon(duthost) -def test_thermal_control_psu_absence(duthost, psu_controller, mocker_factory): +def test_thermal_control_psu_absence(duthosts, rand_one_dut_hostname, psu_controller, mocker_factory): """ @summary: Turn off/on PSUs, check thermal control is working as expect. """ + duthost = duthosts[rand_one_dut_hostname] psu_num = get_psu_num(duthost) if psu_num < 2: pytest.skip("At least 2 PSUs required for rest of the testing in this case") @@ -381,10 +388,11 @@ def turn_off_psu_and_check_thermal_control(dut, psu_ctrl, psu, mocker): @pytest.mark.disable_loganalyzer -def test_thermal_control_fan_status(duthost, mocker_factory): +def test_thermal_control_fan_status(duthosts, rand_one_dut_hostname, mocker_factory): """ @summary: Make FAN absence, over speed and under speed, check logs and LED color. """ + duthost = duthosts[rand_one_dut_hostname] loganalyzer = LogAnalyzer(ansible_host=duthost, marker_prefix='thermal_control') loganalyzer.load_common_config() diff --git a/tests/platform_tests/test_port_toggle.py b/tests/platform_tests/test_port_toggle.py index d8683de1878..250efc081e1 100644 --- a/tests/platform_tests/test_port_toggle.py +++ b/tests/platform_tests/test_port_toggle.py @@ -17,7 +17,7 @@ class TestPortToggle(object): TestPortToggle class for testing port toggle """ - def test_port_toggle(self, duthost, bring_up_dut_interfaces): + def test_port_toggle(self, duthosts, rand_one_dut_hostname, bring_up_dut_interfaces): """ Validates that port toggle works as expected @@ -27,4 +27,5 @@ def test_port_toggle(self, duthost, bring_up_dut_interfaces): Pass Criteria: All interfaces are up correctly. """ + duthost = duthosts[rand_one_dut_hostname] port_toggle(duthost) diff --git a/tests/platform_tests/test_reboot.py b/tests/platform_tests/test_reboot.py index 0ab92da06ba..c314f55004c 100644 --- a/tests/platform_tests/test_reboot.py +++ b/tests/platform_tests/test_reboot.py @@ -34,7 +34,8 @@ @pytest.fixture(scope="module", autouse=True) -def teardown_module(duthost, conn_graph_facts): +def teardown_module(duthosts, rand_one_dut_hostname, conn_graph_facts): + duthost = duthosts[rand_one_dut_hostname] yield logging.info("Tearing down: to make sure all the critical services, interfaces and transceivers are good") @@ -101,24 +102,27 @@ def check_interfaces_and_services(dut, interfaces, reboot_type = None): check_sysfs(dut) -def test_cold_reboot(duthost, localhost, conn_graph_facts): +def test_cold_reboot(duthosts, rand_one_dut_hostname, localhost, conn_graph_facts): """ @summary: This test case is to perform cold reboot and check platform status """ + duthost = duthosts[rand_one_dut_hostname] reboot_and_check(localhost, duthost, conn_graph_facts["device_conn"][duthost.hostname], reboot_type=REBOOT_TYPE_COLD) -def test_fast_reboot(duthost, localhost, conn_graph_facts): +def test_fast_reboot(duthosts, rand_one_dut_hostname, localhost, conn_graph_facts): """ @summary: This test case is to perform cold reboot and check platform status """ + duthost = duthosts[rand_one_dut_hostname] reboot_and_check(localhost, duthost, conn_graph_facts["device_conn"][duthost.hostname], reboot_type=REBOOT_TYPE_FAST) -def test_warm_reboot(duthost, localhost, conn_graph_facts): +def test_warm_reboot(duthosts, rand_one_dut_hostname, localhost, conn_graph_facts): """ @summary: This test case is to perform cold reboot and check platform status """ + duthost = duthosts[rand_one_dut_hostname] asic_type = duthost.facts["asic_type"] if asic_type in ["mellanox"]: @@ -149,7 +153,7 @@ def _power_off_reboot_helper(kwargs): psu_ctrl.turn_on_psu(psu["psu_id"]) -def test_power_off_reboot(duthost, localhost, conn_graph_facts, psu_controller, power_off_delay): +def test_power_off_reboot(duthosts, rand_one_dut_hostname, localhost, conn_graph_facts, psu_controller, power_off_delay): """ @summary: This test case is to perform reboot via powercycle and check platform status @param duthost: Fixture for DUT AnsibleHost object @@ -158,6 +162,7 @@ def test_power_off_reboot(duthost, localhost, conn_graph_facts, psu_controller, @param psu_controller: The python object of psu controller @param power_off_delay: Pytest parameter. The delay between turning off and on the PSU """ + duthost = duthosts[rand_one_dut_hostname] psu_ctrl = psu_controller if psu_ctrl is None: pytest.skip("No PSU controller for %s, skip rest of the testing in this case" % duthost.hostname) @@ -187,10 +192,11 @@ def test_power_off_reboot(duthost, localhost, conn_graph_facts, psu_controller, _power_off_reboot_helper, poweroff_reboot_kwargs) -def test_watchdog_reboot(duthost, localhost, conn_graph_facts): +def test_watchdog_reboot(duthosts, rand_one_dut_hostname, localhost, conn_graph_facts): """ @summary: This test case is to perform reboot via watchdog and check platform status """ + duthost = duthosts[rand_one_dut_hostname] test_watchdog_supported = "python -c \"import sonic_platform.platform as P; P.Platform().get_chassis().get_watchdog(); exit()\"" watchdog_supported = duthost.command(test_watchdog_supported,module_ignore_errors=True)["stderr"] @@ -200,9 +206,10 @@ def test_watchdog_reboot(duthost, localhost, conn_graph_facts): reboot_and_check(localhost, duthost, conn_graph_facts["device_conn"][duthost.hostname], REBOOT_TYPE_WATCHDOG) -def test_continuous_reboot(duthost, localhost, conn_graph_facts): +def test_continuous_reboot(duthosts, rand_one_dut_hostname, localhost, conn_graph_facts): """ @summary: This test case is to perform 3 cold reboot in a row """ + duthost = duthosts[rand_one_dut_hostname] for i in range(3): reboot_and_check(localhost, duthost, conn_graph_facts["device_conn"][duthost.hostname], reboot_type=REBOOT_TYPE_COLD) diff --git a/tests/platform_tests/test_reload_config.py b/tests/platform_tests/test_reload_config.py index ceb22e0046a..36b625a8169 100644 --- a/tests/platform_tests/test_reload_config.py +++ b/tests/platform_tests/test_reload_config.py @@ -20,10 +20,11 @@ ] -def test_reload_configuration(duthost, conn_graph_facts): +def test_reload_configuration(duthosts, rand_one_dut_hostname, conn_graph_facts): """ @summary: This test case is to reload the configuration and check platform status """ + duthost = duthosts[rand_one_dut_hostname] interfaces = conn_graph_facts["device_conn"][duthost.hostname] asic_type = duthost.facts["asic_type"] diff --git a/tests/platform_tests/test_sensors.py b/tests/platform_tests/test_sensors.py index 2cd3acef43c..1b1befbea98 100644 --- a/tests/platform_tests/test_sensors.py +++ b/tests/platform_tests/test_sensors.py @@ -11,7 +11,8 @@ def to_json(obj): return json.dumps(obj, indent=4) -def test_sensors(duthost, creds): +def test_sensors(duthosts, rand_one_dut_hostname, creds): + duthost = duthosts[rand_one_dut_hostname] # Get platform name platform = duthost.facts['platform'] diff --git a/tests/platform_tests/test_sequential_restart.py b/tests/platform_tests/test_sequential_restart.py index 86f7a698f16..353a482dcdc 100644 --- a/tests/platform_tests/test_sequential_restart.py +++ b/tests/platform_tests/test_sequential_restart.py @@ -25,7 +25,8 @@ @pytest.fixture(autouse=True, scope="function") -def heal_testbed(duthost): +def heal_testbed(duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] # Nothing to do before test yield status, details = get_critical_processes_status(duthost) @@ -66,16 +67,18 @@ def restart_service_and_check(localhost, dut, service, interfaces): check_critical_processes(dut, 60) -def test_restart_swss(duthost, localhost, conn_graph_facts): +def test_restart_swss(duthosts, rand_one_dut_hostname, localhost, conn_graph_facts): """ @summary: This test case is to restart the swss service and check platform status """ + duthost = duthosts[rand_one_dut_hostname] restart_service_and_check(localhost, duthost, "swss", conn_graph_facts["device_conn"][duthost.hostname]) @pytest.mark.skip(reason="Restarting syncd is not supported yet") -def test_restart_syncd(duthost, localhost, conn_graph_facts): +def test_restart_syncd(duthosts, rand_one_dut_hostname, localhost, conn_graph_facts): """ @summary: This test case is to restart the syncd service and check platform status """ + duthost = duthosts[rand_one_dut_hostname] restart_service_and_check(localhost, duthost, "syncd", conn_graph_facts["device_conn"][duthost.hostname]) diff --git a/tests/platform_tests/test_sfp.py b/tests/platform_tests/test_sfp.py index 63eda719ec0..9ad13df79d0 100644 --- a/tests/platform_tests/test_sfp.py +++ b/tests/platform_tests/test_sfp.py @@ -90,7 +90,7 @@ def get_port_map(duthost): return port_mapping -def test_check_sfp_status_and_configure_sfp(duthost, conn_graph_facts): +def test_check_sfp_status_and_configure_sfp(duthosts, rand_one_dut_hostname, conn_graph_facts): """ @summary: Check SFP status and configure SFP @@ -102,6 +102,7 @@ def test_check_sfp_status_and_configure_sfp(duthost, conn_graph_facts): * show interface transceiver eeprom * sfputil reset """ + duthost = duthosts[rand_one_dut_hostname] if duthost.facts["asic_type"] in ["mellanox"]: loganalyzer = LogAnalyzer(ansible_host=duthost, marker_prefix='sfp_cfg') loganalyzer.load_common_config() @@ -179,7 +180,7 @@ def test_check_sfp_status_and_configure_sfp(duthost, conn_graph_facts): loganalyzer.analyze(marker) -def test_check_sfp_low_power_mode(duthost, conn_graph_facts): +def test_check_sfp_low_power_mode(duthosts, rand_one_dut_hostname, conn_graph_facts): """ @summary: Check SFP low power mode @@ -188,6 +189,7 @@ def test_check_sfp_low_power_mode(duthost, conn_graph_facts): * sfputil lpmode off * sfputil lpmode on """ + duthost = duthosts[rand_one_dut_hostname] if duthost.facts["asic_type"] in ["mellanox"]: loganalyzer = LogAnalyzer(ansible_host=duthost, marker_prefix='sfp_lpm') loganalyzer.load_common_config() diff --git a/tests/platform_tests/test_xcvr_info_in_db.py b/tests/platform_tests/test_xcvr_info_in_db.py index a61e0572a8e..6887b5a6048 100644 --- a/tests/platform_tests/test_xcvr_info_in_db.py +++ b/tests/platform_tests/test_xcvr_info_in_db.py @@ -15,9 +15,10 @@ pytest.mark.topology('any') ] -def test_xcvr_info_in_db(duthost, conn_graph_facts): +def test_xcvr_info_in_db(duthosts, rand_one_dut_hostname, conn_graph_facts): """ @summary: This test case is to verify that xcvrd works as expected by checking transceiver information in DB """ + duthost = duthosts[rand_one_dut_hostname] logging.info("Check transceiver status") check_transceiver_status(duthost, conn_graph_facts["device_conn"][duthost.hostname]) diff --git a/tests/portstat/test_portstat.py b/tests/portstat/test_portstat.py index 3750cfd7d64..4233cd3930b 100644 --- a/tests/portstat/test_portstat.py +++ b/tests/portstat/test_portstat.py @@ -86,7 +86,8 @@ def parse_portstat(content_lines): @pytest.fixture(scope='function', autouse=True) -def reset_portstat(duthost): +def reset_portstat(duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] logger.info('Clear out all tags') duthost.command('portstat -D', become=True, module_ignore_errors=True) @@ -97,7 +98,8 @@ def reset_portstat(duthost): @pytest.mark.parametrize('command', ['portstat -c', 'portstat --clear']) -def test_portstat_clear(duthost, command): +def test_portstat_clear(duthosts, rand_one_dut_hostname, command): + duthost = duthosts[rand_one_dut_hostname] wait(30, 'Wait for DUT to receive/send some packets') before_portstat = parse_portstat(duthost.command('portstat')['stdout_lines']) pytest_assert(before_portstat, 'No parsed command output') @@ -126,7 +128,8 @@ def test_portstat_clear(duthost, command): 'Value of TX_OK after clear should be lesser') @pytest.mark.parametrize('command', ['portstat -D', 'portstat --delete-all']) -def test_portstat_delete_all(duthost, command): +def test_portstat_delete_all(duthosts, rand_one_dut_hostname, command): + duthost = duthosts[rand_one_dut_hostname] stats_files = ('test_1', 'test_2', 'test_test') @@ -151,7 +154,8 @@ def test_portstat_delete_all(duthost, command): @pytest.mark.parametrize('command', ['portstat -d -t', 'portstat -d --tag', 'portstat --delete -t', 'portstat --delete --tag']) -def test_portstat_delete_tag(duthost, command): +def test_portstat_delete_tag(duthosts, rand_one_dut_hostname, command): + duthost = duthosts[rand_one_dut_hostname] stats_files = ('test_1', 'test_2', 'test_delete_me') file_to_delete = stats_files[2] @@ -182,7 +186,8 @@ def test_portstat_delete_tag(duthost, command): @pytest.mark.parametrize('command', ['portstat -a', 'portstat --all']) -def test_portstat_display_all(duthost, command): +def test_portstat_display_all(duthosts, rand_one_dut_hostname, command): + duthost = duthosts[rand_one_dut_hostname] base_portstat = parse_portstat(duthost.command('portstat')['stdout_lines']) all_portstats = parse_portstat(duthost.command(command)['stdout_lines']) @@ -194,7 +199,8 @@ def test_portstat_display_all(duthost, command): @pytest.mark.parametrize('command', ['portstat -p 1', 'portstat --period 1']) -def test_portstat_period(duthost, command): +def test_portstat_period(duthosts, rand_one_dut_hostname, command): + duthost = duthosts[rand_one_dut_hostname] output = duthost.command(command) pytest_assert('The rates are calculated within 1 seconds period' in output['stdout_lines'][0]) @@ -203,7 +209,8 @@ def test_portstat_period(duthost, command): @pytest.mark.parametrize('command', ['portstat -h', 'portstat --help', 'portstat', 'portstat -v', 'portstat --version', 'portstat -j', 'portstat --json', 'portstat -r', 'portstat --raw']) -def test_portstat_no_exceptions(duthost, command): +def test_portstat_no_exceptions(duthosts, rand_one_dut_hostname, command): + duthost = duthosts[rand_one_dut_hostname] logger.info('Verify that the commands do not cause tracebacks') duthost.command(command) diff --git a/tests/qos/qos_fixtures.py b/tests/qos/qos_fixtures.py index c0e6d1ce087..54096abb892 100644 --- a/tests/qos/qos_fixtures.py +++ b/tests/qos/qos_fixtures.py @@ -3,7 +3,8 @@ @pytest.fixture(scope = "module") -def lossless_prio_dscp_map(duthost): +def lossless_prio_dscp_map(duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] config_facts = duthost.config_facts(host=duthost.hostname, source="persistent")['ansible_facts'] if "PORT_QOS_MAP" not in config_facts.keys(): diff --git a/tests/qos/qos_helpers.py b/tests/qos/qos_helpers.py index 5e51ca978aa..6bf7fc6d87a 100644 --- a/tests/qos/qos_helpers.py +++ b/tests/qos/qos_helpers.py @@ -207,4 +207,4 @@ def setup_testbed(fanouthosts, ptfhost, leaf_fanouts, ptf_local_path, ptf_remote ptfhost.file(path=file, mode="absent") """ Copy the PFC test script to the PTF container """ - ptfhost.copy(src=ptf_local_path, dest=ptf_remote_path, force=True) \ No newline at end of file + ptfhost.copy(src=ptf_local_path, dest=ptf_remote_path, force=True) diff --git a/tests/qos/test_pfc_counters.py b/tests/qos/test_pfc_counters.py index 809ba575ca5..499c129c8fe 100644 --- a/tests/qos/test_pfc_counters.py +++ b/tests/qos/test_pfc_counters.py @@ -88,18 +88,22 @@ def run_test(fanouthosts, duthost, conn_graph_facts, leaf_fanouts, is_pfc=True, else: assert counter_facts[intf]['Rx'] == ['0'] * PRIO_COUNT -def test_pfc_pause(fanouthosts, duthost, conn_graph_facts, leaf_fanouts): +def test_pfc_pause(fanouthosts, duthosts, rand_one_dut_hostname, conn_graph_facts, leaf_fanouts): """ @Summary: Run PFC pause frame (pause time quanta > 0) tests """ + duthost = duthosts[rand_one_dut_hostname] run_test(fanouthosts, duthost, conn_graph_facts, leaf_fanouts) -def test_pfc_unpause(fanouthosts, duthost, conn_graph_facts, leaf_fanouts): +def test_pfc_unpause(fanouthosts, duthosts, rand_one_dut_hostname, conn_graph_facts, leaf_fanouts): """ @Summary: Run PFC unpause frame (pause time quanta = 0) tests """ + duthost = duthosts[rand_one_dut_hostname] run_test(fanouthosts, duthost, conn_graph_facts, leaf_fanouts, pause_time=0) -def test_fc_pause(fanouthosts, duthost, conn_graph_facts, leaf_fanouts): +def test_fc_pause(fanouthosts, duthosts, rand_one_dut_hostname, conn_graph_facts, leaf_fanouts): """ @Summary: Run FC pause frame (pause time quanta > 0) tests """ + duthost = duthosts[rand_one_dut_hostname] run_test(fanouthosts, duthost, conn_graph_facts, leaf_fanouts, is_pfc=False) -def test_fc_unpause(fanouthosts, duthost, conn_graph_facts, leaf_fanouts): +def test_fc_unpause(fanouthosts, duthosts, rand_one_dut_hostname, conn_graph_facts, leaf_fanouts): """ @Summary: Run FC pause frame (pause time quanta = 0) tests """ + duthost = duthosts[rand_one_dut_hostname] run_test(fanouthosts, duthost, conn_graph_facts, leaf_fanouts, is_pfc=False, pause_time=0) diff --git a/tests/read_mac/test_read_mac_metadata.py b/tests/read_mac/test_read_mac_metadata.py index 05dc8b2f914..fc69b932211 100644 --- a/tests/read_mac/test_read_mac_metadata.py +++ b/tests/read_mac/test_read_mac_metadata.py @@ -20,7 +20,8 @@ ] @pytest.fixture(scope='function') -def cleanup_read_mac(duthost, localhost): +def cleanup_read_mac(duthosts, rand_one_dut_hostname, localhost): + duthost = duthosts[rand_one_dut_hostname] yield logger.info('Remove temporary images') duthost.shell("rm -rf {}".format(BINARY_FILE_ON_DUTHOST)) diff --git a/tests/route/test_default_route.py b/tests/route/test_default_route.py index fdc65732627..f4bc9f6ac3a 100644 --- a/tests/route/test_default_route.py +++ b/tests/route/test_default_route.py @@ -10,11 +10,12 @@ logger = logging.getLogger(__name__) -def test_default_route_set_src(duthost): +def test_default_route_set_src(duthosts, rand_one_dut_hostname): """ check if ipv4 and ipv6 default src address match Loopback0 address """ + duthost = duthosts[rand_one_dut_hostname] config_facts = duthost.config_facts(host=duthost.hostname, source="running")['ansible_facts'] @@ -44,11 +45,12 @@ def test_default_route_set_src(duthost): pytest_assert(rtinfo['set_src'] == lo_ipv6.ip, \ "default v6 route set src to wrong IP {} != {}".format(rtinfo['set_src'], lo_ipv6.ip)) -def test_default_ipv6_route_next_hop_global_address(duthost): +def test_default_ipv6_route_next_hop_global_address(duthosts, rand_one_dut_hostname): """ check if ipv6 default route nexthop address uses global address """ + duthost = duthosts[rand_one_dut_hostname] rtinfo = duthost.get_ip_route_info(ipaddress.ip_network(u"::/0")) pytest_assert(rtinfo['nexthops'] > 0, "cannot find ipv6 nexthop for default route") diff --git a/tests/route/test_route_perf.py b/tests/route/test_route_perf.py index 33d744917a1..966756f1688 100644 --- a/tests/route/test_route_perf.py +++ b/tests/route/test_route_perf.py @@ -20,7 +20,7 @@ ROUTE_TABLE_NAME = 'ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY' @pytest.fixture(autouse=True) -def ignore_expected_loganalyzer_exceptions(duthost, loganalyzer): +def ignore_expected_loganalyzer_exceptions(loganalyzer): """ Ignore expected failures logs during test execution. @@ -48,7 +48,8 @@ def ip_versions(request): yield request.param @pytest.fixture(scope='function', autouse=True) -def reload_dut(duthost, request): +def reload_dut(duthosts, rand_one_dut_hostname, request): + duthost = duthosts[rand_one_dut_hostname] yield if request.node.rep_call.failed: #Issue a config_reload to clear statically added route table and ip addr @@ -56,8 +57,9 @@ def reload_dut(duthost, request): config_reload(duthost) @pytest.fixture(scope="module", autouse=True) -def set_polling_interval(duthost): +def set_polling_interval(duthosts, rand_one_dut_hostname): """ Set CRM polling interval to 1 second """ + duthost = duthosts[rand_one_dut_hostname] wait_time = 2 duthost.command("crm config polling interval {}".format(CRM_POLL_INTERVAL)) logger.info("Waiting {} sec for CRM counters to become updated".format(wait_time)) @@ -187,7 +189,8 @@ def _check_num_routes(expected_num_routes): # Retuen time used for set/del routes return (end_time - start_time).total_seconds() -def test_perf_add_remove_routes(duthost, request, ip_versions): +def test_perf_add_remove_routes(duthosts, rand_one_dut_hostname, request, ip_versions): + duthost = duthosts[rand_one_dut_hostname] # Number of routes for test set_num_routes = request.config.getoption("--num_routes") diff --git a/tests/sflow/test_sflow.py b/tests/sflow/test_sflow.py index c5672c56bd8..29f4e14e0cb 100644 --- a/tests/sflow/test_sflow.py +++ b/tests/sflow/test_sflow.py @@ -19,7 +19,8 @@ logger = logging.getLogger(__name__) @pytest.fixture(scope='module',autouse=True) -def setup(duthost, ptfhost): +def setup(duthosts, rand_one_dut_hostname, ptfhost): + duthost = duthosts[rand_one_dut_hostname] global var var = {} @@ -172,7 +173,8 @@ def _partial_ptf_runner(**kwargs): # ---------------------------------------------------------------------------------- @pytest.fixture(scope='class') -def sflowbase_config(duthost): +def sflowbase_config(duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] config_sflow(duthost,'enable') config_sflow_collector(duthost,'collector0','add') config_sflow_collector(duthost,'collector1','add') @@ -193,7 +195,8 @@ class TestSflowCollector(): Test Sflow with 2 collectors , adding or removibg collector and verify collector samples """ - def test_sflow_config(self, duthost, partial_ptf_runner): + def test_sflow_config(self, duthosts, rand_one_dut_hostname, partial_ptf_runner): + duthost = duthosts[rand_one_dut_hostname] # Enable sflow globally and enable sflow on 4 test interfaces # add single collector , send traffic and check samples are received in collector config_sflow(duthost,'enable') @@ -210,7 +213,8 @@ def test_sflow_config(self, duthost, partial_ptf_runner): active_collectors="['collector0']" ) - def test_collector_del_add(self, duthost, partial_ptf_runner): + def test_collector_del_add(self, duthosts, rand_one_dut_hostname, partial_ptf_runner): + duthost = duthosts[rand_one_dut_hostname] # Delete a collector and check samples are not received in collectors config_sflow_collector(duthost,'collector0','del') time.sleep(2) @@ -228,7 +232,8 @@ def test_collector_del_add(self, duthost, partial_ptf_runner): active_collectors="['collector0']" ) - def test_two_collectors(self, sflowbase_config, duthost, partial_ptf_runner): + def test_two_collectors(self, sflowbase_config, duthosts, rand_one_dut_hostname, partial_ptf_runner): + duthost = duthosts[rand_one_dut_hostname] #add 2 collectors with 2 different udp ports and check samples are received in both collectors verify_show_sflow(duthost,status='up',collector=['collector0','collector1']) time.sleep(2) diff --git a/tests/show_techsupport/test_techsupport.py b/tests/show_techsupport/test_techsupport.py index b6a73d8a5f7..97b4c955f2f 100644 --- a/tests/show_techsupport/test_techsupport.py +++ b/tests/show_techsupport/test_techsupport.py @@ -73,12 +73,13 @@ def setup_acl_rules(duthost, acl_setup): @pytest.fixture(scope='function') -def acl_setup(duthost): +def acl_setup(duthosts, rand_one_dut_hostname): """ setup fixture gathers all test required information from DUT facts and testbed :param duthost: DUT host object :return: dictionary with all test required information """ + duthost = duthosts[rand_one_dut_hostname] logger.info('Creating temporary folder for test {}'.format(ACL_RUN_DIR)) duthost.command("mkdir -p {}".format(ACL_RUN_DIR)) tmp_path = duthost.tempfile(path=ACL_RUN_DIR, state='directory', prefix='acl', suffix="")['path'] @@ -106,13 +107,14 @@ def teardown_acl(dut, acl_setup): @pytest.fixture(scope='function') -def acl(duthost, acl_setup): +def acl(duthosts, rand_one_dut_hostname, acl_setup): """ setup/teardown ACL rules based on test class requirements :param duthost: DUT host object :param acl_setup: setup information :return: """ + duthost = duthosts[rand_one_dut_hostname] loganalyzer = LogAnalyzer(ansible_host=duthost, marker_prefix='acl') loganalyzer.load_common_config() @@ -136,7 +138,8 @@ def acl(duthost, acl_setup): # MIRRORING PART # @pytest.fixture(scope='function') -def neighbor_ip(duthost, tbinfo): +def neighbor_ip(duthosts, rand_one_dut_hostname, tbinfo): + duthost = duthosts[rand_one_dut_hostname] # ptf-32 topo is not supported in mirroring if tbinfo['topo']['name'] == 'ptf32': pytest.skip('Unsupported Topology') @@ -156,10 +159,11 @@ def neighbor_ip(duthost, tbinfo): @pytest.fixture(scope='function') -def mirror_setup(duthost): +def mirror_setup(duthosts, rand_one_dut_hostname): """ setup fixture """ + duthost = duthosts[rand_one_dut_hostname] duthost.command('mkdir -p {}'.format(MIRROR_RUN_DIR)) tmp_path = duthost.tempfile(path=MIRROR_RUN_DIR, state='directory', prefix='mirror', suffix="")['path'] @@ -170,7 +174,8 @@ def mirror_setup(duthost): @pytest.fixture(scope='function') -def gre_version(duthost): +def gre_version(duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] asic_type = duthost.facts['asic_type'] if asic_type in ["mellanox"]: SESSION_INFO['gre'] = 0x8949 # Mellanox specific @@ -181,13 +186,14 @@ def gre_version(duthost): @pytest.fixture(scope='function') -def mirroring(duthost, neighbor_ip, mirror_setup, gre_version): +def mirroring(duthosts, rand_one_dut_hostname, neighbor_ip, mirror_setup, gre_version): """ fixture gathers all configuration fixtures :param duthost: DUT host :param mirror_setup: mirror_setup fixture :param mirror_config: mirror_config fixture """ + duthost = duthosts[rand_one_dut_hostname] logger.info("Adding mirror_session to DUT") acl_rule_file = os.path.join(mirror_setup['dut_tmp_dir'], ACL_RULE_PERSISTENT_FILE) extra_vars = { @@ -244,24 +250,26 @@ def config(request): return request.getfixturevalue(request.param) -def execute_command(duthost, since): +def execute_command(duthosts, rand_one_dut_hostname, since): """ Function to execute show techsupport command :param duthost: DUT :param since: since string enterd by user """ + duthost = duthosts[rand_one_dut_hostname] stdout = duthost.command("show techsupport --since={}".format('"' + since + '"')) if stdout['rc'] == SUCCESS_CODE: pytest.tar_stdout = stdout['stdout'] return stdout['rc'] == SUCCESS_CODE -def test_techsupport(request, config, duthost): +def test_techsupport(request, config, duthosts, rand_one_dut_hostname): """ test the "show techsupport" command in a loop :param config: fixture to configure additional setups_list on dut. :param duthost: DUT host """ + duthost = duthosts[rand_one_dut_hostname] loop_range = request.config.getoption("--loop_num") or DEFAULT_LOOP_RANGE loop_delay = request.config.getoption("--loop_delay") or DEFAULT_LOOP_DELAY since = request.config.getoption("--logs_since") or str(randint(1, 23)) + " minute ago" diff --git a/tests/snmp/conftest.py b/tests/snmp/conftest.py index 8c92fa534cd..93a6c68a75c 100644 --- a/tests/snmp/conftest.py +++ b/tests/snmp/conftest.py @@ -2,5 +2,6 @@ from tests.common.utilities import wait_until @pytest.fixture(scope="module", autouse=True) -def setup_check_snmp_ready(duthost): +def setup_check_snmp_ready(duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] assert wait_until(300, 20, duthost.is_service_fully_started, "snmp"), "SNMP service is not running" diff --git a/tests/snmp/test_snmp_cpu.py b/tests/snmp/test_snmp_cpu.py index bb8a9609b52..32a87b3cea3 100644 --- a/tests/snmp/test_snmp_cpu.py +++ b/tests/snmp/test_snmp_cpu.py @@ -10,7 +10,7 @@ ] @pytest.mark.bsl -def test_snmp_cpu(duthost, localhost, creds): +def test_snmp_cpu(duthosts, rand_one_dut_hostname, localhost, creds): """ Test SNMP CPU Utilization @@ -21,6 +21,7 @@ def test_snmp_cpu(duthost, localhost, creds): TODO: abstract the snmp OID by SKU """ + duthost = duthosts[rand_one_dut_hostname] hostip = duthost.host.options['inventory_manager'].get_host(duthost.hostname).vars['ansible_host'] host_facts = duthost.setup()['ansible_facts'] diff --git a/tests/snmp/test_snmp_interfaces.py b/tests/snmp/test_snmp_interfaces.py index c22e96d490e..a05f4030d4e 100644 --- a/tests/snmp/test_snmp_interfaces.py +++ b/tests/snmp/test_snmp_interfaces.py @@ -6,8 +6,9 @@ ] @pytest.mark.bsl -def test_snmp_interfaces(duthost, localhost, creds): +def test_snmp_interfaces(duthosts, rand_one_dut_hostname, localhost, creds): """compare the bgp facts between observed states and target state""" + duthost = duthosts[rand_one_dut_hostname] hostip = duthost.host.options['inventory_manager'].get_host(duthost.hostname).vars['ansible_host'] diff --git a/tests/snmp/test_snmp_lldp.py b/tests/snmp/test_snmp_lldp.py index 978edd31877..7a2398733c4 100644 --- a/tests/snmp/test_snmp_lldp.py +++ b/tests/snmp/test_snmp_lldp.py @@ -6,7 +6,7 @@ ] @pytest.mark.bsl -def test_snmp_lldp(duthost, localhost, creds): +def test_snmp_lldp(duthosts, rand_one_dut_hostname, localhost, creds): """ Test checks for ieee802_1ab MIBs: - lldpLocalSystemData 1.0.8802.1.1.2.1.3 @@ -20,6 +20,7 @@ def test_snmp_lldp(duthost, localhost, creds): For remote values check for availability for at least 80% of minigraph neighbors (similar to lldp test) """ + duthost = duthosts[rand_one_dut_hostname] hostip = duthost.host.options['inventory_manager'].get_host(duthost.hostname).vars['ansible_host'] diff --git a/tests/snmp/test_snmp_pfc_counters.py b/tests/snmp/test_snmp_pfc_counters.py index de52b411b83..5fbcc826640 100644 --- a/tests/snmp/test_snmp_pfc_counters.py +++ b/tests/snmp/test_snmp_pfc_counters.py @@ -5,7 +5,8 @@ pytest.mark.device_type('vs') ] -def test_snmp_pfc_counters(duthost, localhost, creds): +def test_snmp_pfc_counters(duthosts, rand_one_dut_hostname, localhost, creds): + duthost = duthosts[rand_one_dut_hostname] hostip = duthost.host.options['inventory_manager'].get_host(duthost.hostname).vars['ansible_host'] diff --git a/tests/snmp/test_snmp_psu.py b/tests/snmp/test_snmp_psu.py index 148b5a12251..42d00266225 100644 --- a/tests/snmp/test_snmp_psu.py +++ b/tests/snmp/test_snmp_psu.py @@ -7,7 +7,8 @@ ] @pytest.mark.bsl -def test_snmp_numpsu(duthost, localhost, creds): +def test_snmp_numpsu(duthosts, rand_one_dut_hostname, localhost, creds): + duthost = duthosts[rand_one_dut_hostname] hostip = duthost.host.options['inventory_manager'].get_host(duthost.hostname).vars['ansible_host'] @@ -20,7 +21,8 @@ def test_snmp_numpsu(duthost, localhost, creds): @pytest.mark.bsl -def test_snmp_psu_status(duthost, localhost, creds): +def test_snmp_psu_status(duthosts, rand_one_dut_hostname, localhost, creds): + duthost = duthosts[rand_one_dut_hostname] hostip = duthost.host.options['inventory_manager'].get_host(duthost.hostname).vars['ansible_host'] diff --git a/tests/snmp/test_snmp_queue.py b/tests/snmp/test_snmp_queue.py index 47e957f165d..6fe6486bd09 100644 --- a/tests/snmp/test_snmp_queue.py +++ b/tests/snmp/test_snmp_queue.py @@ -5,7 +5,8 @@ pytest.mark.device_type('vs') ] -def test_snmp_queues(duthost, localhost, creds, collect_techsupport): +def test_snmp_queues(duthosts, rand_one_dut_hostname, localhost, creds, collect_techsupport): + duthost = duthosts[rand_one_dut_hostname] hostip = duthost.host.options['inventory_manager'].get_host(duthost.hostname).vars['ansible_host'] diff --git a/tests/syslog/test_syslog.py b/tests/syslog/test_syslog.py index 29c14480ee0..7c694268c9d 100644 --- a/tests/syslog/test_syslog.py +++ b/tests/syslog/test_syslog.py @@ -38,7 +38,8 @@ def _is_syslog_running(): @pytest.fixture(scope="module") -def config_dut(tbinfo, duthost): +def config_dut(tbinfo, duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] logger.info("Configuring the DUT") local_syslog_srv_ip = tbinfo["ptf_ip"] logger.info("test_syslog_srv_ip %s", local_syslog_srv_ip) @@ -53,7 +54,8 @@ def config_dut(tbinfo, duthost): duthost.shell("sudo config syslog del {}".format(local_syslog_srv_ip)) -def test_syslog(duthost, ptfhost, config_dut): +def test_syslog(duthosts, rand_one_dut_hostname, ptfhost, config_dut): + duthost = duthosts[rand_one_dut_hostname] logger.info("Starting syslog tests") test_message = "Basic Test Message" diff --git a/tests/system_health/test_system_health.py b/tests/system_health/test_system_health.py index 36e97ce4899..f86130e2496 100644 --- a/tests/system_health/test_system_health.py +++ b/tests/system_health/test_system_health.py @@ -49,7 +49,8 @@ EXPECT_PSU_INVALID_VOLTAGE = '{} voltage is out of range' -def test_service_checker(duthost): +def test_service_checker(duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] wait_system_health_boot_up(duthost) with ConfigFileContext(duthost, os.path.join(FILES_DIR, IGNORE_DEVICE_CHECK_CONFIG_FILE)): cmd = "monit summary -B" @@ -83,7 +84,8 @@ def test_service_checker(duthost): assert summary == expect_summary, 'Expect summary {}, got {}'.format(expect_summary, summary) -def test_device_checker(duthost, device_mocker_factory): +def test_device_checker(duthosts, rand_one_dut_hostname, device_mocker_factory): + duthost = duthosts[rand_one_dut_hostname] device_mocker = device_mocker_factory(duthost) wait_system_health_boot_up(duthost) with ConfigFileContext(duthost, os.path.join(FILES_DIR, DEVICE_CHECK_CONFIG_FILE)): @@ -232,7 +234,8 @@ def test_device_checker(duthost, device_mocker_factory): assert not value or expect_value not in value, 'Mock PSU good voltage, but it is still invalid' -def test_external_checker(duthost): +def test_external_checker(duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] wait_system_health_boot_up(duthost) with ConfigFileContext(duthost, os.path.join(FILES_DIR, EXTERNAL_CHECK_CONFIG_FILE)): duthost.copy(src=os.path.join(FILES_DIR, EXTERNAL_CHECKER_MOCK_FILE), @@ -244,7 +247,8 @@ def test_external_checker(duthost): assert value == 'Device is broken', 'External checker does not work, value={}'.format(value) -def test_system_health_config(duthost, device_mocker_factory): +def test_system_health_config(duthosts, rand_one_dut_hostname, device_mocker_factory): + duthost = duthosts[rand_one_dut_hostname] device_mocker = device_mocker_factory(duthost) wait_system_health_boot_up(duthost) logging.info('Ignore fan check, verify there is no error information about fan') diff --git a/tests/tacacs/test_ro_user.py b/tests/tacacs/test_ro_user.py index f9b12a4095f..9255331600a 100644 --- a/tests/tacacs/test_ro_user.py +++ b/tests/tacacs/test_ro_user.py @@ -6,7 +6,8 @@ pytest.mark.device_type('vs') ] -def test_ro_user(localhost, duthost, creds, test_tacacs): +def test_ro_user(localhost, duthosts, rand_one_dut_hostname, creds, test_tacacs): + duthost = duthosts[rand_one_dut_hostname] dutip = duthost.host.options['inventory_manager'].get_host(duthost.hostname).vars['ansible_host'] res = localhost.shell("sshpass -p {} ssh "\ @@ -19,7 +20,8 @@ def test_ro_user(localhost, duthost, creds, test_tacacs): if fds[0] == "test": assert fds[4] == "remote_user" -def test_ro_user_ipv6(localhost, duthost, creds, test_tacacs_v6): +def test_ro_user_ipv6(localhost, duthosts, rand_one_dut_hostname, creds, test_tacacs_v6): + duthost = duthosts[rand_one_dut_hostname] dutip = duthost.host.options['inventory_manager'].get_host(duthost.hostname).vars['ansible_host'] res = localhost.shell("sshpass -p {} ssh "\ diff --git a/tests/tacacs/test_rw_user.py b/tests/tacacs/test_rw_user.py index f60fb4819e2..cabab925905 100644 --- a/tests/tacacs/test_rw_user.py +++ b/tests/tacacs/test_rw_user.py @@ -7,9 +7,10 @@ pytest.mark.device_type('vs') ] -def test_rw_user(duthost, creds, test_tacacs): +def test_rw_user(duthosts, rand_one_dut_hostname, creds, test_tacacs): """test tacacs rw user """ + duthost = duthosts[rand_one_dut_hostname] duthost.host.options['variable_manager'].extra_vars.update( {'ansible_user':creds['tacacs_rw_user'], 'ansible_password':creds['tacacs_rw_user_passwd']}) @@ -21,9 +22,10 @@ def test_rw_user(duthost, creds, test_tacacs): if fds[0] == "testadmin": assert fds[4] == "remote_user_su" -def test_rw_user_ipv6(duthost, creds, test_tacacs_v6): +def test_rw_user_ipv6(duthosts, rand_one_dut_hostname, creds, test_tacacs_v6): """test tacacs rw user """ + duthost = duthosts[rand_one_dut_hostname] duthost.host.options['variable_manager'].extra_vars.update( {'ansible_user':creds['tacacs_rw_user'], 'ansible_password':creds['tacacs_rw_user_passwd']}) diff --git a/tests/telemetry/test_telemetry.py b/tests/telemetry/test_telemetry.py index 4fa179c978f..58ebf0daf4f 100644 --- a/tests/telemetry/test_telemetry.py +++ b/tests/telemetry/test_telemetry.py @@ -55,9 +55,10 @@ def verify_telemetry_dockerimage(duthost): return (len(matching) > 0) # Test functions -def test_config_db_parameters(duthost): +def test_config_db_parameters(duthosts, rand_one_dut_hostname): """Verifies required telemetry parameters from config_db. """ + duthost = duthosts[rand_one_dut_hostname] docker_present = verify_telemetry_dockerimage(duthost) if not docker_present: pytest.skip("docker-sonic-telemetry is not part of the image") @@ -83,9 +84,10 @@ def test_config_db_parameters(duthost): server_crt_expected = "/etc/sonic/telemetry/streamingtelemetryserver.cer" pytest_assert(str(value) == server_crt_expected, "'server_crt' value is not '{}'".format(server_crt_expected)) -def test_telemetry_enabledbydefault(duthost): +def test_telemetry_enabledbydefault(duthosts, rand_one_dut_hostname): """Verify telemetry should be enabled by default """ + duthost = duthosts[rand_one_dut_hostname] docker_present = verify_telemetry_dockerimage(duthost) if not docker_present: pytest.skip("docker-sonic-telemetry is not part of the image") @@ -101,9 +103,10 @@ def test_telemetry_enabledbydefault(duthost): status_expected = "enabled"; pytest_assert(str(v) == status_expected, "Telemetry feature is not enabled") -def test_telemetry_ouput(duthost, ptfhost, localhost): +def test_telemetry_ouput(duthosts, rand_one_dut_hostname, ptfhost, localhost): """Run pyclient from ptfdocker and show gnmi server outputself. """ + duthost = duthosts[rand_one_dut_hostname] docker_present = verify_telemetry_dockerimage(duthost) if not docker_present: pytest.skip("docker-sonic-telemetry is not part of the image") diff --git a/tests/test_procdockerstatsd.py b/tests/test_procdockerstatsd.py index 7605cf6833a..45483f337b2 100644 --- a/tests/test_procdockerstatsd.py +++ b/tests/test_procdockerstatsd.py @@ -15,15 +15,17 @@ def get_count_fromredisout(keys_out): return count # Test Functions -def test_verify_status(duthost): +def test_verify_status(duthosts, rand_one_dut_hostname): """Verify procdockerstatsd is active and running """ + duthost = duthosts[rand_one_dut_hostname] status = duthost.get_service_props('procdockerstatsd') pytest_assert(status["ActiveState"] == "active" and status["SubState"] == "running", "Procdockerstatsd either not active or not running") -def test_verify_redisexport(duthost): +def test_verify_redisexport(duthosts, rand_one_dut_hostname): """Verify procdockerstatsd is exporting values to redis. """ + duthost = duthosts[rand_one_dut_hostname] docker_stdout = duthost.shell('/usr/bin/redis-cli -n 6 KEYS "DOCKER_STATS|*" | wc -l', module_ignore_errors=False)['stdout_lines'] docker_keys_count = get_count_fromredisout(docker_stdout) process_stdout= duthost.shell('/usr/bin/redis-cli -n 6 KEYS "PROCESS_STATS|*" | wc -l', module_ignore_errors=False)['stdout_lines'] diff --git a/tests/upgrade_path/test_upgrade_path.py b/tests/upgrade_path/test_upgrade_path.py index e5d69ea5d6f..0599cd5f751 100644 --- a/tests/upgrade_path/test_upgrade_path.py +++ b/tests/upgrade_path/test_upgrade_path.py @@ -29,7 +29,8 @@ @pytest.fixture(scope="module") -def setup(localhost, ptfhost, duthost, upgrade_path_lists): +def setup(localhost, ptfhost, duthosts, rand_one_dut_hostname, upgrade_path_lists): + duthost = duthosts[rand_one_dut_hostname] prepare_ptf(ptfhost, duthost) yield cleanup(localhost, ptfhost, duthost, upgrade_path_lists) @@ -81,7 +82,8 @@ def prepare_ptf(ptfhost, duthost): @pytest.fixture(scope="module") -def ptf_params(duthost, nbrhosts, creds): +def ptf_params(duthosts, rand_one_dut_hostname, nbrhosts, creds): + duthost = duthosts[rand_one_dut_hostname] mg_facts = duthost.minigraph_facts(host=duthost.hostname)['ansible_facts'] lo_v6_prefix = "" @@ -139,7 +141,8 @@ def install_sonic(duthost, image_url): res = duthost.reduce_and_add_sonic_images(new_image_url=image_url) return res['ansible_facts']['downloaded_image_version'] -def test_upgrade_path(localhost, duthost, ptfhost, upgrade_path_lists, ptf_params, setup): +def test_upgrade_path(localhost, duthosts, rand_one_dut_hostname, ptfhost, upgrade_path_lists, ptf_params, setup): + duthost = duthosts[rand_one_dut_hostname] from_list_images, to_list_images, _ = upgrade_path_lists from_list = from_list_images.split(',') to_list = to_list_images.split(',') diff --git a/tests/vlan/test_vlan.py b/tests/vlan/test_vlan.py index 09fe16ac72b..094e3cd9905 100644 --- a/tests/vlan/test_vlan.py +++ b/tests/vlan/test_vlan.py @@ -23,7 +23,8 @@ ] @pytest.fixture(scope="module") -def cfg_facts(duthost): +def cfg_facts(duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] return duthost.config_facts(host=duthost.hostname, source="persistent")['ansible_facts'] @pytest.fixture(scope="module") @@ -93,7 +94,8 @@ def create_vlan_interfaces(vlan_ports_list, vlan_intfs_list, duthost, ptfhost): @pytest.fixture(scope="module", autouse=True) -def setup_vlan(ptfadapter, duthost, ptfhost, vlan_ports_list, vlan_intfs_list, cfg_facts): +def setup_vlan(ptfadapter, duthosts, rand_one_dut_hostname, ptfhost, vlan_ports_list, vlan_intfs_list, cfg_facts): + duthost = duthosts[rand_one_dut_hostname] # --------------------- Setup ----------------------- try: diff --git a/tests/vrf/test_vrf.py b/tests/vrf/test_vrf.py index 15fa2946de2..97f3a45fcae 100644 --- a/tests/vrf/test_vrf.py +++ b/tests/vrf/test_vrf.py @@ -338,11 +338,13 @@ def gen_vrf_neigh_file(vrf, ptfhost, render_file): # fixtures @pytest.fixture(scope="module") -def host_facts(duthost): +def host_facts(duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] return get_host_facts(duthost) @pytest.fixture(scope="module") -def cfg_facts(duthost): +def cfg_facts(duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] return get_cfg_facts(duthost) def restore_config_db(localhost, duthost, ptfhost): @@ -361,7 +363,8 @@ def restore_config_db(localhost, duthost, ptfhost): cleanup_vlan_peer(ptfhost, g_vars['vlan_peer_vrf2ns_map']) @pytest.fixture(scope="module", autouse=True) -def setup_vrf(tbinfo, duthost, ptfhost, localhost, host_facts): +def setup_vrf(tbinfo, duthosts, rand_one_dut_hostname, ptfhost, localhost, host_facts): + duthost = duthosts[rand_one_dut_hostname] # backup config_db.json duthost.shell("mv /etc/sonic/config_db.json /etc/sonic/config_db.json.bak") @@ -432,7 +435,8 @@ def _partial_ptf_runner(testname, **kwargs): # tests class TestVrfCreateAndBind(): - def test_vrf_in_kernel(self, duthost, cfg_facts): + def test_vrf_in_kernel(self, duthosts, rand_one_dut_hostname, cfg_facts): + duthost = duthosts[rand_one_dut_hostname] # verify vrf in kernel res = duthost.shell("ip link show type vrf | grep Vrf") @@ -444,7 +448,8 @@ def test_vrf_in_kernel(self, duthost, cfg_facts): res = duthost.shell("ip link show %s" % intf) assert vrf in res['stdout'], "The master dev of interface %s should be %s !" % (intf, vrf) - def test_vrf_in_appl_db(self, duthost, cfg_facts): + def test_vrf_in_appl_db(self, duthosts, rand_one_dut_hostname, cfg_facts): + duthost = duthosts[rand_one_dut_hostname] # verify vrf in app_db for vrf in cfg_facts['VRF'].keys(): res = duthost.shell("redis-cli -n 0 keys VRF_TABLE:%s" % vrf) @@ -455,7 +460,8 @@ def test_vrf_in_appl_db(self, duthost, cfg_facts): res = duthost.shell("redis-cli -n 0 hgetall \"INTF_TABLE:%s\"" % intf) assert vrf in res['stdout'], "The vrf of interface %s should be %s !" % (intf, vrf) - def test_vrf_in_asic_db(self, duthost, cfg_facts): + def test_vrf_in_asic_db(self, duthosts, rand_one_dut_hostname, cfg_facts): + duthost = duthosts[rand_one_dut_hostname] # verify vrf in asic_db vrf_count = len(cfg_facts['VRF'].keys()) + 1 # plus default virtual router res = duthost.shell("redis-cli -n 1 keys *VIRTUAL_ROUTER*") @@ -463,7 +469,8 @@ def test_vrf_in_asic_db(self, duthost, cfg_facts): class TestVrfNeigh(): - def test_ping_lag_neigh(self, duthost, cfg_facts): + def test_ping_lag_neigh(self, duthosts, rand_one_dut_hostname, cfg_facts): + duthost = duthosts[rand_one_dut_hostname] for neigh in cfg_facts['BGP_NEIGHBOR']: if '|' not in neigh: continue @@ -478,7 +485,8 @@ def test_ping_lag_neigh(self, duthost, cfg_facts): duthost.shell(cmd) - def test_ping_vlan_neigh(self, duthost): + def test_ping_vlan_neigh(self, duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] for (vrf, _), neigh_ips in g_vars['vlan_peer_ips'].iteritems(): for ver, ips in neigh_ips.iteritems(): ping_cmd = 'ping' if ver == 'ipv4' else 'ping6' @@ -515,7 +523,8 @@ def setup_fib_test(self, ptfhost, tbinfo): dst_intfs=['PortChannel0003', 'PortChannel0004'], render_file='/tmp/vrf2_fib.txt') - def test_show_bgp_summary(self, duthost, cfg_facts): + def test_show_bgp_summary(self, duthosts, rand_one_dut_hostname, cfg_facts): + duthost = duthosts[rand_one_dut_hostname] props = g_vars['props'] route_count = props['podset_number'] * props['tor_number'] * props['tor_subnet_number'] @@ -601,7 +610,8 @@ class TestVrfAclRedirect(): c_vars = {} @pytest.fixture(scope="class", autouse=True) - def setup_acl_redirect(self, duthost, cfg_facts): + def setup_acl_redirect(self, duthosts, rand_one_dut_hostname, cfg_facts): + duthost = duthosts[rand_one_dut_hostname] # -------- Setup ---------- # make sure neighs from Vlan2000 are resolved @@ -744,7 +754,8 @@ def setup_vrf_loopback(self, duthost, ptfhost, cfg_facts, tbinfo): # routes on ptf could be flushed when remove vrfs duthost.shell("sysctl -w net.ipv6.ip_nonlocal_bind=0") - def test_ping_vrf1_loopback(self, ptfhost, duthost): + def test_ping_vrf1_loopback(self, ptfhost, duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] for ver, ips in self.c_vars['lb0_ip_facts'].iteritems(): for ip in ips: if ip.version == 4: @@ -757,7 +768,8 @@ def test_ping_vrf1_loopback(self, ptfhost, duthost): neigh_ip6 = self.c_vars['vlan1000_ip_facts']['ipv6'][0].ip + 1 duthost.shell("ping6 {} -I Vrf1 -I {} -c 3 -f -W2".format(neigh_ip6, ip.ip)) - def test_ping_vrf2_loopback(self, ptfhost, duthost): + def test_ping_vrf2_loopback(self, ptfhost, duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] for ver, ips in self.c_vars['lb2_ip_facts'].iteritems(): for ip in ips: if ip.version == 4: @@ -857,7 +869,8 @@ def setup_bgp_with_loopback(self, duthost, ptfhost, cfg_facts): #duthost.shell("vtysh -c 'config terminal' -c 'no router bgp 65444'") @pytest.mark.usefixtures('setup_bgp_with_loopback') - def test_bgp_with_loopback(self, duthost, cfg_facts): + def test_bgp_with_loopback(self, duthosts, rand_one_dut_hostname, cfg_facts): + duthost = duthosts[rand_one_dut_hostname] peer_range = IPNetwork(cfg_facts['BGP_PEER_RANGE']['BGPSLBPassive']['ip_range'][0]) ptf_speaker_ip = IPNetwork("{}/{}".format(peer_range[1], peer_range.prefixlen)) @@ -888,7 +901,8 @@ def setup_vrf_warm_reboot(self, ptfhost, tbinfo): #FIXME Might need cold reboot if test failed? pass - def test_vrf_swss_warm_reboot(self, duthost, cfg_facts, partial_ptf_runner): + def test_vrf_swss_warm_reboot(self, duthosts, rand_one_dut_hostname, cfg_facts, partial_ptf_runner): + duthost = duthosts[rand_one_dut_hostname] # enable swss warm-reboot duthost.shell("config warm_restart enable swss") @@ -934,7 +948,8 @@ def test_vrf_swss_warm_reboot(self, duthost, cfg_facts, partial_ptf_runner): assert wait_until(300, 20, check_interface_status, duthost, up_ports), \ "All interfaces should be up!" - def test_vrf_system_warm_reboot(self, duthost, localhost, cfg_facts, partial_ptf_runner): + def test_vrf_system_warm_reboot(self, duthosts, rand_one_dut_hostname, localhost, cfg_facts, partial_ptf_runner): + duthost = duthosts[rand_one_dut_hostname] exc_que = Queue.Queue() params = { 'ptf_runner': partial_ptf_runner, @@ -1160,7 +1175,8 @@ def setup_vrf_capacity(self, duthost, ptfhost, localhost, cfg_facts, vrf_count, duthost.shell("logger -p INFO -- '-------- {} end!!! ---------'".format(request.cls.__name__)) - def test_ping(self, duthost, random_vrf_list): + def test_ping(self, duthosts, rand_one_dut_hostname, random_vrf_list): + duthost = duthosts[rand_one_dut_hostname] dut_extra_vars = { 'vrf_name_tpl': self.vrf_name_tpl, 'random_vrf_list': random_vrf_list, @@ -1224,13 +1240,15 @@ def setup_vrf_rebind_intf(self, duthost, cfg_facts): assert wait_until(120, 10, check_bgp_facts, duthost, cfg_facts), \ "Bgp sessions should be re-estabalished after Portchannel0001 rebind to Vrf" - def test_pc1_ip_addr_flushed(self, duthost): + def test_pc1_ip_addr_flushed(self, duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] ip_addr_show = duthost.shell("ip addr show PortChannel0001")['stdout'] for ver, ips in g_vars['vrf_intfs']['Vrf1']['PortChannel0001'].iteritems(): for ip in ips: assert str(ip) not in ip_addr_show, "The ip addresses on PortChannel0001 should be flushed after unbind from vrf." - def test_pc1_neigh_flushed(self, duthost): + def test_pc1_neigh_flushed(self, duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] # verify ipv4 show_arp = duthost.shell("show arp")['stdout'] assert 'PortChannel0001' not in show_arp, "The arps on PortChannel0001 should be flushed after unbind from vrf." @@ -1374,23 +1392,28 @@ def setup_vrf_restore(self, duthost, cfg_facts): assert wait_until(120, 10, check_bgp_facts, duthost, cfg_facts), \ "Bgp sessions should be re-estabalished after restore Vrf1" - def test_pc1_ip_addr_flushed(self, duthost): + def test_pc1_ip_addr_flushed(self, duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] show_interfaces = duthost.shell("show ip interfaces")['stdout'] assert 'PortChannel0001' not in show_interfaces, "The ip addr of PortChannel0001 should be flushed after Vrf1 is deleted." - def test_pc2_ip_addr_flushed(self, duthost): + def test_pc2_ip_addr_flushed(self, duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] show_interfaces = duthost.shell("show ip interfaces")['stdout'] assert 'PortChannel0002' not in show_interfaces, "The ip addr of PortChannel0002 should be flushed after Vrf1 is deleted." - def test_vlan1000_ip_addr_flushed(self, duthost): + def test_vlan1000_ip_addr_flushed(self, duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] show_interfaces = duthost.shell("show ip interfaces")['stdout'] assert 'Vlan1000' not in show_interfaces, "The ip addr of Vlan1000 should be flushed after Vrf1 is deleted." - def test_loopback0_ip_addr_flushed(self, duthost): + def test_loopback0_ip_addr_flushed(self, duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] show_interfaces = duthost.shell("show ip interfaces")['stdout'] assert 'Loopback0' not in show_interfaces, "The ip addr of Loopback0 should be flushed after Vrf1 is deleted." - def test_vrf1_neighs_flushed(self, duthost): + def test_vrf1_neighs_flushed(self, duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] ip_neigh_show = duthost.shell("ip neigh show vrf Vrf1", module_ignore_errors=True)['stdout'] assert '' == ip_neigh_show, "The neighbors on Vrf1 should be flushed after Vrf1 is deleted." diff --git a/tests/vrf/test_vrf_attr.py b/tests/vrf/test_vrf_attr.py index 1deac4e2567..84a6bed821c 100644 --- a/tests/vrf/test_vrf_attr.py +++ b/tests/vrf/test_vrf_attr.py @@ -39,7 +39,8 @@ def setup_vrf_attr_src_mac(self, duthost, ptfhost, host_facts): duthost.shell("config load -y /tmp/vrf_attr_src_mac.json") - def test_vrf_src_mac_cfg(self, duthost): + def test_vrf_src_mac_cfg(self, duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] # get vrf1 new router_mac from config_db vrf1_mac = duthost.shell("redis-cli -n 4 hget 'VRF|Vrf1' 'src_mac'")['stdout'] assert vrf1_mac == self.new_vrf1_router_mac diff --git a/tests/vxlan/__init__.py b/tests/vxlan/__init__.py index 8585b4a5be9..cb8d9ce4ecd 100644 --- a/tests/vxlan/__init__.py +++ b/tests/vxlan/__init__.py @@ -53,7 +53,7 @@ def vnet_test_params(request): return params @pytest.fixture(scope="module") -def minigraph_facts(duthost): +def minigraph_facts(duthosts, rand_one_dut_hostname): """ Fixture to get minigraph facts @@ -63,6 +63,7 @@ def minigraph_facts(duthost): Returns: Dictionary containing minigraph information """ + duthost = duthosts[rand_one_dut_hostname] return duthost.minigraph_facts(host=duthost.hostname)["ansible_facts"] diff --git a/tests/vxlan/test_vnet_route_leak.py b/tests/vxlan/test_vnet_route_leak.py index 52325b30d47..75bf23aafa4 100644 --- a/tests/vxlan/test_vnet_route_leak.py +++ b/tests/vxlan/test_vnet_route_leak.py @@ -36,7 +36,7 @@ @pytest.fixture(scope="module") -def configure_dut(minigraph_facts, duthost, vnet_config, vnet_test_params): +def configure_dut(minigraph_facts, duthosts, rand_one_dut_hostname, vnet_config, vnet_test_params): """ Setup/teardown fixture for VNET route leak test @@ -49,6 +49,7 @@ def configure_dut(minigraph_facts, duthost, vnet_config, vnet_test_params): vnet_config: Dictionary containing VNET configuration information vnet_test_params: Dictionary containing VNET test parameters """ + duthost = duthosts[rand_one_dut_hostname] logger.info("Backing up config_db.json") duthost.shell(BACKUP_CONFIG_DB_CMD) @@ -165,7 +166,7 @@ def get_leaked_routes(duthost): return leaked_routes -def test_vnet_route_leak(configure_dut, duthost): +def test_vnet_route_leak(configure_dut, duthosts, rand_one_dut_hostname): """ Test case for VNET route leak check @@ -180,6 +181,7 @@ def test_vnet_route_leak(configure_dut, duthost): configure_dut: Pytest fixture to prepare DUT for testing duthost: DUT host object """ + duthost = duthosts[rand_one_dut_hostname] leaked_routes = get_leaked_routes(duthost) pytest_assert(not leaked_routes, LEAKED_ROUTES_TEMPLATE.format(leaked_routes)) diff --git a/tests/vxlan/test_vnet_vxlan.py b/tests/vxlan/test_vnet_vxlan.py index 6d5a0f0e8f3..a4452d8a107 100644 --- a/tests/vxlan/test_vnet_vxlan.py +++ b/tests/vxlan/test_vnet_vxlan.py @@ -60,7 +60,7 @@ def prepare_ptf(ptfhost, mg_facts, dut_facts, vnet_config): ptfhost.copy(content=json.dumps(vnet_json, indent=2), dest="/tmp/vnet.json") @pytest.fixture(scope="module") -def setup(duthost, ptfhost, minigraph_facts, vnet_config, vnet_test_params): +def setup(duthosts, rand_one_dut_hostname, ptfhost, minigraph_facts, vnet_config, vnet_test_params): """ Prepares DUT and PTF hosts for testing @@ -71,6 +71,7 @@ def setup(duthost, ptfhost, minigraph_facts, vnet_config, vnet_test_params): vnet_config: Configuration file generated from templates/vnet_config.j2 vnet_test_params: Dictionary holding vnet test parameters """ + duthost = duthosts[rand_one_dut_hostname] dut_facts = duthost.setup(gather_subset="!all,!any,network", filter="ansible_Ethernet*")["ansible_facts"] @@ -81,7 +82,7 @@ def setup(duthost, ptfhost, minigraph_facts, vnet_config, vnet_test_params): return minigraph_facts @pytest.fixture(params=["Disabled", "Enabled", "Cleanup"]) -def vxlan_status(setup, request, duthost, vnet_test_params, vnet_config): +def vxlan_status(setup, request, duthosts, rand_one_dut_hostname, vnet_test_params, vnet_config): """ Paramterized fixture that tests the Disabled, Enabled, and Cleanup configs for VxLAN @@ -93,6 +94,7 @@ def vxlan_status(setup, request, duthost, vnet_test_params, vnet_config): Returns: A tuple containing the VxLAN status (True or False), and the test scenario (one of the pytest parameters) """ + duthost = duthosts[rand_one_dut_hostname] vxlan_enabled = False if request.param == "Disabled": @@ -117,7 +119,7 @@ def vxlan_status(setup, request, duthost, vnet_test_params, vnet_config): return vxlan_enabled, request.param -def test_vnet_vxlan(setup, vxlan_status, duthost, ptfhost, vnet_test_params, creds): +def test_vnet_vxlan(setup, vxlan_status, duthosts, rand_one_dut_hostname, ptfhost, vnet_test_params, creds): """ Test case for VNET VxLAN @@ -128,6 +130,7 @@ def test_vnet_vxlan(setup, vxlan_status, duthost, ptfhost, vnet_test_params, cre ptfhost: PTF host object vnet_test_params: Dictionary containing vnet test parameters """ + duthost = duthosts[rand_one_dut_hostname] vxlan_enabled, scenario = vxlan_status diff --git a/tests/vxlan/test_vxlan_decap.py b/tests/vxlan/test_vxlan_decap.py index 5d71e331e94..c9fe5f29e41 100644 --- a/tests/vxlan/test_vxlan_decap.py +++ b/tests/vxlan/test_vxlan_decap.py @@ -92,7 +92,8 @@ def generate_vxlan_config_files(duthost, mg_facts): @pytest.fixture(scope="module") -def setup(duthost, ptfhost): +def setup(duthosts, rand_one_dut_hostname, ptfhost): + duthost = duthosts[rand_one_dut_hostname] logger.info("Gather some facts") mg_facts = duthost.minigraph_facts(host=duthost.hostname)["ansible_facts"] @@ -119,7 +120,8 @@ def setup(duthost, ptfhost): @pytest.fixture(params=["NoVxLAN", "Enabled", "Removed"]) -def vxlan_status(setup, request, duthost): +def vxlan_status(setup, request, duthosts, rand_one_dut_hostname): + duthost = duthosts[rand_one_dut_hostname] #clear FDB and arp cache on DUT duthost.shell('sonic-clear arp; fdbclear') if request.param == "Enabled": @@ -135,7 +137,8 @@ def vxlan_status(setup, request, duthost): return False, request.param -def test_vxlan_decap(setup, vxlan_status, duthost, ptfhost, creds): +def test_vxlan_decap(setup, vxlan_status, duthosts, rand_one_dut_hostname, ptfhost, creds): + duthost = duthosts[rand_one_dut_hostname] vxlan_enabled, scenario = vxlan_status logger.info("vxlan_enabled=%s, scenario=%s" % (vxlan_enabled, scenario))