Skip to content

Commit 0b0d88a

Browse files
committed
Fixes
Signed-off-by: Abhishek Dosi <[email protected]>
1 parent a090893 commit 0b0d88a

3 files changed

Lines changed: 43 additions & 35 deletions

File tree

tests/common/devices/multi_asic.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ def asic_instance(self, asic_index):
129129
return self.asics[0]
130130
return self.asics[asic_index]
131131

132+
def asic_instance_from_namespace(self, namespace=DEFAULT_NAMESPACE):
133+
if not namespace:
134+
return self.asics[0]
135+
136+
for asic in self.asics:
137+
if asic.namespace == namespace:
138+
return asic
139+
return None
140+
132141
def get_asic_ids(self):
133142
if self.sonichost.facts['num_asic'] == 1:
134143
return [DEFAULT_ASIC_ID]
@@ -209,16 +218,6 @@ def get_asic_or_sonic_host(self, asic_id):
209218
return self.sonichost
210219
return self.asics[asic_id]
211220

212-
def get_asic_from_namespace(self, namespace=DEFAULT_NAMESPACE):
213-
if not namespace:
214-
return self.sonichost
215-
216-
for asic in self.asics:
217-
if asic.namespace == namespace:
218-
return asic
219-
220-
return None
221-
222221
def stop_service(self, service):
223222
if service in self._DEFAULT_SERVICES:
224223
return self.sonichost.stop_service(service, service)

tests/copp/copp_utils.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def limit_policer(dut, pps_limit, nn_target_namespace):
3838
pps_limit (int): The rate limit for COPP to enforce on ALL trap groups.
3939
"""
4040

41-
asichost = dut.get_asic_from_namespace(nn_target_namespace)
41+
asichost = dut.asic_instance_from_namespace(nn_target_namespace)
4242

4343
swss_docker_name = asichost.get_docker_name("swss")
4444

@@ -77,7 +77,7 @@ def restore_policer(dut, nn_target_namespace):
7777
7878
The SWSS container must be restarted for the config change to take effect.
7979
"""
80-
asichost = dut.get_asic_from_namespace(nn_target_namespace)
80+
asichost = dut.asic_instance_from_namespace(nn_target_namespace)
8181

8282
swss_docker_name = asichost.get_docker_name("swss")
8383

@@ -142,7 +142,7 @@ def configure_syncd(dut, nn_target_port, nn_target_interface, nn_target_namespac
142142
facts = {"nn_target_port": nn_target_port, "nn_target_interface": nn_target_interface}
143143
dut.host.options["variable_manager"].extra_vars.update(facts)
144144

145-
asichost = dut.get_asic_from_namespace(nn_target_namespace)
145+
asichost = dut.asic_instance_from_namespace(nn_target_namespace)
146146

147147
syncd_docker_name = asichost.get_docker_name("syncd")
148148

@@ -156,7 +156,7 @@ def configure_syncd(dut, nn_target_port, nn_target_interface, nn_target_namespac
156156
dut.command("docker exec {} supervisorctl update".format(syncd_docker_name))
157157

158158
def restore_syncd(dut, nn_target_namespace):
159-
asichost = dut.get_asic_from_namespace(nn_target_namespace)
159+
asichost = dut.asic_instance_from_namespace(nn_target_namespace)
160160

161161
syncd_docker_name = asichost.get_docker_name("syncd")
162162

@@ -200,3 +200,14 @@ def _map_port_number_to_interface(dut, nn_target_port):
200200

201201
interfaces = dut.command("portstat")["stdout_lines"][2:]
202202
return interfaces[nn_target_port].split()[0]
203+
204+
def _get_http_and_https_proxy_ip(creds):
205+
"""
206+
Get the http and https proxy ip.
207+
208+
Args:
209+
creds (dict): Credential information according to the dut inventory
210+
"""
211+
212+
return (re.findall(r'[0-9]+(?:\.[0-9]+){3}', creds.get('proxy_env', {}).get('http_proxy', ''))[0],
213+
re.findall(r'[0-9]+(?:\.[0-9]+){3}', creds.get('proxy_env', {}).get('https_proxy', ''))[0])

tests/copp/test_copp.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ def copp_testbed(
126126
pytest.skip("Topology not supported by COPP tests")
127127

128128
try:
129-
_setup_testbed(duthost, creds, ptfhost, test_params)
129+
_setup_testbed(duthost, creds, ptfhost, test_params, tbinfo)
130130
yield test_params
131131
finally:
132-
_teardown_testbed(duthost, creds, ptfhost, test_params)
132+
_teardown_testbed(duthost, creds, ptfhost, test_params, tbinfo)
133133

134134
@pytest.fixture(autouse=True)
135135
def ignore_expected_loganalyzer_exceptions(rand_one_dut_hostname, loganalyzer):
@@ -144,10 +144,6 @@ def ignore_expected_loganalyzer_exceptions(rand_one_dut_hostname, loganalyzer):
144144
loganalyzer: Loganalyzer utility fixture
145145
"""
146146
ignoreRegex = [
147-
".*ERR monit.*'lldpd_monitor' process is not running.*",
148-
".*ERR monit.* 'lldp\|lldpd_monitor' status failed.*-- 'lldpd:' is not running.*",
149-
".*ERR monit.*'lldp_syncd' process is not running.*",
150-
".*ERR monit.*'lldp\|lldp_syncd' status failed.*'python2 -m lldp_syncd' is not running.*",
151147
".*snmp#snmp-subagent.*",
152148
".*kernel reports TIME_ERROR: 0x4041: Clock Unsynchronized.*"
153149
]
@@ -208,33 +204,37 @@ def _gather_test_params(tbinfo, duthost, request):
208204
peerip = bgp_peer["peer_addr"]
209205
break
210206

211-
logging.info("nn_target_port {} nn_target_interface {}".format(nn_target_port, nn_target_interface))
207+
nn_target_namespace = mg_facts["minigraph_neighbors"][nn_target_interface]['namespace']
208+
209+
logging.info("nn_target_port {} nn_target_interface {} nn_target_namespace {}".format(nn_target_port, nn_target_interface, nn_target_namespace))
212210

213211
return _COPPTestParameters(nn_target_port=nn_target_port,
214212
swap_syncd=swap_syncd,
215213
topo=topo,
216214
myip=myip,
217215
peerip = peerip,
218216
nn_target_interface=nn_target_interface,
219-
nn_target_namespace=mg_facts["minigraph_neighbors"][nn_target_interface]['namespace'])
217+
nn_target_namespace=nn_target_namespace)
220218

221-
def _setup_testbed(dut, creds, ptf, test_params):
219+
def _setup_testbed(dut, creds, ptf, test_params, tbinfo):
222220
"""
223221
Sets up the testbed to run the COPP tests.
224222
"""
225223
if dut.is_multi_asic:
226224
logging.info("Adding iptables rules and enabling eth0 port forwarding")
225+
http_proxy, https_proxy = copp_utils._get_http_and_https_proxy_ip(creds)
227226
# IP Table rule for http and ptf nn_agent traffic.
228227
dut.command("sudo sysctl net.ipv4.conf.eth0.forwarding=1")
229228
mgmt_ip = dut.host.options["inventory_manager"].get_host(dut.hostname).vars["ansible_host"]
229+
# Rule to communicate to http/s proxy from namespace
230230
dut.command("sudo iptables -t nat -A POSTROUTING -p tcp --dport 8080 -j SNAT --to-source {}".format(mgmt_ip))
231-
ip_ifs = dut.show_ip_interface(namespace = test_params.nn_target_namespace)["ansible_facts"]
232-
dut.command("sudo iptables -t nat -A PREROUTING -p tcp --dport 10900 -j DNAT --to-destination {}".format(ip_ifs["ip_interfaces"]["eth0"]["ipv4"]))
233-
http_proxy = re.findall(r'[0-9]+(?:\.[0-9]+){3}', creds.get('proxy_env', {}).get('http_proxy', ''))[0]
234-
https_proxy = re.findall(r'[0-9]+(?:\.[0-9]+){3}', creds.get('proxy_env', {}).get('https_proxy', ''))[0]
235231
dut.command("sudo ip -n {} rule add from all to {} pref 1 lookup default".format(test_params.nn_target_namespace, http_proxy))
236232
if http_proxy != https_proxy:
237233
dut.command("sudo ip -n {} rule add from all to {} pref 2 lookup default".format(test_params.nn_target_namespace, https_proxy))
234+
# Rule to communicate to ptf nn agent client from namespace
235+
ns_ip = dut.shell("sudo ip -n {} -4 -o addr show eth0".format(test_params.nn_target_namespace) + " | awk '{print $4}' | cut -d'/' -f1")["stdout"]
236+
dut.command("sudo iptables -t nat -A PREROUTING -p tcp --dport 10900 -j DNAT --to-destination {}".format(ns_ip))
237+
dut.command("sudo ip -n {} rule add from {} to {} pref 3 lookup default".format(test_params.nn_target_namespace, ns_ip, tbinfo["ptf_ip"]))
238238

239239

240240

@@ -258,33 +258,31 @@ def _setup_testbed(dut, creds, ptf, test_params):
258258
# NOTE: Even if the rpc syncd image is already installed, we need to restart
259259
# SWSS for the COPP changes to take effect.
260260
logging.info("Reloading config and restarting swss...")
261-
config_reload(dut, wait=180)
261+
config_reload(dut)
262262

263263
logging.info("Configure syncd RPC for testing")
264264
copp_utils.configure_syncd(dut, test_params.nn_target_port, test_params.nn_target_interface,
265265
test_params.nn_target_namespace, creds)
266266

267-
def _teardown_testbed(dut, creds, ptf, test_params):
267+
def _teardown_testbed(dut, creds, ptf, test_params, tbinfo):
268268
"""
269269
Tears down the testbed, returning it to its initial state.
270270
"""
271271
if dut.is_multi_asic:
272272
logging.info("Removing iptables rules and disabling eth0 port forwarding")
273+
http_proxy, https_proxy = copp_utils._get_http_and_https_proxy_ip(creds)
273274

274275
dut.command("sudo sysctl net.ipv4.conf.eth0.forwarding=0")
275276

276277
mgmt_ip = dut.host.options["inventory_manager"].get_host(dut.hostname).vars["ansible_host"]
277278
dut.command("sudo iptables -t nat -D POSTROUTING -p tcp --dport 8080 -j SNAT --to-source {}".format(mgmt_ip))
278-
279-
ip_ifs = dut.show_ip_interface(namespace = test_params.nn_target_namespace)["ansible_facts"]
280-
dut.command("sudo iptables -t nat -D PREROUTING -p tcp --dport 10900 -j DNAT --to-destination {}".format(ip_ifs["ip_interfaces"]["eth0"]["ipv4"]))
281-
http_proxy = re.findall(r'[0-9]+(?:\.[0-9]+){3}', creds.get('proxy_env', {}).get('http_proxy', ''))[0]
282-
https_proxy = re.findall(r'[0-9]+(?:\.[0-9]+){3}', creds.get('proxy_env', {}).get('https_proxy', ''))[0]
283279
dut.command("sudo ip -n {} rule delete from all to {} pref 1 lookup default".format(test_params.nn_target_namespace, http_proxy))
284280
if http_proxy != https_proxy:
285281
dut.command("sudo ip -n {} rule delete from all to {} pref 2 lookup default".format(test_params.nn_target_namespace, https_proxy))
286282

287-
283+
ns_ip = dut.shell("sudo ip -n {} -4 -o addr show eth0".format(test_params.nn_target_namespace) + " | awk '{print $4}' | cut -d'/' -f1")["stdout"]
284+
dut.command("sudo iptables -t nat -D PREROUTING -p tcp --dport 10900 -j DNAT --to-destination {}".format(ns_ip))
285+
dut.command("sudo ip -n {} rule delete from {} to {} pref 3 lookup default".format(test_params.nn_target_namespace, ns_ip, tbinfo["ptf_ip"]))
288286

289287
logging.info("Restore PTF post COPP test")
290288
copp_utils.restore_ptf(ptf)

0 commit comments

Comments
 (0)