Skip to content

Commit 346b916

Browse files
authored
[Mellanox] Enhance Python3 support for platform API (#7410) (#7910)
- Why I did it This is to back-port Azure 7410 to 202012 branch. Enhance the Python3 support for platform API. Originally, some platform APIs call SDK API which didn't support Python 3. Now the Python 3 APIs have been supported in SDK 4.4.3XXX, Python3 is completely supported by platform API - How I did it Start all platform daemons from python3 1. Remove #/usr/bin/env python at the beginning of each platform API file as the platform API won't be started as daemons but be imported from other daemons. 2. Adjust SDK API calls accordingly Signed-off-by: Stephen Sun <[email protected]>
1 parent 93585b0 commit 346b916

File tree

11 files changed

+16
-27
lines changed

11 files changed

+16
-27
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"skip_ledd": true,
33
"skip_fancontrol": true,
4-
"delay_xcvrd": true,
5-
"python2_daemons": ["xcvrd"]
4+
"delay_xcvrd": true
65
}
76

platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
#############################################################################
42
# Mellanox
53
#

platform/mellanox/mlnx-platform-api/sonic_platform/component.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
#############################################################################
42
# Mellanox
53
#

platform/mellanox/mlnx-platform-api/sonic_platform/fan.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
#############################################################################
42
# Mellanox
53
#

platform/mellanox/mlnx-platform-api/sonic_platform/fan_drawer.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
#############################################################################
42
# Mellanox
53
#

platform/mellanox/mlnx-platform-api/sonic_platform/platform.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
#############################################################################
42
# Mellanox
53
#

platform/mellanox/mlnx-platform-api/sonic_platform/psu.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
#############################################################################
42
# Mellanox
53
#

platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
#############################################################################
42
# Mellanox
53
#
@@ -1479,9 +1477,12 @@ def mgmt_phy_mod_pwr_attr_get(self, power_attr_type):
14791477
sx_mgmt_phy_mod_pwr_attr = sx_mgmt_phy_mod_pwr_attr_t()
14801478
sx_mgmt_phy_mod_pwr_attr.power_attr_type = power_attr_type
14811479
sx_mgmt_phy_mod_pwr_attr_t_p_assign(sx_mgmt_phy_mod_pwr_attr_p, sx_mgmt_phy_mod_pwr_attr)
1480+
module_id_info = sx_mgmt_module_id_info_t()
1481+
module_id_info.slot_id = 0
1482+
module_id_info.module_id = self.sdk_index
14821483
try:
1483-
rc = sx_mgmt_phy_mod_pwr_attr_get(self.sdk_handle, self.sdk_index, sx_mgmt_phy_mod_pwr_attr_p)
1484-
assert SX_STATUS_SUCCESS == rc, "sx_mgmt_phy_mod_pwr_attr_get failed"
1484+
rc = sx_mgmt_phy_module_pwr_attr_get(self.sdk_handle, module_id_info, sx_mgmt_phy_mod_pwr_attr_p)
1485+
assert SX_STATUS_SUCCESS == rc, "sx_mgmt_phy_module_pwr_attr_get failed {}".format(rc)
14851486
sx_mgmt_phy_mod_pwr_attr = sx_mgmt_phy_mod_pwr_attr_t_p_value(sx_mgmt_phy_mod_pwr_attr_p)
14861487
pwr_mode_attr = sx_mgmt_phy_mod_pwr_attr.pwr_mode_attr
14871488
return pwr_mode_attr.admin_pwr_mode_e, pwr_mode_attr.oper_pwr_mode_e
@@ -1872,9 +1873,12 @@ def reset(self):
18721873
18731874
refer plugins/sfpreset.py
18741875
"""
1875-
rc = sx_mgmt_phy_mod_reset(self.sdk_handle, self.sdk_index)
1876+
module_id_info = sx_mgmt_module_id_info_t()
1877+
module_id_info.slot_id = 0
1878+
module_id_info.module_id = self.sdk_index
1879+
rc = sx_mgmt_phy_module_reset(self.sdk_handle, module_id_info)
18761880
if rc != SX_STATUS_SUCCESS:
1877-
logger.log_warning("sx_mgmt_phy_mod_reset failed, rc = %d" % rc)
1881+
logger.log_error("Error occurred when resetting SFP module {}, error code {}".format(self.sdk_index, rc))
18781882

18791883
return rc == SX_STATUS_SUCCESS
18801884

@@ -1982,10 +1986,13 @@ def mgmt_phy_mod_pwr_attr_set(self, power_attr_type, admin_pwr_mode):
19821986
sx_mgmt_phy_mod_pwr_attr.pwr_mode_attr = sx_mgmt_phy_mod_pwr_mode_attr
19831987
sx_mgmt_phy_mod_pwr_attr_p = new_sx_mgmt_phy_mod_pwr_attr_t_p()
19841988
sx_mgmt_phy_mod_pwr_attr_t_p_assign(sx_mgmt_phy_mod_pwr_attr_p, sx_mgmt_phy_mod_pwr_attr)
1989+
module_id_info = sx_mgmt_module_id_info_t()
1990+
module_id_info.slot_id = 0
1991+
module_id_info.module_id = self.sdk_index
19851992
try:
1986-
rc = sx_mgmt_phy_mod_pwr_attr_set(self.sdk_handle, SX_ACCESS_CMD_SET, self.sdk_index, sx_mgmt_phy_mod_pwr_attr_p)
1993+
rc = sx_mgmt_phy_module_pwr_attr_set(self.sdk_handle, SX_ACCESS_CMD_SET, module_id_info, sx_mgmt_phy_mod_pwr_attr_p)
19871994
if SX_STATUS_SUCCESS != rc:
1988-
logger.log_error("sx_mgmt_phy_mod_pwr_attr_set failed, rc = %d" % rc)
1995+
logger.log_error("Error occurred when setting power mode for SFP module {}, error code {}".format(self.sdk_index, rc))
19891996
result = False
19901997
else:
19911998
result = True

platform/mellanox/mlnx-platform-api/sonic_platform/sfp_event.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python
21
'''
32
listen to the SDK for the SFP change event and return to chassis.
43
'''

platform/mellanox/mlnx-platform-api/sonic_platform/thermal.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
#############################################################################
42
# Mellanox
53
#

0 commit comments

Comments
 (0)