-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[Mellnox] Add support for liquid cooling of mellnox platform api #24125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yuazhe
wants to merge
8
commits into
sonic-net:master
Choose a base branch
from
yuazhe:master_lc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9477789
Add support for liquid cooling of mellnox api
yuazhe e065786
Merge branch 'master' into master_lc
judyjoseph eff6984
Merge branch 'master' into master_lc
judyjoseph 5c049fc
Merge branch 'master' into master_lc
judyjoseph 17d98c4
Merge branch 'master' into master_lc
liat-grozovik becd1dc
Fix the header time as the file is new
yuazhe 9bcd808
Merge branch 'master' into master_lc
yuazhe fed4843
Merge branch 'master' into master_lc
yuazhe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
platform/mellanox/mlnx-platform-api/sonic_platform/liquid_cooling.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # | ||
| # SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES | ||
| # Copyright (c) 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. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| ############################################################################# | ||
| # Mellanox | ||
| # | ||
| # Module contains an implementation of SONiC Platform Base API and | ||
| # provides the liquid cooling status which are available in the platform | ||
| # | ||
| ############################################################################# | ||
|
|
||
| try: | ||
| from sonic_platform_base.liquid_cooling_base import LeakageSensorBase,LiquidCoolingBase | ||
| from sonic_py_common.logger import Logger | ||
| from . import utils | ||
| import os | ||
| import glob | ||
| import logging | ||
| except ImportError as e: | ||
| raise ImportError(str(e) + "- required module not found") | ||
|
|
||
| logging.basicConfig(level=logging.DEBUG) | ||
| logger = logging.getLogger(__name__) | ||
|
|
||
| LIQUID_COOLING_SENSOR_PATH = "/var/run/hw-management/system/" | ||
|
|
||
| class LeakageSensor(LeakageSensorBase): | ||
| def __init__(self, name,path): | ||
| super(LeakageSensor, self).__init__(name) | ||
| self.path = path | ||
|
|
||
| def is_leak(self): | ||
| content = utils.read_int_from_file(self.path, 'N/A') | ||
|
|
||
| if content == 1: | ||
| self.leaking = False | ||
| return False | ||
| elif content == 0: | ||
| self.leaking = True | ||
| return True | ||
| else: | ||
| logger.error(f"Failed to read leakage sensor {self.name} value: {content}") | ||
| return 'N/A' | ||
|
|
||
| class LiquidCooling(LiquidCoolingBase): | ||
| """Platform-specific Liquid Cooling class""" | ||
|
|
||
| def __init__(self): | ||
|
|
||
| self.leakage_sensors_num = utils.read_int_from_file("/var/run/hw-management/config/leakage_counter") | ||
| self.leakage_sensors = [] | ||
|
|
||
| sensor_files = glob.glob(os.path.join(LIQUID_COOLING_SENSOR_PATH, "leakage*")) | ||
| sensor_files.sort(key=lambda x: int(x.split("leakage")[-1])) | ||
|
|
||
| for sensor_path in sensor_files[:self.leakage_sensors_num]: | ||
| sensor_name = os.path.basename(sensor_path) | ||
| self.leakage_sensors.append(LeakageSensor(sensor_name, sensor_path)) | ||
|
|
||
| super(LiquidCooling, self).__init__(self.leakage_sensors_num, self.leakage_sensors) | ||
|
|
55 changes: 55 additions & 0 deletions
55
platform/mellanox/mlnx-platform-api/tests/test_liquid_cooling.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import os | ||
| import sys | ||
| from unittest import mock | ||
| from sonic_platform.liquid_cooling import LiquidCooling, LeakageSensor | ||
| from sonic_platform.utils import read_int_from_file | ||
|
|
||
| def test_leakage_sensor_init(): | ||
| sensor = LeakageSensor("leakage1", "/test/path") | ||
| assert sensor.name == "leakage1" | ||
| assert sensor.path == "/test/path" | ||
|
|
||
| def test_leakage_sensor_is_leak(): | ||
| sensor = LeakageSensor("leakage1", "/test/path") | ||
|
|
||
| # Test when file exists and content is "1" (no leak) | ||
| with mock.patch('os.path.exists') as mock_exists: | ||
| with mock.patch('builtins.open', mock.mock_open(read_data="1")): | ||
| mock_exists.return_value = True | ||
| assert sensor.is_leak() is False | ||
|
|
||
| # Test when file exists and content is "0" (leak detected) | ||
| with mock.patch('os.path.exists') as mock_exists: | ||
| with mock.patch('builtins.open', mock.mock_open(read_data="0")): | ||
| mock_exists.return_value = True | ||
| assert sensor.is_leak() is True | ||
|
|
||
| # Test when file does not exist | ||
| with mock.patch('os.path.exists') as mock_exists: | ||
| mock_exists.return_value = False | ||
| assert sensor.is_leak() == 'N/A' | ||
|
|
||
| def test_liquid_cooling_init(): | ||
| with mock.patch('os.path.exists') as mock_exists, \ | ||
| mock.patch('os.path.join', side_effect=lambda *args: "/".join(args)) as mock_join, \ | ||
| mock.patch('glob.glob') as mock_glob, \ | ||
| mock.patch('sonic_platform.utils.read_int_from_file', return_value=4) as mock_read_int: | ||
|
|
||
| # Setup mock to simulate 4 leakage sensors | ||
| mock_exists.side_effect = [True, True, True, True] | ||
| mock_glob.return_value = [ | ||
| "/var/run/hw-management/system/leakage1", | ||
| "/var/run/hw-management/system/leakage2", | ||
| "/var/run/hw-management/system/leakage3", | ||
| "/var/run/hw-management/system/leakage4" | ||
| ] | ||
|
|
||
| liquid_cooling = LiquidCooling() | ||
|
|
||
| # Verify the number of sensors initialized | ||
| assert liquid_cooling.get_num_leak_sensors() == 4 | ||
|
|
||
|
|
||
| with mock.patch.object(liquid_cooling.leakage_sensors[3], 'is_leak', return_value=False) as mock_sensor1: | ||
| sensors = liquid_cooling.get_leak_sensor_status() | ||
| assert len(sensors) == 3 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.