Skip to content

Commit 203e42f

Browse files
authored
[Mellanox] Query PSU fan speed only on presence (sonic-net#21593)
- Why I did it The PsuFan in Mellanox platform queries for fan speed even though the relevant sysfs files do not exist. In psud the speed is already overwritten on presence, since the current implementation generates an error log, it is changed to query speed only on PSU presence and return 0 if there is no presence (Previously returned default value) - How I did it Check presence using get_presence api and return fan speed only if it returns True
1 parent d83b104 commit 203e42f

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

platform/mellanox/mlnx-platform-api/sonic_platform/fan.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#
2-
# Copyright (c) 2019-2023 NVIDIA CORPORATION & AFFILIATES.
3-
# Apache-2.0
2+
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
3+
# Copyright (c) 2019-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0
45
#
56
# Licensed under the Apache License, Version 2.0 (the "License");
67
# you may not use this file except in compliance with the License.
@@ -256,6 +257,11 @@ def set_speed(self, speed):
256257
logger.log_error('Failed to set PSU FAN speed - {}'.format(e))
257258
return False
258259

260+
def get_speed(self):
261+
if not self.get_presence():
262+
logger.log_notice(f"No PSU presence detected, returning default value for {self._name}")
263+
return 0
264+
return super().get_speed()
259265

260266
class Fan(MlnxFan):
261267
"""Platform-specific Fan class"""

platform/mellanox/mlnx-platform-api/tests/test_fan_api.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#
2-
# Copyright (c) 2020-2023 NVIDIA CORPORATION & AFFILIATES.
3-
# Apache-2.0
2+
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
3+
# Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0
45
#
56
# Licensed under the Apache License, Version 2.0 (the "License");
67
# you may not use this file except in compliance with the License.
@@ -14,6 +15,7 @@
1415
# See the License for the specific language governing permissions and
1516
# limitations under the License.
1617
#
18+
1719
import os
1820
import pytest
1921
import subprocess
@@ -155,3 +157,8 @@ def mock_read_str_from_file(file_path, default='', raise_exception=False):
155157
subprocess.check_call = MagicMock()
156158
utils.read_str_from_file = MagicMock(side_effect=RuntimeError(''))
157159
assert not fan.set_speed(60)
160+
fan.get_presence = MagicMock(return_value=False)
161+
assert fan.get_speed() == 0
162+
fan.get_presence = MagicMock(return_value=True)
163+
utils.read_int_from_file = MagicMock(return_value=60)
164+
assert fan.get_speed() == 100

0 commit comments

Comments
 (0)