Skip to content

Commit

Permalink
[test_gap] enable test copp on t0 (#4723)
Browse files Browse the repository at this point in the history
Approach
What is the motivation for this PR?
Enable test_copp on t0, eliminate test gap #4588

How did you do it?
Modify prepare logic to make it suitable to both t0 and t1 topologies.
Install another required package.
How did you verify/test it?
Run it on physical testbeds, including:

3 t0 testbeds with different platforms
1 t1 testbed to make sure it doesn't influence existing testbed
1 t1 backend testbed
All of them passed the test_policer and test_no_policer test functions,
but the new test function test_counter brought by #4456 raised errors due to the command mismatch of the bin file, it should be the issue of the new test case so we can ignore it for now.

Supported testbed topology if it's a new test case?
t0, t0-64, t0-52, t0-116

Co-authored-by: Jianquan Ye <jianquanye@microsoft.com>
  • Loading branch information
yejianquan authored Nov 19, 2021
1 parent 021206d commit f956a79
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
27 changes: 17 additions & 10 deletions tests/copp/copp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Refactor ptfadapter so it can be leveraged in these test cases.
"""
import re
import logging

DEFAULT_NN_TARGET_PORT = 3

Expand Down Expand Up @@ -93,26 +94,29 @@ def restore_policer(dut, nn_target_namespace):
else:
dut.command("cp {} {}".format(_BASE_COPP_TEMPLATE, _DEFAULT_COPP_TEMPLATE))

def configure_ptf(ptf, nn_target_port, nn_target_vlanid, is_backend_topology=False):

def configure_ptf(ptf, test_params, is_backend_topology=False):
"""
Configures the PTF to run the NN agent on the specified port.
Args:
ptf (PTFHost): The target PTF.
nn_target_port (int): The port to run NN agent on.
nn_target_vlanid (str): The vlan id of the port to run NN agent on.
is_backend_topology (bool): Whether it's a backend topology testbed
test_params (_COPPTestParameters): test parameters set.
is_backend_topology (bool): Whether it's a backend topology testbed.
"""

ptf.script(cmd=_REMOVE_IP_SCRIPT)
if is_backend_topology:
ptf.script(cmd=_ADD_IP_BACKEND_SCRIPT)
ip_command = "ip address add %s/31 dev \"eth%s.%s\"" % (test_params.myip, test_params.nn_target_port, test_params.nn_target_vlanid)
else:
ptf.script(cmd=_ADD_IP_SCRIPT)
ip_command = "ip address add %s/31 dev eth%s" % (test_params.myip, test_params.nn_target_port)

logging.debug("ip_command is: %s" % ip_command)
ptf.command(ip_command)

facts = {
"nn_target_port": nn_target_port,
"nn_target_vlanid": nn_target_vlanid
"nn_target_port": test_params.nn_target_port,
"nn_target_vlanid": test_params.nn_target_vlanid
}
ptf.host.options["variable_manager"].extra_vars.update(facts)
ptf.template(src=_PTF_NN_TEMPLATE, dest=_PTF_NN_DEST)
Expand All @@ -129,7 +133,10 @@ def restore_ptf(ptf):

ptf.script(cmd=_REMOVE_IP_SCRIPT)

facts = {"nn_target_port": DEFAULT_NN_TARGET_PORT}
facts = {
"nn_target_port": DEFAULT_NN_TARGET_PORT,
"nn_target_vlanid": None
}
ptf.host.options["variable_manager"].extra_vars.update(facts)

ptf.template(src=_PTF_NN_TEMPLATE, dest=_PTF_NN_DEST)
Expand Down Expand Up @@ -201,7 +208,7 @@ def _install_nano(dut, creds, syncd_docker_name):
cmd = '''docker exec -e http_proxy={} -e https_proxy={} {} bash -c " \
rm -rf /var/lib/apt/lists/* \
&& apt-get update \
&& apt-get install -y python-pip build-essential libssl-dev python-dev python-setuptools wget cmake \
&& apt-get install -y python-pip build-essential libssl-dev libffi-dev python-dev python-setuptools wget cmake \
&& wget https://github.com/nanomsg/nanomsg/archive/1.0.0.tar.gz \
&& tar xzf 1.0.0.tar.gz && cd nanomsg-1.0.0 \
&& mkdir -p build && cmake . && make install && ldconfig && cd .. && rm -rf nanomsg-1.0.0 \
Expand Down
9 changes: 6 additions & 3 deletions tests/copp/test_copp.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"send_rate_limit",
"nn_target_vlanid"])
_SUPPORTED_PTF_TOPOS = ["ptf32", "ptf64"]
_SUPPORTED_T0_TOPOS = ["t0", "t0-64", "t0-52", "t0-116"]
_SUPPORTED_T1_TOPOS = ["t1", "t1-lag", "t1-64-lag", "t1-backend"]
_SUPPORTED_T2_TOPOS = ["t2"]
_TOR_ONLY_PROTOCOL = ["DHCP"]
Expand Down Expand Up @@ -176,7 +177,7 @@ def copp_testbed(
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
test_params = _gather_test_params(tbinfo, duthost, request)

if test_params.topo not in (_SUPPORTED_PTF_TOPOS + _SUPPORTED_T1_TOPOS + _SUPPORTED_T2_TOPOS):
if test_params.topo not in (_SUPPORTED_PTF_TOPOS + _SUPPORTED_T0_TOPOS + _SUPPORTED_T1_TOPOS + _SUPPORTED_T2_TOPOS):
pytest.skip("Topology not supported by COPP tests")

try:
Expand Down Expand Up @@ -263,11 +264,13 @@ def _gather_test_params(tbinfo, duthost, request):
topo = tbinfo["topo"]["name"]
mg_facts = duthost.get_extended_minigraph_facts(tbinfo)
is_backend_topology = mg_facts.get(constants.IS_BACKEND_TOPOLOGY_KEY, False)
# filter out server peer port and only bgp peer ports remain, to support T0 topologies
bgp_peer_name_set = set([bgp_peer["name"] for bgp_peer in mg_facts["minigraph_bgp"]])
# get the port_index_map using the ptf_indicies to support multi DUT topologies
port_index_map = {
k: v
for k, v in mg_facts["minigraph_ptf_indices"].items()
if k in mg_facts["minigraph_ports"]
if k in mg_facts["minigraph_ports"] and mg_facts["minigraph_neighbors"][k]["name"] in bgp_peer_name_set
}
# use randam sonic interface for testing
nn_target_interface = random.choice(port_index_map.keys())
Expand Down Expand Up @@ -309,7 +312,7 @@ def _setup_testbed(dut, creds, ptf, test_params, tbinfo):
is_backend_topology = mg_facts.get(constants.IS_BACKEND_TOPOLOGY_KEY, False)

logging.info("Set up the PTF for COPP tests")
copp_utils.configure_ptf(ptf, test_params.nn_target_port, test_params.nn_target_vlanid, is_backend_topology)
copp_utils.configure_ptf(ptf, test_params, is_backend_topology)

logging.info("Update the rate limit for the COPP policer")
copp_utils.limit_policer(dut, _TEST_RATE_LIMIT, test_params.nn_target_namespace)
Expand Down

0 comments on commit f956a79

Please sign in to comment.