Skip to content

Commit 04aae60

Browse files
Junchao-Mellanoxskbarista
authored andcommitted
[Mellanox] add more log while doing sysfs reading (sonic-net#11556)
- Why I did it Add more log while doing sysfs reading to increase the debug capability - How I did it Log the relevant file path and error number while sysfs reading return None - How to verify it Manual test
1 parent ef40f95 commit 04aae60

File tree

1 file changed

+9
-1
lines changed
  • platform/mellanox/mlnx-platform-api/sonic_platform

1 file changed

+9
-1
lines changed

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616
#
17+
import ctypes
1718
import functools
1819
import subprocess
1920
import json
@@ -43,7 +44,14 @@ def read_from_file(file_path, target_type, default='', raise_exception=False, lo
4344
"""
4445
try:
4546
with open(file_path, 'r') as f:
46-
value = target_type(f.read().strip())
47+
value = f.read()
48+
if value is None:
49+
# None return value is not allowed in any case, so we log error here for further debug.
50+
logger.log_error('Failed to read from {}, value is None, errno is {}'.format(file_path, ctypes.get_errno()))
51+
# Raise ValueError for the except statement to handle this as a normal exception
52+
raise ValueError('File content of {} is None'.format(file_path))
53+
else:
54+
value = target_type(value.strip())
4755
except (ValueError, IOError) as e:
4856
if log_func:
4957
log_func('Failed to read from file {} - {}'.format(file_path, repr(e)))

0 commit comments

Comments
 (0)