From 3f42353bf1ea6864236b21afaab894500c82faea Mon Sep 17 00:00:00 2001 From: Stephen Sun <5379172+stephenxs@users.noreply.github.com> Date: Mon, 21 Oct 2019 21:14:35 +0800 Subject: [PATCH] [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 --- .../x86_64-mlnx_msn2010-r0/plugins/psuutil.py | 12 +++--------- .../x86_64-mlnx_msn2100-r0/plugins/psuutil.py | 5 ++++- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/device/mellanox/x86_64-mlnx_msn2010-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2010-r0/plugins/psuutil.py index 914ef050d2..5424128241 100644 --- a/device/mellanox/x86_64-mlnx_msn2010-r0/plugins/psuutil.py +++ b/device/mellanox/x86_64-mlnx_msn2010-r0/plugins/psuutil.py @@ -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() diff --git a/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py index b9bb580d7c..5424128241 100644 --- a/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py +++ b/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py @@ -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()