Skip to content

Commit

Permalink
[Mellanox] Query PSU fan speed only on presence (#21593)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
gpunathilell authored Feb 11, 2025
1 parent d83b104 commit 203e42f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 8 additions & 2 deletions platform/mellanox/mlnx-platform-api/sonic_platform/fan.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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"""
Expand Down
11 changes: 9 additions & 2 deletions platform/mellanox/mlnx-platform-api/tests/test_fan_api.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -14,6 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

import os
import pytest
import subprocess
Expand Down Expand Up @@ -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

0 comments on commit 203e42f

Please # to comment.