[Mellanox] Fix SN2010 issue: "show platform psustatus" returns "NOT PRESENT" for power off PSU on 201811 (#3598)

* [plugins/psuutil]Align psuutil of 2010 with that of 2100.

* [plugins/psuutil.py]Address comments via using more human-readable code
This commit is contained in:
Stephen Sun 2019-10-21 21:14:35 +08:00 committed by liat-grozovik
parent 5965c3f4f9
commit 3f42353bf1
2 changed files with 7 additions and 10 deletions

View File

@ -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)
@ -65,14 +66,7 @@ class PsuUtil(PsuBase):
: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:
if not isinstance(index, int):
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:
return False
return status == 1
return index > 0 and index <= self.get_num_psus()

View File

@ -66,4 +66,7 @@ class PsuUtil(PsuBase):
: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()