From d5151033f06ac4a9ab70bb3c08b94ccdfdd56474 Mon Sep 17 00:00:00 2001 From: junchao Date: Tue, 19 Apr 2022 16:58:36 +0800 Subject: [PATCH] [Mellanox] Adjust PSU voltage WA --- .../mlnx-platform-api/sonic_platform/psu.py | 18 ++++++++++++------ .../mlnx-platform-api/tests/test_psu.py | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py b/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py index a2dcfcd55b4e..69f2f8930cc4 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py @@ -397,6 +397,7 @@ def get_temperature_high_threshold(self): return None + @utils.default_return(None) def get_voltage_high_threshold(self): """ Retrieves the high threshold PSU voltage output @@ -414,10 +415,12 @@ def get_voltage_high_threshold(self): if 'max' in capability: max_voltage = utils.read_int_from_file(self.psu_voltage_max, log_func=logger.log_info) max_voltage = InvalidPsuVolWA.run(self, max_voltage, self.psu_voltage_max) - return float(max_voltage) / 1000 + if max_voltage: + return float(max_voltage) / 1000 return None + @utils.default_return(None) def get_voltage_low_threshold(self): """ Retrieves the low threshold PSU voltage output @@ -435,7 +438,8 @@ def get_voltage_low_threshold(self): if 'min' in capability: min_voltage = utils.read_int_from_file(self.psu_voltage_min, log_func=logger.log_info) min_voltage = InvalidPsuVolWA.run(self, min_voltage, self.psu_voltage_min) - return float(min_voltage) / 1000 + if min_voltage: + return float(min_voltage) / 1000 return None @@ -471,7 +475,7 @@ class InvalidPsuVolWA: EXPECT_PLATFORMS = ['x86_64-mlnx_msn3700-r0', 'x86_64-mlnx_msn3700c-r0', 'x86_64-mlnx_msn3800-r0', 'x86_64-mlnx_msn4600c-r0'] MFR_FIELD = 'MFR_NAME' CAPACITY_FIELD = 'CAPACITY' - WAIT_TIME = 5 + WAIT_TIME = 1 @classmethod def run(cls, psu, threshold_value, threshold_file): @@ -499,8 +503,8 @@ def run(cls, psu, threshold_value, threshold_file): logger.log_warning('PSU {} threshold file {} value {}, but its capacity is {}'.format(psu.index, threshold_file, threshold_value, capacity)) return threshold_value - # Run a sensor -s command to triger hardware to get the real threashold value - utils.run_command('sensor -s') + # Run a sensors -s command to triger hardware to get the real threashold value + utils.run_command('sensors -s') # Wait for the threshold value change return cls.wait_set_done(threshold_file) @@ -516,5 +520,7 @@ def wait_set_done(cls, threshold_file): wait_time -= 1 time.sleep(1) - logger.log_error('sensor -s does not recover PSU threshold sensor after {} seconds'.format(cls.WAIT_TIME)) + # It is enough to use warning here because user might power off/on the PSU which may cause threshold_file + # does not exist + logger.log_warning('sensors -s does not recover PSU threshold sensor after {} seconds'.format(cls.WAIT_TIME)) return None diff --git a/platform/mellanox/mlnx-platform-api/tests/test_psu.py b/platform/mellanox/mlnx-platform-api/tests/test_psu.py index 5a5f13ff05f3..68260ef630f7 100644 --- a/platform/mellanox/mlnx-platform-api/tests/test_psu.py +++ b/platform/mellanox/mlnx-platform-api/tests/test_psu.py @@ -152,4 +152,4 @@ def get_entry_value(key): # Normal vpd_info[InvalidPsuVolWA.CAPACITY_FIELD] = InvalidPsuVolWA.EXPECT_CAPACITY assert InvalidPsuVolWA.run(psu, InvalidPsuVolWA.INVALID_VOLTAGE_VALUE, '') == 9999 - mock_run_command.assert_called_with('sensor -s') + mock_run_command.assert_called_with('sensors -s')