Skip to content

Commit

Permalink
[Mellanox] add more log while doing sysfs reading (#11556)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Junchao-Mellanox authored and yxieca committed Aug 8, 2022
1 parent 34a20c4 commit bc300b4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion platform/mellanox/mlnx-platform-api/sonic_platform/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import ctypes
import functools
import subprocess
import json
Expand Down Expand Up @@ -43,7 +44,14 @@ def read_from_file(file_path, target_type, default='', raise_exception=False, lo
"""
try:
with open(file_path, 'r') as f:
value = target_type(f.read().strip())
value = f.read()
if value is None:
# None return value is not allowed in any case, so we log error here for further debug.
logger.log_error('Failed to read from {}, value is None, errno is {}'.format(file_path, ctypes.get_errno()))
# Raise ValueError for the except statement to handle this as a normal exception
raise ValueError('File content of {} is None'.format(file_path))
else:
value = target_type(value.strip())
except (ValueError, IOError) as e:
if log_func:
log_func('Failed to read from file {} - {}'.format(file_path, repr(e)))
Expand Down

0 comments on commit bc300b4

Please sign in to comment.