Skip to content
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
12 changes: 3 additions & 9 deletions device/mellanox/x86_64-mlnx_msn2010-r0/plugins/psuutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class PsuUtil(PsuBase):

def __init__(self):
PsuBase.__init__(self)

self.psu_path = ""
for index in range(0, 100):
hwmon_path = "/sys/devices/platform/mlxplat/mlxreg-hotplug/hwmon/hwmon{}/".format(index)
Expand Down Expand Up @@ -65,14 +66,7 @@ def get_psu_presence(self, index):
:param index: An integer, 1-based index of the PSU of which to query status
:return: Boolean, True if PSU is plugged, False if not
"""
if index is None:
return False

status = 0
try:
with open(self.psu_path + self.psu_presence.format(index), 'r') as presence_status:
status = int(presence_status.read())
except IOError:
if not isinstance(index, int):
return False

return status == 1
return index > 0 and index <= self.get_num_psus()
5 changes: 4 additions & 1 deletion device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,7 @@ def get_psu_presence(self, index):
:param index: An integer, 1-based index of the PSU of which to query status
:return: Boolean, True if PSU is plugged, False if not
"""
return isinstance(index, int) and index > 0 and index <= self.get_num_psus()
if not isinstance(index, int):
return False

return index > 0 and index <= self.get_num_psus()