diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py b/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py index d123b6c6c3a..491be834aa2 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py @@ -221,6 +221,8 @@ def set_speed(self, speed): status = True if self.is_psu_fan: + if not self.get_presence(): + return False from .thermal import logger try: with open(self.psu_i2c_bus_path, 'r') as f: diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py b/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py index a323132faf9..5541402916a 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py @@ -122,6 +122,8 @@ def _read_generic_file(self, filename, len): """ result = 0 try: + if not os.path.exists(filename): + return result with open(filename, 'r') as fileobj: result = int(fileobj.read().strip()) except Exception as e: diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/thermal.py b/platform/mellanox/mlnx-platform-api/sonic_platform/thermal.py index 3c25ebb642e..54e2d1a478c 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/thermal.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/thermal.py @@ -495,12 +495,15 @@ def set_thermal_algorithm_status(cls, status, force=True): We usually disable the algorithm when we want to set a fix speed. E.g, when a fan unit is removed from system, we will set fan speed to 100% and disable the algorithm to avoid it adjust the speed. + + Returns: + True if thermal algorithm status changed. """ if not cls.thermal_profile: raise Exception("Fail to get thermal profile for this switch") if not force and cls.thermal_algorithm_status == status: - return + return False cls.thermal_algorithm_status = status content = "enabled" if status else "disabled" @@ -521,6 +524,7 @@ def set_thermal_algorithm_status(cls, status, force=True): for index in range(count): cls._write_generic_file(join(THERMAL_ZONE_GEARBOX_PATH.format(start + index), THERMAL_ZONE_MODE), content) cls._write_generic_file(join(THERMAL_ZONE_GEARBOX_PATH.format(start + index), THERMAL_ZONE_POLICY), policy) + return True @classmethod def check_thermal_zone_temperature(cls): diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/thermal_actions.py b/platform/mellanox/mlnx-platform-api/sonic_platform/thermal_actions.py index 3a4d5f2a8a6..9a4cde05b84 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/thermal_actions.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/thermal_actions.py @@ -66,9 +66,6 @@ def set_psu_fan_speed(cls, thermal_info_dict, speed): for psu_fan in psu.get_all_fans(): psu_fan.set_speed(speed) - logger.log_info('Updated PSU FAN speed to {}%'.format(speed)) - - @thermal_json_object('fan.all.check_and_set_speed') class CheckAndSetAllFanSpeedAction(SetAllFanSpeedAction): @@ -131,14 +128,17 @@ def execute(self, thermal_info_dict): from .thermal import Thermal from .thermal_conditions import UpdateCoolingLevelToMinCondition from .fan import Fan - Thermal.set_thermal_algorithm_status(self.status, False) - if self.status: - # Check thermal zone temperature, if all thermal zone temperature - # back to normal, set it to minimum allowed speed to - # save power - UpdateCoolingLevelToMinAction.update_cooling_level_to_minimum(thermal_info_dict) + status_changed = Thermal.set_thermal_algorithm_status(self.status, False) - logger.log_info('Changed thermal algorithm status to {}'.format(self.status)) + # Only update cooling level if thermal algorithm status changed + if status_changed: + if self.status: + # Check thermal zone temperature, if all thermal zone temperature + # back to normal, set it to minimum allowed speed to + # save power + UpdateCoolingLevelToMinAction.update_cooling_level_to_minimum(thermal_info_dict) + + logger.log_info('Changed thermal algorithm status to {}'.format(self.status)) class ChangeMinCoolingLevelAction(ThermalPolicyActionBase): @@ -174,8 +174,6 @@ def execute(self, thermal_info_dict): Fan.set_cooling_level(Fan.min_cooling_level, current_cooling_level) UpdateCoolingLevelToMinAction.update_cooling_level_to_minimum(thermal_info_dict) - logger.log_info('Changed minimum cooling level to {}'.format(Fan.min_cooling_level)) - class UpdatePsuFanSpeedAction(ThermalPolicyActionBase): def execute(self, thermal_info_dict):