Skip to content

Commit 9c8ad51

Browse files
authored
[copp] Fix COPP test failures and make clean-up more robust (#1904)
- Add minig_bgp var introduced by 1171 - Disable loganalyzer for LLDP messages - Updates default swap_syncd behavior to match qos_sai - Remove docker images after test Signed-off-by: Danny Allen <[email protected]>
1 parent 6ef53cb commit 9c8ad51

4 files changed

Lines changed: 68 additions & 39 deletions

File tree

tests/common/system_utils/docker.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,8 @@ def restore_default_syncd(dut):
202202

203203
_LOGGER.info("swss has been restarted, waiting 60 seconds to initialize...")
204204
time.sleep(60)
205+
206+
# Remove the RPC image from the DUT
207+
docker_rpc_image = docker_syncd_name + "-rpc"
208+
registry = load_docker_registry_info(dut)
209+
dut.command("docker rmi {}/{}:{}".format(registry.host, docker_rpc_image, sonic_version))

tests/copp/conftest.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ def pytest_addoption(parser):
2424
)
2525

2626
parser.addoption(
27-
"--swap_syncd",
28-
action="store_true",
29-
default=False,
30-
help="Install syncd RPC image for this test case"
27+
"--copp_swap_syncd",
28+
action="store",
29+
type=bool,
30+
default=True,
31+
help="Swap syncd container with syncd-rpc container",
3132
)

tests/copp/copp_utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ def configure_ptf(ptf, nn_target_port):
5858
nn_target_port (int): The port to run NN agent on.
5959
"""
6060

61+
ptf.script(cmd=_REMOVE_IP_SCRIPT)
6162
ptf.script(cmd=_ADD_IP_SCRIPT)
6263

6364
facts = {"nn_target_port": nn_target_port}
64-
ptf.host.options['variable_manager'].extra_vars.update(facts)
65+
ptf.host.options["variable_manager"].extra_vars.update(facts)
6566
ptf.template(src=_PTF_NN_TEMPLATE, dest=_PTF_NN_DEST)
6667

6768
ptf.supervisorctl(name="ptf_nn_agent", state="restarted")
@@ -77,7 +78,7 @@ def restore_ptf(ptf):
7778
ptf.script(cmd=_REMOVE_IP_SCRIPT)
7879

7980
facts = {"nn_target_port": DEFAULT_NN_TARGET_PORT}
80-
ptf.host.options['variable_manager'].extra_vars.update(facts)
81+
ptf.host.options["variable_manager"].extra_vars.update(facts)
8182

8283
ptf.template(src=_PTF_NN_TEMPLATE, dest=_PTF_NN_DEST)
8384

@@ -98,7 +99,7 @@ def configure_syncd(dut, nn_target_port):
9899

99100
facts = {"nn_target_port": nn_target_port,
100101
"nn_target_interface": _map_port_number_to_interface(dut, nn_target_port)}
101-
dut.host.options['variable_manager'].extra_vars.update(facts)
102+
dut.host.options["variable_manager"].extra_vars.update(facts)
102103

103104
dut.template(src=_SYNCD_NN_TEMPLATE, dest=_SYNCD_NN_DEST)
104105
dut.command("docker cp {} syncd:/etc/supervisor/conf.d/".format(_SYNCD_NN_DEST))

tests/copp/test_copp.py

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,33 @@
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
2930
import time
3031
import pytest
3132
from 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]
3534
from tests.copp import copp_utils
3635
from tests.ptf_runner import ptf_runner
3736
from 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

4042
pytestmark = [
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+
118127
def _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

159171
def _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

181198
def _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

Comments
 (0)