From 7c74a0d6023792d57d06ac21188103fdbc4a4886 Mon Sep 17 00:00:00 2001 From: Patrick MacArthur Date: Tue, 7 Jan 2025 11:52:29 -0500 Subject: [PATCH] sonic-mgmt: Fix namespace issues for qos tests on T2 single ASIC (#15708) 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. --- tests/qos/qos_sai_base.py | 11 +++++++---- tests/saitests/py3/sai_qos_tests.py | 7 +++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/qos/qos_sai_base.py b/tests/qos/qos_sai_base.py index 03ee343230d..3ae11556906 100644 --- a/tests/qos/qos_sai_base.py +++ b/tests/qos/qos_sai_base.py @@ -1089,6 +1089,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] @@ -1097,7 +1098,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} @@ -1114,7 +1115,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'] @@ -1132,6 +1133,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')[ @@ -1141,6 +1143,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): @@ -1150,7 +1153,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} @@ -1167,7 +1170,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'] diff --git a/tests/saitests/py3/sai_qos_tests.py b/tests/saitests/py3/sai_qos_tests.py index bfd06eb47c5..e756d5f416b 100755 --- a/tests/saitests/py3/sai_qos_tests.py +++ b/tests/saitests/py3/sai_qos_tests.py @@ -4018,10 +4018,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)