From 9693616c142928f74d270b245fbe6fc79f4e6c08 Mon Sep 17 00:00:00 2001 From: "Nana@Nvidia" <78413612+nhe-NV@users.noreply.github.com> Date: Thu, 15 Jun 2023 09:25:59 +0800 Subject: [PATCH] Fix python3 migration issue for qos sai test case (#7958) Fix the issues: #7866 and #7884 What is the motivation for this PR? Fix the test failure caused by python3 migration How did you verify/test it? Run qos sai and test_sub_port_l2_forwarding, and it could pass --- tests/qos/files/mellanox/qos_param_generator.py | 6 +++--- tests/qos/qos_sai_base.py | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/qos/files/mellanox/qos_param_generator.py b/tests/qos/files/mellanox/qos_param_generator.py index 9fec776836..854f44a853 100644 --- a/tests/qos/files/mellanox/qos_param_generator.py +++ b/tests/qos/files/mellanox/qos_param_generator.py @@ -2,8 +2,8 @@ class QosParamMellanox(object): - def __init__(self, qos_params, asic_type, speed_cable_len, dutConfig, ingressLosslessProfile, - ingressLossyProfile, egressLosslessProfile, egressLossyProfile, sharedHeadroomPoolSize, dualTor): + def __init__(self, qos_params, asic_type, speed_cable_len, dutConfig, ingressLosslessProfile, ingressLossyProfile, + egressLosslessProfile, egressLossyProfile, sharedHeadroomPoolSize, dualTor): self.asic_param_dic = { 'spc1': { 'cell_size': 96, @@ -107,7 +107,7 @@ def collect_qos_configurations(self): for i in range(1, ingress_ports_num_shp): for j in range(pgs_per_port): pkts_num_trig_pfc_shp.append(occupancy_per_port + xon + hysteresis) - occupancy_per_port /= 2 + occupancy_per_port //= 2 ingress_ports_list_shp.append(testPortIds[i]) self.qos_parameters['pkts_num_trig_pfc_shp'] = pkts_num_trig_pfc_shp self.qos_parameters['src_port_ids'] = ingress_ports_list_shp diff --git a/tests/qos/qos_sai_base.py b/tests/qos/qos_sai_base.py index e607bbe753..42b6946dbc 100644 --- a/tests/qos/qos_sai_base.py +++ b/tests/qos/qos_sai_base.py @@ -21,6 +21,7 @@ from tests.common.fixtures.duthost_utils import dut_qos_maps, separated_dscp_to_tc_map_on_uplink # noqa F401 from tests.common.utilities import wait_until from tests.ptf_runner import ptf_runner +from tests.common.system_utils import docker # noqa F401 from tests.common.errors import RunAnsibleModuleFail logger = logging.getLogger(__name__) @@ -86,8 +87,9 @@ def dutTestParams(self, duthosts, enum_rand_one_per_hwsku_frontend_hostname, enu if 'mac' in vlan and vlan['mac']: dut_test_params["basicParams"]["def_vlan_mac"] = vlan['mac'] break - pytest_assert(dut_test_params["basicParams"]["def_vlan_mac"] - is not None, "Dual-TOR miss default VLAN MAC address") + + pytest_assert(dut_test_params["basicParams"]["def_vlan_mac"] is not None, + "Dual-TOR miss default VLAN MAC address") else: try: duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] @@ -434,7 +436,7 @@ def __assignTestPortIps(self, mgFacts, topo): testVlanIp = None for vlan in mgFacts["minigraph_vlan_interfaces"]: if mgFacts["minigraph_vlans"][testVlan]["name"] in vlan["attachto"]: - testVlanIp = ipaddress.ip_address(str(vlan["addr"])) # noqa F821 + testVlanIp = ipaddress.ip_address(vlan["addr"]) # noqa F821 break pytest_assert(testVlanIp, "Failed to obtain vlan IP") @@ -682,8 +684,7 @@ def dutConfig( [iface]["members"]) ) portIndex = mgFacts["minigraph_ptf_indices"][portName] - portIpMap = { - 'peer_addr': addr["peer_ipv4"], 'port': portName} + portIpMap = {'peer_addr': addr["peer_ipv4"], 'port': portName} dutPortIps.update({portIndex: portIpMap}) testPortIds = sorted(dutPortIps.keys()) @@ -1005,9 +1006,8 @@ def dutArpProxyConfig(self, duthost): # so far, only record ARP proxy config to logging for debug purpose vlanInterface = {} try: - vlanInterface = json.loads(duthost.shell( - 'sonic-cfggen -d --var-json "VLAN_INTERFACE"')['stdout']) - except Exception: + vlanInterface = json.loads(duthost.shell('sonic-cfggen -d --var-json "VLAN_INTERFACE"')['stdout']) + except: # noqa: E722 logger.info('Failed to read vlan interface config') if not vlanInterface: return