From 523012e3700e5851f50f9237feba45cb6e5c5c98 Mon Sep 17 00:00:00 2001 From: Jianquan Ye Date: Thu, 18 Nov 2021 10:11:46 +0800 Subject: [PATCH] [test_gap] enable test copp on t0 --- tests/copp/copp_utils.py | 27 +++++++++++++++++---------- tests/copp/test_copp.py | 9 ++++++--- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/tests/copp/copp_utils.py b/tests/copp/copp_utils.py index e1699089b09..ede5d5cd1a6 100644 --- a/tests/copp/copp_utils.py +++ b/tests/copp/copp_utils.py @@ -5,6 +5,7 @@ Refactor ptfadapter so it can be leveraged in these test cases. """ import re +import logging DEFAULT_NN_TARGET_PORT = 3 @@ -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) @@ -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) @@ -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 \ diff --git a/tests/copp/test_copp.py b/tests/copp/test_copp.py index 47a42731d2b..529aad02947 100644 --- a/tests/copp/test_copp.py +++ b/tests/copp/test_copp.py @@ -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"] @@ -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: @@ -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()) @@ -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)