diff --git a/tests/acl/test_acl.py b/tests/acl/test_acl.py index d0b674f323b..b83e4241012 100644 --- a/tests/acl/test_acl.py +++ b/tests/acl/test_acl.py @@ -9,6 +9,7 @@ import ptf.testutils as testutils import ptf.mask as mask import ptf.packet as packet +import re from abc import ABCMeta, abstractmethod from collections import defaultdict @@ -21,8 +22,9 @@ from tests.common.fixtures.ptfhost_utils import copy_arp_responder_py, run_garp_service, change_mac_addresses # noqa F401 from tests.common.dualtor.dual_tor_mock import mock_server_base_ip_addr # noqa F401 from tests.common.helpers.constants import DEFAULT_NAMESPACE -from tests.common.utilities import wait_until, get_upstream_neigh_type, get_downstream_neigh_type, check_msg_in_syslog -from tests.common.fixtures.conn_graph_facts import conn_graph_facts # noqa F401 +from tests.common.utilities import wait_until, check_msg_in_syslog +from tests.common.utilities import get_all_upstream_neigh_type, get_downstream_neigh_type +from tests.common.fixtures.conn_graph_facts import conn_graph_facts # noqa: F401 from tests.common.platform.processes_utils import wait_critical_processes from tests.common.platform.interface_utils import check_all_interface_information from tests.common.utilities import get_iface_ip @@ -346,9 +348,9 @@ def setup(duthosts, ptfhost, rand_selected_dut, rand_unselected_dut, tbinfo, ptf downstream_port_id_to_router_mac_map = t2_info['downstream_port_id_to_router_mac_map'] upstream_port_id_to_router_mac_map = t2_info['upstream_port_id_to_router_mac_map'] else: - upstream_neigh_type = get_upstream_neigh_type(topo) + upstream_neigh_types = get_all_upstream_neigh_type(topo) downstream_neigh_type = get_downstream_neigh_type(topo) - pytest_require(upstream_neigh_type is not None and downstream_neigh_type is not None, + pytest_require(len(upstream_neigh_types) > 0 and downstream_neigh_type is not None, "Cannot get neighbor type for unsupported topo: {}".format(topo)) mg_vlans = mg_facts["minigraph_vlans"] for interface, neighbor in list(mg_facts["minigraph_neighbors"].items()): @@ -361,10 +363,11 @@ def setup(duthosts, ptfhost, rand_selected_dut, rand_unselected_dut, tbinfo, ptf downstream_ports[neighbor['namespace']].append(interface) downstream_port_ids.append(port_id) downstream_port_id_to_router_mac_map[port_id] = downlink_dst_mac - elif upstream_neigh_type in neighbor["name"].upper(): - upstream_ports[neighbor['namespace']].append(interface) - upstream_port_ids.append(port_id) - upstream_port_id_to_router_mac_map[port_id] = rand_selected_dut.facts["router_mac"] + for neigh_type in upstream_neigh_types: + if neigh_type in neighbor["name"].upper(): + upstream_ports[neighbor['namespace']].append(interface) + upstream_port_ids.append(port_id) + upstream_port_id_to_router_mac_map[port_id] = rand_selected_dut.facts["router_mac"] # stop garp service for single tor if 'dualtor' not in tbinfo['topo']['name']: @@ -397,9 +400,18 @@ def setup(duthosts, ptfhost, rand_selected_dut, rand_unselected_dut, tbinfo, ptf # In multi-asic we need config both in host and namespace. if namespace: acl_table_ports[''] += port - - if topo in ["t0", "m0_vlan", "m0_l3"] or tbinfo["topo"]["name"] in ("t1-lag", "t1-64-lag", "t1-64-lag-clet", - "t1-56-lag", "t1-28-lag", "t1-32-lag"): + if ( + len(port_channels) + and ( + topo in ["t0", "m0_vlan", "m0_l3"] + or tbinfo["topo"]["name"] in ( + "t1-lag", "t1-64-lag", "t1-64-lag-clet", + "t1-56-lag", "t1-28-lag", "t1-32-lag" + ) + or 't1-isolated' in tbinfo["topo"]["name"] + ) + and not re.match(r"t0-.*s\d+", tbinfo["topo"]["name"]) + ): for k, v in list(port_channels.items()): acl_table_ports[v['namespace']].append(k) # In multi-asic we need config both in host and namespace. diff --git a/tests/acl/test_stress_acl.py b/tests/acl/test_stress_acl.py index ca0a80e5589..d826572f61c 100644 --- a/tests/acl/test_stress_acl.py +++ b/tests/acl/test_stress_acl.py @@ -112,7 +112,8 @@ def prepare_test_port(rand_selected_dut, tbinfo): upstream_port_ids = [] for interface, neighbor in list(mg_facts["minigraph_neighbors"].items()): port_id = mg_facts["minigraph_ptf_indices"][interface] - if (topo == "t1" and "T2" in neighbor["name"]) or (topo == "t0" and "T1" in neighbor["name"]) or \ + if (topo == "t1" and "T2" in neighbor["name"]) or \ + (topo == "t0" and ("T1" in neighbor["name"] or "PT0" in neighbor["name"])) or \ (topo == "m0" and "M1" in neighbor["name"]) or (topo == "mx" and "M0" in neighbor["name"]): upstream_ports[neighbor['namespace']].append(interface) upstream_port_ids.append(port_id) diff --git a/tests/common/helpers/constants.py b/tests/common/helpers/constants.py index 8f42b4940b6..3cdba761e17 100644 --- a/tests/common/helpers/constants.py +++ b/tests/common/helpers/constants.py @@ -19,6 +19,19 @@ "m0_vlan": "m1", "m0_l3": "m1" } + +# Describe ALL upstream neighbor of dut in different topos +UPSTREAM_ALL_NEIGHBOR_MAP = { + "t0": ["t1", "pt0"], + "t1": ["t2"], + "m1": ["ma", "mb"], + "m0": ["m1"], + "mx": ["m0"], + "t2": ["t3"], + "m0_vlan": ["m1"], + "m0_l3": ["m1"], +} + # Describe downstream neighbor of dut in different topos DOWNSTREAM_NEIGHBOR_MAP = { "t0": "server", @@ -29,3 +42,15 @@ "m0_vlan": "server", "m0_l3": "mx" } + +# Describe downstream neighbor of dut in different topos +DOWNSTREAM_ALL_NEIGHBOR_MAP = { + "t0": ["server"], + "t1": ["t0"], + "m1": ["m0", "c0"], + "m0": ["mx", "server"], + "mx": ["server"], + "t2": ["t1"], + "m0_vlan": ["mx", "server"], + "m0_l3": ["mx", "server"], +} diff --git a/tests/common/helpers/ptf_tests_helper.py b/tests/common/helpers/ptf_tests_helper.py index de6e8fbc5c8..ec28aa5d445 100644 --- a/tests/common/helpers/ptf_tests_helper.py +++ b/tests/common/helpers/ptf_tests_helper.py @@ -57,7 +57,7 @@ def upstream_links(rand_selected_dut, tbinfo, nbrhosts): duthost = rand_selected_dut def filter(interface, neighbor, mg_facts, tbinfo): - if ((tbinfo["topo"]["type"] == "t0" and "T1" in neighbor["name"]) + if ((tbinfo["topo"]["type"] == "t0" and ("T1" in neighbor["name"] or "PT0" in neighbor["name"])) or (tbinfo["topo"]["type"] == "t1" and "T2" in neighbor["name"])): for item in mg_facts["minigraph_bgp"]: if item["name"] == neighbor["name"]: diff --git a/tests/common/utilities.py b/tests/common/utilities.py index 01e34f87a63..766ecbc8930 100644 --- a/tests/common/utilities.py +++ b/tests/common/utilities.py @@ -32,7 +32,8 @@ from tests.common import constants from tests.common.cache import cached from tests.common.cache import FactsCache -from tests.common.helpers.constants import UPSTREAM_NEIGHBOR_MAP, DOWNSTREAM_NEIGHBOR_MAP +from tests.common.helpers.constants import UPSTREAM_NEIGHBOR_MAP, UPSTREAM_ALL_NEIGHBOR_MAP +from tests.common.helpers.constants import DOWNSTREAM_NEIGHBOR_MAP, DOWNSTREAM_ALL_NEIGHBOR_MAP from tests.common.helpers.assertions import pytest_assert from netaddr import valid_ipv6 @@ -878,6 +879,19 @@ def get_upstream_neigh_type(topo_type, is_upper=True): return None +def get_all_upstream_neigh_type(topo_type, is_upper=True): + """ + @summary: Get ALL upstream neighbor type by topo type + @param topo_type: topo type + @param is_upper: if is_upper is True, return uppercase str, else return lowercase str + @return a list + Sample output: ["ma", "mb"] + """ + if is_upper: + return [neigh.upper() for neigh in UPSTREAM_ALL_NEIGHBOR_MAP.get(topo_type, [])] + return UPSTREAM_ALL_NEIGHBOR_MAP.get(topo_type, []) + + def get_downstream_neigh_type(topo_type, is_upper=True): """ @summary: Get neighbor type by topo type @@ -892,6 +906,19 @@ def get_downstream_neigh_type(topo_type, is_upper=True): return None +def get_all_downstream_neigh_type(topo_type, is_upper=True): + """ + @summary: Get ALL downstream neighbor type by topo type + @param topo_type: topo type + @param is_upper: if is_upper is True, return uppercase str, else return lowercase str + @return a list + Sample output: ["m0", "c0"] + """ + if is_upper: + return [neigh.upper() for neigh in DOWNSTREAM_ALL_NEIGHBOR_MAP.get(topo_type, [])] + return DOWNSTREAM_ALL_NEIGHBOR_MAP.get(topo_type, []) + + def run_until(interval, delay, retry, condition, function, *args, **kwargs): """ @summary: Execute function until condition or retry number met.