diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py b/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py index fba2463619dd..a1c8691f3edf 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py @@ -1,6 +1,7 @@ # -# Copyright (c) 2019-2023 NVIDIA CORPORATION & AFFILIATES. -# Apache-2.0 +# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES +# Copyright (c) 2019-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -256,6 +257,11 @@ def set_speed(self, speed): logger.log_error('Failed to set PSU FAN speed - {}'.format(e)) return False + def get_speed(self): + if not self.get_presence(): + logger.log_notice(f"No PSU presence detected, returning default value for {self._name}") + return 0 + return super().get_speed() class Fan(MlnxFan): """Platform-specific Fan class""" 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 bb643f211e0a..52ab2aa73a15 100644 --- a/platform/mellanox/mlnx-platform-api/tests/test_fan_api.py +++ b/platform/mellanox/mlnx-platform-api/tests/test_fan_api.py @@ -1,6 +1,7 @@ # -# Copyright (c) 2020-2023 NVIDIA CORPORATION & AFFILIATES. -# Apache-2.0 +# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES +# Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,6 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # + import os import pytest import subprocess @@ -155,3 +157,8 @@ def mock_read_str_from_file(file_path, default='', raise_exception=False): subprocess.check_call = MagicMock() utils.read_str_from_file = MagicMock(side_effect=RuntimeError('')) assert not fan.set_speed(60) + fan.get_presence = MagicMock(return_value=False) + assert fan.get_speed() == 0 + fan.get_presence = MagicMock(return_value=True) + utils.read_int_from_file = MagicMock(return_value=60) + assert fan.get_speed() == 100