2222 --pkt_tx_count <n> (int): How many packets to send during each individual test case.
2323 Default is 100000.
2424
25- --swap_syncd : Used to install the RPC syncd image before running the tests. Default
26- is disabled .
25+ --copp_swap_syncd : Used to install the RPC syncd image before running the tests. Default
26+ is enabled .
2727"""
2828
29+ import logging
2930import time
3031import pytest
3132from collections import namedtuple
3233
33- from tests .common .fixtures .ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import]
34- from tests .common .fixtures .ptfhost_utils import change_mac_addresses # lgtm[py/unused-import]
3534from tests .copp import copp_utils
3635from tests .ptf_runner import ptf_runner
3736from tests .common .system_utils import docker
38- from tests .common .broadcom_data import is_broadcom_device
37+
38+ # Module-level fixtures
39+ from tests .common .fixtures .ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import]
40+ from tests .common .fixtures .ptfhost_utils import change_mac_addresses # lgtm[py/unused-import]
3941
4042pytestmark = [
41- pytest .mark .topology ('t1' )
43+ pytest .mark .topology ("t1" )
4244]
4345
4446_COPPTestParameters = namedtuple ("_COPPTestParameters" ,
4547 ["nn_target_port" ,
4648 "pkt_tx_count" ,
4749 "swap_syncd" ,
48- "topo" ])
50+ "topo" ,
51+ "bgp_graph" ])
4952_SUPPORTED_TOPOS = ["ptf32" , "ptf64" , "t1" , "t1-lag" ]
5053_TEST_RATE_LIMIT = 600
5154
@@ -58,55 +61,41 @@ class TestCOPP(object):
5861 "IP2ME" ,
5962 "SNMP" ,
6063 "SSH" ])
61- def test_policer (self , protocol , duthost , ptfhost , _copp_testbed ):
64+ def test_policer (self , protocol , duthost , ptfhost , copp_testbed ):
6265 """
6366 Validates that rate-limited COPP groups work as expected.
6467
6568 Checks that the policer enforces the rate limit for protocols
6669 that have a set rate limit.
6770 """
68-
69- if protocol == "ARP" \
70- and is_broadcom_device (duthost ) \
71- and "201811" not in duthost .os_version :
72- pytest .xfail ("ARP policy disabled on BRCM devices due to SAI bug" )
73-
74- if protocol in ["IP2ME" , "SNMP" , "SSH" ] and _copp_testbed .topo == "t1-lag" :
75- pytest .xfail ("Packets not received due to faulty DIP, see #1171" )
76-
7771 _copp_runner (duthost ,
7872 ptfhost ,
7973 protocol ,
80- _copp_testbed )
74+ copp_testbed )
8175
8276 @pytest .mark .parametrize ("protocol" , ["BGP" ,
8377 "DHCP" ,
8478 "LACP" ,
8579 "LLDP" ,
8680 "UDLD" ])
87- def test_no_policer (self , protocol , duthost , ptfhost , _copp_testbed ):
81+ def test_no_policer (self , protocol , duthost , ptfhost , copp_testbed ):
8882 """
8983 Validates that non-rate-limited COPP groups work as expected.
9084
9185 Checks that the policer does not enforce a rate limit for protocols
9286 that do not have any set rate limit.
9387 """
94-
95- if protocol == "BGP" and _copp_testbed .topo == "t1-lag" :
96- pytest .xfail ("Packets not received due to faulty DIP, see #1171" )
97-
9888 _copp_runner (duthost ,
9989 ptfhost ,
10090 protocol ,
101- _copp_testbed )
91+ copp_testbed )
10292
10393@pytest .fixture (scope = "class" )
104- def _copp_testbed (duthost , ptfhost , testbed , request ):
94+ def copp_testbed (duthost , ptfhost , testbed , request ):
10595 """
10696 Pytest fixture to handle setup and cleanup for the COPP tests.
10797 """
108-
109- test_params = _gather_test_params (testbed , request )
98+ test_params = _gather_test_params (testbed , duthost , request )
11099
111100 if test_params .topo not in _SUPPORTED_TOPOS :
112101 pytest .skip ("Topology not supported by COPP tests" )
@@ -115,14 +104,35 @@ def _copp_testbed(duthost, ptfhost, testbed, request):
115104 yield test_params
116105 _teardown_testbed (duthost , ptfhost , test_params )
117106
107+ @pytest .fixture (autouse = True )
108+ def ignore_expected_loganalyzer_exceptions (self , duthost , loganalyzer ):
109+ """
110+ Ignore expected failures logs during test execution.
111+
112+ We disable LLDP during the test, so we expect to see "lldp not running"
113+ messages in the logs. All other errors should be treated as errors.
114+
115+ Args:
116+ duthost: DUT fixture
117+ loganalyzer: Loganalyzer utility fixture
118+ """
119+ ignoreRegex = [
120+ ".*ERR monit.*'lldpd_monitor' process is not running" ,
121+ ".*ERR monit.*'lldp_syncd' process is not running" ,
122+ ]
123+ loganalyzer .ignore_regex .extend (ignoreRegex )
124+
125+ yield
126+
118127def _copp_runner (dut , ptf , protocol , test_params ):
119128 """
120129 Configures and runs the PTF test cases.
121130 """
122131
123132 params = {"verbose" : False ,
124133 "pkt_tx_count" : test_params .pkt_tx_count ,
125- "target_port" : test_params .nn_target_port }
134+ "target_port" : test_params .nn_target_port ,
135+ "minig_bgp" : test_params .bgp_graph }
126136
127137 dut_ip = dut .setup ()["ansible_facts" ]["ansible_eth0" ]["ipv4" ]["address" ]
128138 device_sockets = ["0-{}@tcp://127.0.0.1:10900" .format (test_params .nn_target_port ),
@@ -141,57 +151,69 @@ def _copp_runner(dut, ptf, protocol, test_params):
141151 debug_level = None ,
142152 device_sockets = device_sockets )
143153
144- def _gather_test_params (testbed , request ):
154+ def _gather_test_params (testbed , duthost , request ):
145155 """
146156 Fetches the test parameters from pytest.
147157 """
148158
149159 nn_target_port = request .config .getoption ("--nn_target_port" )
150160 pkt_tx_count = request .config .getoption ("--pkt_tx_count" )
151- swap_syncd = request .config .getoption ("--swap_syncd " )
161+ swap_syncd = request .config .getoption ("--copp_swap_syncd " )
152162 topo = testbed ["topo" ]["name" ]
163+ bgp_graph = duthost .minigraph_facts (host = duthost .hostname )["ansible_facts" ]["minigraph_bgp" ]
153164
154165 return _COPPTestParameters (nn_target_port = nn_target_port ,
155166 pkt_tx_count = pkt_tx_count ,
156167 swap_syncd = swap_syncd ,
157- topo = topo )
168+ topo = topo ,
169+ bgp_graph = bgp_graph )
158170
159171def _setup_testbed (dut , ptf , test_params ):
160172 """
161173 Sets up the testbed to run the COPP tests.
162174 """
163175
164- # We don't want LLDP to throw off our test results, so we disable it first.
176+ logging . info ( "Disable LLDP for COPP tests" )
165177 dut .command ("docker exec lldp supervisorctl stop lldp-syncd" )
166178 dut .command ("docker exec lldp supervisorctl stop lldpd" )
167179
180+ logging .info ("Set up the PTF for COPP tests" )
168181 copp_utils .configure_ptf (ptf , test_params .nn_target_port )
169182
183+ logging .info ("Update the rate limit for the COPP policer" )
170184 copp_utils .limit_policer (dut , _TEST_RATE_LIMIT )
171185
172186 if test_params .swap_syncd :
187+ logging .info ("Swap out syncd to use RPC image..." )
173188 docker .swap_syncd (dut )
174189 else :
175190 # NOTE: Even if the rpc syncd image is already installed, we need to restart
176191 # SWSS for the COPP changes to take effect.
192+ logging .info ("Restart SWSS..." )
177193 _restart_swss (dut )
178194
195+ logging .info ("Configure syncd RPC for testing" )
179196 copp_utils .configure_syncd (dut , test_params .nn_target_port )
180197
181198def _teardown_testbed (dut , ptf , test_params ):
182199 """
183200 Tears down the testbed, returning it to its initial state.
184201 """
185202
203+ logging .info ("Restore PTF post COPP test" )
186204 copp_utils .restore_ptf (ptf )
187205
206+ logging .info ("Restore COPP policer to default settings" )
188207 copp_utils .restore_policer (dut )
189208
190209 if test_params .swap_syncd :
210+ logging .info ("Restore default syncd docker..." )
191211 docker .restore_default_syncd (dut )
192212 else :
213+ logging .info ("Restart SWSS..." )
193214 _restart_swss (dut )
194215
216+ logging .info ("Restore LLDP" )
195217 dut .command ("docker exec lldp supervisorctl start lldpd" )
196218 dut .command ("docker exec lldp supervisorctl start lldp-syncd" )
197219
0 commit comments