Skip to content

Commit 34bb044

Browse files
yejianquanAntonHryshchuk
authored andcommitted
[test_gap] enable test copp on t0 (sonic-net#4723)
Approach What is the motivation for this PR? Enable test_copp on t0, eliminate test gap sonic-net#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 sonic-net#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 <[email protected]>
1 parent 7714af2 commit 34bb044

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

tests/copp/copp_utils.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Refactor ptfadapter so it can be leveraged in these test cases.
66
"""
77
import re
8+
import logging
89

910
DEFAULT_NN_TARGET_PORT = 3
1011

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

96-
def configure_ptf(ptf, nn_target_port, nn_target_vlanid, is_backend_topology=False):
97+
98+
def configure_ptf(ptf, test_params, is_backend_topology=False):
9799
"""
98100
Configures the PTF to run the NN agent on the specified port.
99101
100102
Args:
101103
ptf (PTFHost): The target PTF.
102-
nn_target_port (int): The port to run NN agent on.
103-
nn_target_vlanid (str): The vlan id of the port to run NN agent on.
104-
is_backend_topology (bool): Whether it's a backend topology testbed
104+
test_params (_COPPTestParameters): test parameters set.
105+
is_backend_topology (bool): Whether it's a backend topology testbed.
105106
"""
106107

107108
ptf.script(cmd=_REMOVE_IP_SCRIPT)
108109
if is_backend_topology:
109-
ptf.script(cmd=_ADD_IP_BACKEND_SCRIPT)
110+
ip_command = "ip address add %s/31 dev \"eth%s.%s\"" % (test_params.myip, test_params.nn_target_port, test_params.nn_target_vlanid)
110111
else:
111-
ptf.script(cmd=_ADD_IP_SCRIPT)
112+
ip_command = "ip address add %s/31 dev eth%s" % (test_params.myip, test_params.nn_target_port)
113+
114+
logging.debug("ip_command is: %s" % ip_command)
115+
ptf.command(ip_command)
112116

113117
facts = {
114-
"nn_target_port": nn_target_port,
115-
"nn_target_vlanid": nn_target_vlanid
118+
"nn_target_port": test_params.nn_target_port,
119+
"nn_target_vlanid": test_params.nn_target_vlanid
116120
}
117121
ptf.host.options["variable_manager"].extra_vars.update(facts)
118122
ptf.template(src=_PTF_NN_TEMPLATE, dest=_PTF_NN_DEST)
@@ -129,7 +133,10 @@ def restore_ptf(ptf):
129133

130134
ptf.script(cmd=_REMOVE_IP_SCRIPT)
131135

132-
facts = {"nn_target_port": DEFAULT_NN_TARGET_PORT}
136+
facts = {
137+
"nn_target_port": DEFAULT_NN_TARGET_PORT,
138+
"nn_target_vlanid": None
139+
}
133140
ptf.host.options["variable_manager"].extra_vars.update(facts)
134141

135142
ptf.template(src=_PTF_NN_TEMPLATE, dest=_PTF_NN_DEST)
@@ -201,7 +208,7 @@ def _install_nano(dut, creds, syncd_docker_name):
201208
cmd = '''docker exec -e http_proxy={} -e https_proxy={} {} bash -c " \
202209
rm -rf /var/lib/apt/lists/* \
203210
&& apt-get update \
204-
&& apt-get install -y python-pip build-essential libssl-dev python-dev python-setuptools wget cmake \
211+
&& apt-get install -y python-pip build-essential libssl-dev libffi-dev python-dev python-setuptools wget cmake \
205212
&& wget https://github.com/nanomsg/nanomsg/archive/1.0.0.tar.gz \
206213
&& tar xzf 1.0.0.tar.gz && cd nanomsg-1.0.0 \
207214
&& mkdir -p build && cmake . && make install && ldconfig && cd .. && rm -rf nanomsg-1.0.0 \

tests/copp/test_copp.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"send_rate_limit",
5454
"nn_target_vlanid"])
5555
_SUPPORTED_PTF_TOPOS = ["ptf32", "ptf64"]
56+
_SUPPORTED_T0_TOPOS = ["t0", "t0-64", "t0-52", "t0-116"]
5657
_SUPPORTED_T1_TOPOS = ["t1", "t1-lag", "t1-64-lag", "t1-backend"]
5758
_SUPPORTED_T2_TOPOS = ["t2"]
5859
_TOR_ONLY_PROTOCOL = ["DHCP"]
@@ -176,7 +177,7 @@ def copp_testbed(
176177
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
177178
test_params = _gather_test_params(tbinfo, duthost, request)
178179

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

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

311314
logging.info("Set up the PTF for COPP tests")
312-
copp_utils.configure_ptf(ptf, test_params.nn_target_port, test_params.nn_target_vlanid, is_backend_topology)
315+
copp_utils.configure_ptf(ptf, test_params, is_backend_topology)
313316

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

0 commit comments

Comments
 (0)