Skip to content

Commit

Permalink
sonic-mgmt: Fix namespace issues for qos tests on T2 single ASIC
Browse files Browse the repository at this point in the history
We are seeing UnboundLocalError when running sonic-mgmt tests against
a single-ASIC linecard:

```
UnboundLocalError: local variable 'dst_sys_port_id' referenced before assignment
```

Upon further investigation, this was determined to be happening
because a previous attempt to fix this issue (PR #13700) completely
omitted the ASIC prefix, but the entries in SYSTEM_PORT in config_db
do have an Asic0 prefix even on a single ASIC DUT.

Resolve this by specifically adding the Asic0 prefix in the case of a
single-ASIC T2 DUT, instead of leaving the prefix out.

Tested by manually running qos tests on a T2 single ASIC DUT with
these changes.
  • Loading branch information
patrickmacarthur committed Nov 22, 2024
1 parent 1b4b3a9 commit 2e9c5ce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
11 changes: 7 additions & 4 deletions tests/qos/qos_sai_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,7 @@ def dutConfig(
dutPortIps[src_dut_index][src_asic_index] = {}
sysPortMap[src_dut_index][src_asic_index] = {}
active_ips = src_asic.get_active_ip_interfaces(tbinfo)
src_namespace_prefix = src_asic.namespace + '|' if src_asic.namespace else f'Asic{src_asic.asic_index}|'
for iface, addr in active_ips.items():
if iface.startswith("Ethernet") and ("Ethernet-Rec" not in iface):
portIndex = src_mgFacts["minigraph_ptf_indices"][iface]
Expand All @@ -1091,7 +1092,7 @@ def dutConfig(
# Map port IDs to system port for dnx chassis
if 'platform_asic' in get_src_dst_asic_and_duts["src_dut"].facts and \
get_src_dst_asic_and_duts["src_dut"].facts['platform_asic'] == 'broadcom-dnx':
sys_key = src_asic.namespace + '|' + iface if src_asic.namespace else iface
sys_key = src_namespace_prefix + iface
if sys_key in src_system_port:
system_port = src_system_port[sys_key]['system_port_id']
sysPort = {'port': iface, 'system_port': system_port, 'port_type': iface}
Expand All @@ -1108,7 +1109,7 @@ def dutConfig(
if 'platform_asic' in get_src_dst_asic_and_duts["src_dut"].facts and \
get_src_dst_asic_and_duts["src_dut"].facts['platform_asic'] == 'broadcom-dnx':
for portName in src_mgFacts["minigraph_portchannels"][iface]["members"]:
sys_key = src_asic.namespace + '|' + portName if src_asic.namespace else portName
sys_key = src_namespace_prefix + portName
port_Index = src_mgFacts["minigraph_ptf_indices"][portName]
if sys_key in src_system_port:
system_port = src_system_port[sys_key]['system_port_id']
Expand All @@ -1126,6 +1127,7 @@ def dutConfig(
dutPortIps[dst_dut_index] = {}
testPortIds[dst_dut_index] = {}
sysPortMap[dst_dut_index] = {}
dst_system_port = {}
if 'platform_asic' in get_src_dst_asic_and_duts["src_dut"].facts and \
get_src_dst_asic_and_duts["src_dut"].facts['platform_asic'] == 'broadcom-dnx':
dst_system_port = dst_dut.config_facts(host=dst_dut.hostname, source='running')[
Expand All @@ -1135,6 +1137,7 @@ def dutConfig(
dst_system_port = src_system_port
dutPortIps[dst_dut_index][dst_asic_index] = {}
sysPortMap[dst_dut_index][dst_asic_index] = {}
dst_namespace_prefix = dst_asic.namespace + '|' if dst_asic.namespace else f'Asic{dst_asic.asic_index}|'
active_ips = dst_asic.get_active_ip_interfaces(tbinfo)
for iface, addr in active_ips.items():
if iface.startswith("Ethernet") and ("Ethernet-Rec" not in iface):
Expand All @@ -1144,7 +1147,7 @@ def dutConfig(
# Map port IDs to system port IDs
if 'platform_asic' in get_src_dst_asic_and_duts["src_dut"].facts and \
get_src_dst_asic_and_duts["src_dut"].facts['platform_asic'] == 'broadcom-dnx':
sys_key = dst_asic.namespace + '|' + iface if dst_asic.namespace else iface
sys_key = dst_namespace_prefix + iface
if sys_key in dst_system_port:
system_port = dst_system_port[sys_key]['system_port_id']
sysPort = {'port': iface, 'system_port': system_port, 'port_type': iface}
Expand All @@ -1161,7 +1164,7 @@ def dutConfig(
if 'platform_asic' in get_src_dst_asic_and_duts["src_dut"].facts and \
get_src_dst_asic_and_duts["src_dut"].facts['platform_asic'] == 'broadcom-dnx':
for portName in dst_mgFacts["minigraph_portchannels"][iface]["members"]:
sys_key = dst_asic.namespace + '|' + portName if dst_asic.namespace else portName
sys_key = dst_namespace_prefix + portName
port_Index = dst_mgFacts["minigraph_ptf_indices"][portName]
if sys_key in dst_system_port:
system_port = dst_system_port[sys_key]['system_port_id']
Expand Down
7 changes: 3 additions & 4 deletions tests/saitests/py3/sai_qos_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3965,10 +3965,9 @@ def runTest(self):
self.dst_client, asic_type, port_list['dst'][dst_port_id])
# for t2 chassis
if platform_asic and platform_asic == "broadcom-dnx":
if dst_port_id in dst_sys_port_ids:
for port_id, sysport in dst_sys_port_ids.items():
if dst_port_id == port_id:
dst_sys_port_id = int(sysport)
assert dst_port_id in dst_sys_port_ids, \
"dst_port_id does not have a sys port id configured"
dst_sys_port_id = int(dst_sys_port_ids[dst_port_id])
log_message("actual dst_sys_port_id: {}".format(dst_sys_port_id), to_stderr=True)
voq_list = sai_thrift_get_voq_port_id(self.src_client, dst_sys_port_id)
voq_queue_counters_base = sai_thrift_read_port_voq_counters(self.src_client, voq_list)
Expand Down

0 comments on commit 2e9c5ce

Please sign in to comment.