Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mellanox] Enhance Python3 support for platform API #7410

Merged
merged 3 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"skip_ledd": true,
"skip_fancontrol": true,
"delay_xcvrd": true,
"python2_daemons": ["xcvrd"]
"delay_xcvrd": true
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python

#############################################################################
# Mellanox
#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python

#############################################################################
# Mellanox
#
Expand Down
2 changes: 0 additions & 2 deletions platform/mellanox/mlnx-platform-api/sonic_platform/fan.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python

#############################################################################
# Mellanox
#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python

#############################################################################
# Mellanox
#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python

#############################################################################
# Mellanox
#
Expand Down
2 changes: 0 additions & 2 deletions platform/mellanox/mlnx-platform-api/sonic_platform/psu.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python

#############################################################################
# Mellanox
#
Expand Down
29 changes: 18 additions & 11 deletions platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python

#############################################################################
# Mellanox
#
Expand Down Expand Up @@ -1493,9 +1491,12 @@ def mgmt_phy_mod_pwr_attr_get(cls, power_attr_type, sdk_handle, sdk_index):
sx_mgmt_phy_mod_pwr_attr = sx_mgmt_phy_mod_pwr_attr_t()
stephenxs marked this conversation as resolved.
Show resolved Hide resolved
sx_mgmt_phy_mod_pwr_attr.power_attr_type = power_attr_type
sx_mgmt_phy_mod_pwr_attr_t_p_assign(sx_mgmt_phy_mod_pwr_attr_p, sx_mgmt_phy_mod_pwr_attr)
module_id_info = sx_mgmt_module_id_info_t()
module_id_info.slot_id = 0
module_id_info.module_id = sdk_index
try:
rc = sx_mgmt_phy_mod_pwr_attr_get(sdk_handle, sdk_index, sx_mgmt_phy_mod_pwr_attr_p)
assert SX_STATUS_SUCCESS == rc, "sx_mgmt_phy_mod_pwr_attr_get failed"
rc = sx_mgmt_phy_module_pwr_attr_get(sdk_handle, module_id_info, sx_mgmt_phy_mod_pwr_attr_p)
assert SX_STATUS_SUCCESS == rc, "sx_mgmt_phy_module_pwr_attr_get failed {}".format(rc)
sx_mgmt_phy_mod_pwr_attr = sx_mgmt_phy_mod_pwr_attr_t_p_value(sx_mgmt_phy_mod_pwr_attr_p)
pwr_mode_attr = sx_mgmt_phy_mod_pwr_attr.pwr_mode_attr
return pwr_mode_attr.admin_pwr_mode_e, pwr_mode_attr.oper_pwr_mode_e
Expand All @@ -1517,7 +1518,7 @@ def get_lpmode(self):
get_lpmode_code = 'from sonic_platform import sfp;\n' \
'with sfp.SdkHandleContext() as sdk_handle:' \
'print(sfp.SFP._get_lpmode(sdk_handle, {}))'.format(self.sdk_index)
lpm_cmd = "docker exec pmon python -c \"{}\"".format(get_lpmode_code)
lpm_cmd = "docker exec pmon python3 -c \"{}\"".format(get_lpmode_code)
try:
output = subprocess.check_output(lpm_cmd, shell=True, universal_newlines=True)
return 'True' in output
Expand Down Expand Up @@ -1921,7 +1922,7 @@ def reset(self):
'with sfp.SdkHandleContext() as sdk_handle:' \
'print(sfp.SFP._reset(sdk_handle, {}))' \
.format(self.sdk_index)
reset_cmd = "docker exec pmon python -c \"{}\"".format(reset_code)
reset_cmd = "docker exec pmon python3 -c \"{}\"".format(reset_code)

try:
output = subprocess.check_output(reset_cmd, shell=True, universal_newlines=True)
Expand All @@ -1935,9 +1936,12 @@ def reset(self):

@classmethod
def _reset(cls, sdk_handle, sdk_index):
rc = sx_mgmt_phy_mod_reset(sdk_handle, sdk_index)
module_id_info = sx_mgmt_module_id_info_t()
module_id_info.slot_id = 0
module_id_info.module_id = sdk_index
rc = sx_mgmt_phy_module_reset(sdk_handle, module_id_info)
if rc != SX_STATUS_SUCCESS:
logger.log_warning("sx_mgmt_phy_mod_reset failed, rc = %d" % rc)
logger.log_error("Error occurred when resetting SFP module {}, error code {}".format(sdk_index, rc))

return rc == SX_STATUS_SUCCESS

Expand Down Expand Up @@ -2051,10 +2055,13 @@ def mgmt_phy_mod_pwr_attr_set(cls, sdk_handle, sdk_index, power_attr_type, admin
sx_mgmt_phy_mod_pwr_attr.pwr_mode_attr = sx_mgmt_phy_mod_pwr_mode_attr
sx_mgmt_phy_mod_pwr_attr_p = new_sx_mgmt_phy_mod_pwr_attr_t_p()
sx_mgmt_phy_mod_pwr_attr_t_p_assign(sx_mgmt_phy_mod_pwr_attr_p, sx_mgmt_phy_mod_pwr_attr)
module_id_info = sx_mgmt_module_id_info_t()
module_id_info.slot_id = 0
module_id_info.module_id = sdk_index
try:
rc = sx_mgmt_phy_mod_pwr_attr_set(sdk_handle, SX_ACCESS_CMD_SET, sdk_index, sx_mgmt_phy_mod_pwr_attr_p)
rc = sx_mgmt_phy_module_pwr_attr_set(sdk_handle, SX_ACCESS_CMD_SET, module_id_info, sx_mgmt_phy_mod_pwr_attr_p)
if SX_STATUS_SUCCESS != rc:
logger.log_error("sx_mgmt_phy_mod_pwr_attr_set failed, rc = %d" % rc)
logger.log_error("Error occurred when setting power mode for SFP module {}, error code {}".format(sdk_index, rc))
result = False
else:
result = True
Expand Down Expand Up @@ -2104,7 +2111,7 @@ def set_lpmode(self, lpmode):
'with sfp.SdkHandleContext() as sdk_handle:' \
'print(sfp.SFP._set_lpmode({}, sdk_handle, {}))' \
.format('True' if lpmode else 'False', self.sdk_index)
lpm_cmd = "docker exec pmon python -c \"{}\"".format(set_lpmode_code)
lpm_cmd = "docker exec pmon python3 -c \"{}\"".format(set_lpmode_code)

# Set LPM
try:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
stephenxs marked this conversation as resolved.
Show resolved Hide resolved
'''
listen to the SDK for the SFP change event and return to chassis.
'''
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python

#############################################################################
# Mellanox
#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python

"""
Mellanox

Expand Down