Skip to content

Commit 5a5aefd

Browse files
Fix error log while creating PSU thermal object
1 parent 6107b51 commit 5a5aefd

File tree

1 file changed

+12
-8
lines changed
  • platform/mellanox/mlnx-platform-api/sonic_platform

1 file changed

+12
-8
lines changed

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

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2019-2023 NVIDIA CORPORATION & AFFILIATES.
2+
# Copyright (c) 2019-2024 NVIDIA CORPORATION & AFFILIATES.
33
# Apache-2.0
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -220,15 +220,15 @@ def create_indexable_thermal(rule, index, sysfs_folder, position, presence_cb=No
220220
name = rule['name'].format(index)
221221
sysfs_folder = rule.get('sysfs_folder', sysfs_folder)
222222
temp_file = os.path.join(sysfs_folder, rule['temperature'].format(index))
223-
_check_thermal_sysfs_existence(temp_file)
223+
_check_thermal_sysfs_existence(temp_file, presence_cb)
224224
if 'high_threshold' in rule:
225225
high_th_file = os.path.join(sysfs_folder, rule['high_threshold'].format(index))
226-
_check_thermal_sysfs_existence(high_th_file)
226+
_check_thermal_sysfs_existence(high_th_file, presence_cb)
227227
else:
228228
high_th_file = None
229229
if 'high_critical_threshold' in rule:
230230
high_crit_th_file = os.path.join(sysfs_folder, rule['high_critical_threshold'].format(index))
231-
_check_thermal_sysfs_existence(high_crit_th_file)
231+
_check_thermal_sysfs_existence(high_crit_th_file, presence_cb)
232232
else:
233233
high_crit_th_file = None
234234
high_th_default = rule.get('high_threshold_default')
@@ -253,15 +253,15 @@ def create_single_thermal(rule, sysfs_folder, position, presence_cb=None):
253253

254254
sysfs_folder = rule.get('sysfs_folder', sysfs_folder)
255255
temp_file = os.path.join(sysfs_folder, temp_file)
256-
_check_thermal_sysfs_existence(temp_file)
256+
_check_thermal_sysfs_existence(temp_file, presence_cb)
257257
if 'high_threshold' in rule:
258258
high_th_file = os.path.join(sysfs_folder, rule['high_threshold'])
259-
_check_thermal_sysfs_existence(high_th_file)
259+
_check_thermal_sysfs_existence(high_th_file, presence_cb)
260260
else:
261261
high_th_file = None
262262
if 'high_critical_threshold' in rule:
263263
high_crit_th_file = os.path.join(sysfs_folder, rule['high_critical_threshold'])
264-
_check_thermal_sysfs_existence(high_crit_th_file)
264+
_check_thermal_sysfs_existence(high_crit_th_file, presence_cb)
265265
else:
266266
high_crit_th_file = None
267267
high_th_default = rule.get('high_threshold_default')
@@ -274,7 +274,11 @@ def create_single_thermal(rule, sysfs_folder, position, presence_cb=None):
274274
return RemovableThermal(name, temp_file, high_th_file, high_crit_th_file, high_th_default, high_crit_th_default, scale, position, presence_cb)
275275

276276

277-
def _check_thermal_sysfs_existence(file_path):
277+
def _check_thermal_sysfs_existence(file_path, presence_cb):
278+
if presence_cb:
279+
status, _ = presence_cb()
280+
if not status:
281+
return
278282
if not os.path.exists(file_path):
279283
logger.log_error('Thermal sysfs {} does not exist'.format(file_path))
280284

0 commit comments

Comments
 (0)