From 838efecd0e1693876c2541c7afa0988b81186c3d Mon Sep 17 00:00:00 2001 From: junchao Date: Tue, 25 Aug 2020 18:00:23 +0800 Subject: [PATCH 1/7] Mellanox platform API change for SONiC Physical MIB Entity feature --- .../sonic_platform/chassis.py | 26 +++++-- .../mlnx-platform-api/sonic_platform/fan.py | 20 +++++- .../sonic_platform/fan_drawer.py | 16 +++++ .../mlnx-platform-api/sonic_platform/psu.py | 22 +++++- .../mlnx-platform-api/sonic_platform/sfp.py | 23 ++++++- .../sonic_platform/thermal.py | 68 ++++++++++++++----- .../mlnx-platform-api/sonic_platform/utils.py | 42 ++++++++++++ 7 files changed, 192 insertions(+), 25 deletions(-) create mode 100644 platform/mellanox/mlnx-platform-api/sonic_platform/utils.py diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py b/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py index 68c3fe16a86a..af534ea062d6 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py @@ -110,7 +110,7 @@ def initialize_fan(self): drawer = drawer_ctor(drawer_index, fan_data) self._fan_drawer_list.append(drawer) for index in range(fan_num_per_drawer): - fan = Fan(fan_index, drawer) + fan = Fan(fan_index, drawer, index + 1) fan_index += 1 drawer._fan_list.append(fan) self._fan_list.append(fan) @@ -130,18 +130,18 @@ def initialize_sfp(self): for index in range(self.PORT_START, self.PORT_END + 1): if index in range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1): - sfp_module = SFP(index, 'QSFP') + sfp_module = SFP(index, 'QSFP', self.platform_name) else: - sfp_module = SFP(index, 'SFP') + sfp_module = SFP(index, 'SFP', self.platform_name) self._sfp_list.append(sfp_module) self.sfp_module_initialized = True def initialize_thermals(self): - from sonic_platform.thermal import initialize_thermals + from sonic_platform.thermal import initialize_chassis_thermals # Initialize thermals - initialize_thermals(self.platform_name, self._thermal_list, self._psu_list) + initialize_chassis_thermals(self.platform_name, self._thermal_list) def initialize_eeprom(self): @@ -495,3 +495,19 @@ def get_status_led(self): specified. """ return None if not Chassis._led else Chassis._led.get_status() + + def get_position_in_parent(self): + """ + Retrieves 1-based relative physical position in parent device + Returns: + integer: The 1-based relative physical position in parent device + """ + return 1 + + def is_replaceable(self): + """ + Indicate whether this device is replaceable. + Returns: + bool: True if it is replaceable. + """ + return False diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py b/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py index 1808bdd0aeee..7229368aa73c 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py @@ -36,12 +36,13 @@ class Fan(FanBase): PSU_FAN_SPEED = ['0x3c', '0x3c', '0x3c', '0x3c', '0x3c', '0x3c', '0x3c', '0x46', '0x50', '0x5a', '0x64'] - def __init__(self, fan_index, fan_drawer, psu_fan = False): + def __init__(self, fan_index, fan_drawer, position, psu_fan = False): super(Fan, self).__init__() # API index is starting from 0, Mellanox platform index is starting from 1 self.index = fan_index + 1 self.fan_drawer = fan_drawer + self.position = position self.is_psu_fan = psu_fan if self.fan_drawer: @@ -291,6 +292,22 @@ def get_speed_tolerance(self): # The tolerance value is fixed as 50% for all the Mellanox platform return 50 + def get_position_in_parent(self): + """ + Retrieves 1-based relative physical position in parent device + Returns: + integer: The 1-based relative physical position in parent device + """ + return self.position + + def is_replaceable(self): + """ + Indicate whether this device is replaceable. + Returns: + bool: True if it is replaceable. + """ + return False + @classmethod def set_cooling_level(cls, level, cur_state): """ @@ -329,3 +346,4 @@ def get_cooling_level(cls): except (ValueError, IOError) as e: raise RuntimeError("Failed to get cooling level - {}".format(e)) + \ No newline at end of file diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/fan_drawer.py b/platform/mellanox/mlnx-platform-api/sonic_platform/fan_drawer.py index bed6c7ab042a..66ee39491735 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/fan_drawer.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/fan_drawer.py @@ -84,6 +84,22 @@ def get_status_led(self): """ return self._led.get_status() + def get_position_in_parent(self): + """ + Retrieves 1-based relative physical position in parent device + Returns: + integer: The 1-based relative physical position in parent device + """ + return self._index + + def is_replaceable(self): + """ + Indicate whether this device is replaceable. + Returns: + bool: True if it is replaceable. + """ + return self._fan_data['hot_swappable'] + class RealDrawer(MellanoxFanDrawer): def __init__(self, index, fan_data): diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py b/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py index d26df89f04ce..66c678811210 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py @@ -103,7 +103,7 @@ def __init__(self, psu_index, platform): # unplugable PSU has no FAN if self.psu_data['hot_swappable']: - fan = Fan(psu_index, None, True) + fan = Fan(psu_index, None, 1, True) self._fan_list.append(fan) if self.psu_data['led_num'] == 1: @@ -111,6 +111,10 @@ def __init__(self, psu_index, platform): else: # 2010/2100 self.led = PsuLed(self.index) + # initialize thermal for PSU + from .thermal import initialize_psu_thermals + initialize_psu_thermals(platform, self._thermal_list, self.index, self.get_powergood_status) + def get_name(self): return self._name @@ -244,6 +248,22 @@ def get_power_available_status(self): else: return True, "" + def get_position_in_parent(self): + """ + Retrieves 1-based relative physical position in parent device + Returns: + integer: The 1-based relative physical position in parent device + """ + return self.index + + def is_replaceable(self): + """ + Indicate whether this device is replaceable. + Returns: + bool: True if it is replaceable. + """ + return self.psu_data['hot_swappable'] + @classmethod def get_shared_led(cls): if not cls.shared_led: diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py b/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py index afe0dd0cc19b..b87df1b13e54 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py @@ -284,7 +284,8 @@ class SFP(SfpBase): """Platform-specific SFP class""" - def __init__(self, sfp_index, sfp_type): + def __init__(self, sfp_index, sfp_type, platform): + SfpBase.__init__(self) self.index = sfp_index + 1 self.sfp_eeprom_path = "qsfp{}".format(self.index) self.sfp_status_path = "qsfp{}_status".format(self.index) @@ -294,6 +295,10 @@ def __init__(self, sfp_index, sfp_type): self.sdk_handle = None self.sdk_index = sfp_index + # initialize SFP thermal list + from .thermal import initialize_sfp_thermals + initialize_sfp_thermals(platform, self._thermal_list, self.index) + #SDK initializing stuff def _initialize_sdk_handle(self): @@ -2149,3 +2154,19 @@ def set_power_override(self, power_override, power_set): return self._write_i2c_via_mcia(0, 0x50, MCIA_ADDR_POWER_OVERRIDE, power_set_bit|power_override_bit, power_override_mask) else: return NotImplementedError + + def get_position_in_parent(self): + """ + Retrieves 1-based relative physical position in parent device + Returns: + integer: The 1-based relative physical position in parent device + """ + return self.index + + def is_replaceable(self): + """ + Indicate whether this device is replaceable. + Returns: + bool: True if it is replaceable. + """ + return True diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/thermal.py b/platform/mellanox/mlnx-platform-api/sonic_platform/thermal.py index 4ebe28252481..b7b9eeadb2d0 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/thermal.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/thermal.py @@ -115,10 +115,7 @@ thermal_device_categories_all = [ THERMAL_DEV_CATEGORY_CPU_CORE, THERMAL_DEV_CATEGORY_CPU_PACK, - THERMAL_DEV_CATEGORY_MODULE, - THERMAL_DEV_CATEGORY_PSU, - THERMAL_DEV_CATEGORY_AMBIENT, - THERMAL_DEV_CATEGORY_GEARBOX + THERMAL_DEV_CATEGORY_AMBIENT ] thermal_device_categories_singleton = [ @@ -305,18 +302,42 @@ } ] +def initialize_psu_thermals(platform, thermal_list, psu_index, dependency): + tp_index = platform_dict_thermal[platform] + thermal_profile = thermal_profile_list[tp_index] + _, count = thermal_profile[THERMAL_DEV_CATEGORY_PSU] + if count == 0: + return + thermal = Thermal(THERMAL_DEV_CATEGORY_PSU, psu_index, True, 1, dependency) + thermal_list.append(thermal) + + +def initialize_sfp_thermals(platform, thermal_list, sfp_index): + thermal = Thermal(THERMAL_DEV_CATEGORY_MODULE, sfp_index, True, 1) + thermal_list.append(thermal) -def initialize_thermals(platform, thermal_list, psu_list): + tp_index = platform_dict_thermal[platform] + thermal_profile = thermal_profile_list[tp_index] + _, count = thermal_profile[THERMAL_DEV_CATEGORY_GEARBOX] + if count == 0: + return + thermal = Thermal(THERMAL_DEV_CATEGORY_GEARBOX, sfp_index, True, 2) + thermal_list.append(thermal) + + +def initialize_chassis_thermals(platform, thermal_list): # create thermal objects for all categories of sensors tp_index = platform_dict_thermal[platform] thermal_profile = thermal_profile_list[tp_index] Thermal.thermal_profile = thermal_profile + position = 1 for category in thermal_device_categories_all: if category == THERMAL_DEV_CATEGORY_AMBIENT: count, ambient_list = thermal_profile[category] for ambient in ambient_list: - thermal = Thermal(category, ambient, True) - thermal_list.append(thermal) + thermal = Thermal(category, ambient, True, position) + thermal_list.append(thermal), + position += 1 else: start, count = 0, 0 if category in thermal_profile: @@ -324,17 +345,14 @@ def initialize_thermals(platform, thermal_list, psu_list): if count == 0: continue if count == 1: - thermal = Thermal(category, 0, False) + thermal = Thermal(category, 0, False, position) thermal_list.append(thermal) + position += 1 else: - if category == THERMAL_DEV_CATEGORY_PSU: - for index in range(count): - thermal = Thermal(category, start + index, True, psu_list[index].get_power_available_status) - thermal_list.append(thermal) - else: - for index in range(count): - thermal = Thermal(category, start + index, True) - thermal_list.append(thermal) + for index in range(count): + thermal = Thermal(category, start + index, True, position) + thermal_list.append(thermal) + position += 1 @@ -342,7 +360,7 @@ class Thermal(ThermalBase): thermal_profile = None thermal_algorithm_status = False - def __init__(self, category, index, has_index, dependency = None): + def __init__(self, category, index, has_index, position, dependency = None): """ index should be a string for category ambient and int for other categories """ @@ -357,6 +375,7 @@ def __init__(self, category, index, has_index, dependency = None): self.index = 0 self.category = category + self.position = position self.temperature = self._get_file_from_api(THERMAL_API_GET_TEMPERATURE) self.high_threshold = self._get_file_from_api(THERMAL_API_GET_HIGH_THRESHOLD) self.high_critical_threshold = self._get_file_from_api(THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD) @@ -480,6 +499,21 @@ def get_high_critical_threshold(self): return None return value_float / 1000.0 + def get_position_in_parent(self): + """ + Retrieves 1-based relative physical position in parent device + Returns: + integer: The 1-based relative physical position in parent device + """ + return self.position + + def is_replaceable(self): + """ + Indicate whether this device is replaceable. + Returns: + bool: True if it is replaceable. + """ + return False @classmethod def _write_generic_file(cls, filename, content): diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/utils.py b/platform/mellanox/mlnx-platform-api/sonic_platform/utils.py new file mode 100644 index 000000000000..03fe1f2c3b31 --- /dev/null +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/utils.py @@ -0,0 +1,42 @@ +import os + + +class FileUtils(object): + last_error = '' + + @classmethod + def read(cls, file_path, default=None, no_raise=True): + cls.last_error = '' + try: + with open(file_path, 'r') as f: + return f.read().strip() + except IOError as e: + cls.last_error = 'Failed to read from {} - {}'.format(file_path, repr(e)) + return default + + @classmethod + def read_int(cls, file_path, default=0): + try: + return int(cls.read(file_path, default)) + except ValueError as e: + cls.last_error = 'Failed to read from {} - {}'.format(file_path, repr(e)) + return default + + @classmethod + def read_float(cls, file_path, default=0): + try: + return float(cls.read(file_path, default)) + except ValueError as e: + cls.last_error = 'Failed to read from {} - {}'.format(file_path, repr(e)) + return default + + classmethod + def write(cls, file_path, value): + cls.last_error = '' + try: + with open(file_path, 'w') as f: + f.write(str(value)) + return True + except IOError as e: + cls.last_error = 'Failed to write to {} - {}'.format(file_path, repr(e)) + return False From 4cd10f9778ea445fd8ca819c23cab5679ebf68ac Mon Sep 17 00:00:00 2001 From: junchao Date: Fri, 28 Aug 2020 10:18:36 +0800 Subject: [PATCH 2/7] Fix unit test issue --- platform/mellanox/mlnx-platform-api/tests/test_fan_api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platform/mellanox/mlnx-platform-api/tests/test_fan_api.py b/platform/mellanox/mlnx-platform-api/tests/test_fan_api.py index 24158997abf7..bb9ee7e125a2 100644 --- a/platform/mellanox/mlnx-platform-api/tests/test_fan_api.py +++ b/platform/mellanox/mlnx-platform-api/tests/test_fan_api.py @@ -16,7 +16,7 @@ def test_get_absence_fan_direction(): fan_drawer = RealDrawer(0, DEVICE_DATA['x86_64-mlnx_msn2700-r0']['fans']) - fan = Fan(0, fan_drawer) + fan = Fan(0, fan_drawer, 1) fan_drawer.get_presence = MagicMock(return_value=False) assert not fan.is_psu_fan @@ -31,8 +31,8 @@ def test_fan_drawer_set_status_led(): with pytest.raises(Exception): fan_drawer.set_status_led(None, Fan.STATUS_LED_COLOR_RED) - fan1 = Fan(0, fan_drawer) - fan2 = Fan(1, fan_drawer) + fan1 = Fan(0, fan_drawer, 1) + fan2 = Fan(1, fan_drawer, 2) fan_list = fan_drawer.get_all_fans() fan_list.append(fan1) fan_list.append(fan2) From 25f48ab7d61097ca7c6f832f149a46d10aa6ee5d Mon Sep 17 00:00:00 2001 From: junchao Date: Mon, 31 Aug 2020 16:15:17 +0800 Subject: [PATCH 3/7] Fix issue found in manual test --- platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py | 2 +- platform/mellanox/mlnx-platform-api/sonic_platform/psu.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py b/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py index af534ea062d6..82150ed4a568 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py @@ -502,7 +502,7 @@ def get_position_in_parent(self): Returns: integer: The 1-based relative physical position in parent device """ - return 1 + return -1 def is_replaceable(self): """ diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py b/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py index 66c678811210..705522224cf7 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py @@ -113,7 +113,7 @@ def __init__(self, psu_index, platform): # initialize thermal for PSU from .thermal import initialize_psu_thermals - initialize_psu_thermals(platform, self._thermal_list, self.index, self.get_powergood_status) + initialize_psu_thermals(platform, self._thermal_list, self.index, self.get_power_available_status) def get_name(self): From 4a2f61401ab851045a089359c531eec6bc2daa50 Mon Sep 17 00:00:00 2001 From: junchao Date: Tue, 1 Sep 2020 17:48:09 +0800 Subject: [PATCH 4/7] Fix thermal order --- .../mlnx-platform-api/sonic_platform/thermal.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/thermal.py b/platform/mellanox/mlnx-platform-api/sonic_platform/thermal.py index b7b9eeadb2d0..48b277345b3a 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/thermal.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/thermal.py @@ -113,9 +113,10 @@ } thermal_device_categories_all = [ - THERMAL_DEV_CATEGORY_CPU_CORE, + THERMAL_DEV_CATEGORY_AMBIENT, THERMAL_DEV_CATEGORY_CPU_PACK, - THERMAL_DEV_CATEGORY_AMBIENT + THERMAL_DEV_CATEGORY_CPU_CORE, + THERMAL_DEV_CATEGORY_GEARBOX, ] thermal_device_categories_singleton = [ @@ -316,14 +317,6 @@ def initialize_sfp_thermals(platform, thermal_list, sfp_index): thermal = Thermal(THERMAL_DEV_CATEGORY_MODULE, sfp_index, True, 1) thermal_list.append(thermal) - tp_index = platform_dict_thermal[platform] - thermal_profile = thermal_profile_list[tp_index] - _, count = thermal_profile[THERMAL_DEV_CATEGORY_GEARBOX] - if count == 0: - return - thermal = Thermal(THERMAL_DEV_CATEGORY_GEARBOX, sfp_index, True, 2) - thermal_list.append(thermal) - def initialize_chassis_thermals(platform, thermal_list): # create thermal objects for all categories of sensors From c135445fead400c59ccea2772124fb86d5291d7a Mon Sep 17 00:00:00 2001 From: junchao Date: Wed, 9 Sep 2020 10:34:43 +0800 Subject: [PATCH 5/7] Fix review comment --- .../mellanox/mlnx-platform-api/sonic_platform/chassis.py | 9 +++++---- .../mellanox/mlnx-platform-api/sonic_platform/sfp.py | 8 -------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py b/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py index 82150ed4a568..b5ca59da32ad 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py @@ -498,10 +498,11 @@ def get_status_led(self): def get_position_in_parent(self): """ - Retrieves 1-based relative physical position in parent device - Returns: - integer: The 1-based relative physical position in parent device - """ + Retrieves 1-based relative physical position in parent device. If the agent cannot determine the parent-relative position + for some reason, or if the associated value of entPhysicalContainedIn is '0', then the value '-1' is returned + Returns: + integer: The 1-based relative physical position in parent device or -1 if cannot determine the position + """ return -1 def is_replaceable(self): diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py b/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py index b87df1b13e54..2734eb3a08de 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py @@ -2155,14 +2155,6 @@ def set_power_override(self, power_override, power_set): else: return NotImplementedError - def get_position_in_parent(self): - """ - Retrieves 1-based relative physical position in parent device - Returns: - integer: The 1-based relative physical position in parent device - """ - return self.index - def is_replaceable(self): """ Indicate whether this device is replaceable. From 938ed53352e8197047d99793ef7472b633c730a6 Mon Sep 17 00:00:00 2001 From: junchao Date: Sun, 27 Sep 2020 10:39:41 +0800 Subject: [PATCH 6/7] Fix issue: PSU fan should not be there if PSU is absence --- .../mellanox/mlnx-platform-api/sonic_platform/fan.py | 9 +++------ .../mellanox/mlnx-platform-api/sonic_platform/psu.py | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py b/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py index 7229368aa73c..7d534e821507 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py @@ -36,7 +36,7 @@ class Fan(FanBase): PSU_FAN_SPEED = ['0x3c', '0x3c', '0x3c', '0x3c', '0x3c', '0x3c', '0x3c', '0x46', '0x50', '0x5a', '0x64'] - def __init__(self, fan_index, fan_drawer, position, psu_fan = False): + def __init__(self, fan_index, fan_drawer, position, psu_fan = False, psu=None): super(Fan, self).__init__() # API index is starting from 0, Mellanox platform index is starting from 1 @@ -45,6 +45,7 @@ def __init__(self, fan_index, fan_drawer, position, psu_fan = False): self.position = position self.is_psu_fan = psu_fan + self.psu = psu if self.fan_drawer: self.led = ComponentFaultyIndicator(self.fan_drawer.get_led()) elif self.is_psu_fan: @@ -128,11 +129,7 @@ def get_presence(self): """ status = 0 if self.is_psu_fan: - if os.path.exists(os.path.join(FAN_PATH, self.fan_presence_path)): - status = 1 - else: - status = 0 - return status == 1 + return self.psu.get_presence() and self.psu.get_powergood_status() and os.path.exists(os.path.join(FAN_PATH, self.fan_presence_path)) else: return self.fan_drawer.get_presence() diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py b/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py index 705522224cf7..897555ed8020 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py @@ -103,7 +103,7 @@ def __init__(self, psu_index, platform): # unplugable PSU has no FAN if self.psu_data['hot_swappable']: - fan = Fan(psu_index, None, 1, True) + fan = Fan(psu_index, None, 1, True, self) self._fan_list.append(fan) if self.psu_data['led_num'] == 1: From 30bad8cd501d6037e1bb2cdb0ea0b009114add9d Mon Sep 17 00:00:00 2001 From: junchao Date: Fri, 16 Oct 2020 14:47:37 +0800 Subject: [PATCH 7/7] Fix LGTM warnings --- .../mlnx-platform-api/sonic_platform/fan.py | 1 - .../mlnx-platform-api/sonic_platform/utils.py | 42 ------------------- 2 files changed, 43 deletions(-) delete mode 100644 platform/mellanox/mlnx-platform-api/sonic_platform/utils.py diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py b/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py index 7d534e821507..686b0f82ddbe 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py @@ -127,7 +127,6 @@ def get_presence(self): Returns: bool: True if fan is present, False if not """ - status = 0 if self.is_psu_fan: return self.psu.get_presence() and self.psu.get_powergood_status() and os.path.exists(os.path.join(FAN_PATH, self.fan_presence_path)) else: diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/utils.py b/platform/mellanox/mlnx-platform-api/sonic_platform/utils.py deleted file mode 100644 index 03fe1f2c3b31..000000000000 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/utils.py +++ /dev/null @@ -1,42 +0,0 @@ -import os - - -class FileUtils(object): - last_error = '' - - @classmethod - def read(cls, file_path, default=None, no_raise=True): - cls.last_error = '' - try: - with open(file_path, 'r') as f: - return f.read().strip() - except IOError as e: - cls.last_error = 'Failed to read from {} - {}'.format(file_path, repr(e)) - return default - - @classmethod - def read_int(cls, file_path, default=0): - try: - return int(cls.read(file_path, default)) - except ValueError as e: - cls.last_error = 'Failed to read from {} - {}'.format(file_path, repr(e)) - return default - - @classmethod - def read_float(cls, file_path, default=0): - try: - return float(cls.read(file_path, default)) - except ValueError as e: - cls.last_error = 'Failed to read from {} - {}'.format(file_path, repr(e)) - return default - - classmethod - def write(cls, file_path, value): - cls.last_error = '' - try: - with open(file_path, 'w') as f: - f.write(str(value)) - return True - except IOError as e: - cls.last_error = 'Failed to write to {} - {}'.format(file_path, repr(e)) - return False