Skip to content
Merged
15 changes: 10 additions & 5 deletions tests/acl/test_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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"])
Expand All @@ -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:
Expand All @@ -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"
Expand Down Expand Up @@ -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:
Expand All @@ -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"]

Expand Down
3 changes: 2 additions & 1 deletion tests/arp/test_arpall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down
5 changes: 3 additions & 2 deletions tests/autorestart/test_container_autorestart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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)

Expand Down
6 changes: 4 additions & 2 deletions tests/bgp/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}\" \
Expand Down Expand Up @@ -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', {})
Expand Down
3 changes: 2 additions & 1 deletion tests/bgp/test_bgp_gr_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', {})
Expand Down
3 changes: 2 additions & 1 deletion tests/bgp/test_bgp_multipath_relax.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
12 changes: 8 additions & 4 deletions tests/bgp/test_bgp_speaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###########")

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
3 changes: 2 additions & 1 deletion tests/cacl/test_cacl_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,15 @@ 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

This is done by generating our own set of expected iptables and ip6tables
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"]
Expand Down
3 changes: 2 additions & 1 deletion tests/cacl/test_cacl_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/common/fixtures/advanced_reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion tests/common/fixtures/conn_graph_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
12 changes: 8 additions & 4 deletions tests/common/fixtures/duthost_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
12 changes: 8 additions & 4 deletions tests/common/fixtures/pfc_asym.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']


Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 = {
Expand Down
3 changes: 2 additions & 1 deletion tests/common/fixtures/populate_fdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
3 changes: 2 additions & 1 deletion tests/common/fixtures/ptfhost_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/common/helpers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
DEFAULT_NAMESPACE = None
NAMESPACE_PREFIX = 'asic'
ASIC_PARAM_TYPE_ALL = 'num_asics'
ASIC_PARAM_TYPE_FRONTEND = 'frontend_asics'
ASIC_PARAM_TYPE_FRONTEND = 'frontend_asics'
Loading