Skip to content

Commit dc91229

Browse files
[Mellanox] support thermal sensor which has discrete index
1 parent 8e246d2 commit dc91229

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

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

+28-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#
2-
# Copyright (c) 2019-2024 NVIDIA CORPORATION & AFFILIATES.
2+
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
3+
# Copyright (c) 2019-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
34
# Apache-2.0
45
#
56
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,7 +27,9 @@
2627
from sonic_platform_base.thermal_base import ThermalBase
2728
from sonic_py_common.logger import Logger
2829
import copy
30+
import glob
2931
import os
32+
import re
3033

3134
from .device_data import DeviceDataManager
3235
from . import utils
@@ -133,7 +136,9 @@
133136
"temperature": "sodimm{}_temp_input",
134137
"high_threshold": "sodimm{}_temp_max",
135138
"high_critical_threshold": "sodimm{}_temp_crit",
136-
"type": "indexable",
139+
"search_pattern": '/run/hw-management/thermal/sodimm*_temp_input',
140+
'index_pattern': r'sodimm(\d+)_temp_input',
141+
"type": "discrete",
137142
}
138143
],
139144
'linecard thermals': {
@@ -153,21 +158,22 @@ def initialize_chassis_thermals():
153158
rules = THERMAL_NAMING_RULE['chassis thermals']
154159
position = 1
155160
for rule in rules:
156-
if 'type' in rule and rule['type'] == 'indexable':
161+
thermal_type = rule.get('type')
162+
if thermal_type == 'indexable':
157163
count = 0
158164
if 'Gearbox' in rule['name']:
159165
count = DeviceDataManager.get_gearbox_count('/run/hw-management/config')
160166
elif 'CPU Core' in rule['name']:
161167
count = DeviceDataManager.get_cpu_thermal_count()
162-
elif 'SODIMM' in rule['name']:
163-
count = DeviceDataManager.get_sodimm_thermal_count()
164168
if count == 0:
165169
logger.log_debug('Failed to get thermal object count for {}'.format(rule['name']))
166170
continue
167171

168172
for index in range(count):
169173
thermal_list.append(create_indexable_thermal(rule, index, CHASSIS_THERMAL_SYSFS_FOLDER, position))
170174
position += 1
175+
elif thermal_type == 'discrete':
176+
thermal_list.extend(create_discrete_thermal(rule))
171177
else:
172178
thermal_object = create_single_thermal(rule, CHASSIS_THERMAL_SYSFS_FOLDER, position)
173179
if thermal_object:
@@ -274,6 +280,23 @@ def create_single_thermal(rule, sysfs_folder, position, presence_cb=None):
274280
return RemovableThermal(name, temp_file, high_th_file, high_crit_th_file, high_th_default, high_crit_th_default, scale, position, presence_cb)
275281

276282

283+
def create_discrete_thermal(rule):
284+
search_pattern = rule.get('search_pattern')
285+
index_pattern = rule.get('index_pattern')
286+
position = 1
287+
thermal_list = []
288+
for file_path in glob.iglob(search_pattern):
289+
file_name = os.path.basename(file_path)
290+
match = re.search(index_pattern, file_name)
291+
if not match:
292+
logger.log_error(f'Failed to extract index from {file_name} using pattern {index_pattern}')
293+
continue
294+
index = int(match.group(1))
295+
thermal_list.append(create_indexable_thermal(rule, index - 1, CHASSIS_THERMAL_SYSFS_FOLDER, position))
296+
position += 1
297+
return thermal_list
298+
299+
277300
def _check_thermal_sysfs_existence(file_path, presence_cb):
278301
if presence_cb:
279302
status, _ = presence_cb()

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#
2-
# Copyright (c) 2021-2023 NVIDIA CORPORATION & AFFILIATES.
2+
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
3+
# Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
34
# Apache-2.0
45
#
56
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -39,7 +40,9 @@ class TestThermal:
3940
@mock.patch('os.path.exists', mock.MagicMock(return_value=True))
4041
@mock.patch('sonic_platform.device_data.DeviceDataManager.get_gearbox_count', mock.MagicMock(return_value=2))
4142
@mock.patch('sonic_platform.device_data.DeviceDataManager.get_cpu_thermal_count', mock.MagicMock(return_value=2))
42-
@mock.patch('sonic_platform.device_data.DeviceDataManager.get_sodimm_thermal_count', mock.MagicMock(return_value=2))
43+
@mock.patch('sonic_platform.thermal.glob.iglob', mock.MagicMock(
44+
return_value=['/run/hw-management/thermal/sodimm1_temp_input',
45+
'/run/hw-management/thermal/sodimm2_temp_input']))
4346
@mock.patch('sonic_platform.device_data.DeviceDataManager.get_platform_name', mock.MagicMock(return_value='x86_64-mlnx_msn2700-r0'))
4447
def test_chassis_thermal(self):
4548
from sonic_platform.thermal import THERMAL_NAMING_RULE

0 commit comments

Comments
 (0)