Skip to content

Commit

Permalink
[Mellanox] Redirect ethtool stderr to subprocess for better error log (
Browse files Browse the repository at this point in the history
…#12038)

- Why I did it
ethtool print error logs when EEPROM of a SFP is not available. It prints error like this:

INFO pmon#/supervisord: xcvrd Cannot get module EEPROM information: Input/output error
INFO pmon#/supervisord: xcvrd Cannot get Module EEPROM data: Invalid argument
However, this log does not contain the relevant SFP index which is hard for developer/qa to find the exactly SFP.

- How I did it
Redirect ethtool stderr to subprocess and log it better

- How to verify it
Manual test
  • Loading branch information
Junchao-Mellanox authored Sep 14, 2022
1 parent c674b3c commit 9750cb4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,16 @@ def _read_eeprom_specific_bytes(self, offset, num_bytes):
try:
output = subprocess.check_output(ethtool_cmd,
shell=True,
universal_newlines=True)
universal_newlines=True,
stderr=subprocess.PIPE)
output_lines = output.splitlines()
first_line_raw = output_lines[0]
if "Offset" in first_line_raw:
for line in output_lines[2:]:
line_split = line.split()
eeprom_raw = eeprom_raw + line_split[1:]
except subprocess.CalledProcessError as e:
logger.log_notice("Failed to get EEPROM data for sfp {}: {}".format(self.index, e.stderr))
return None

eeprom_raw = list(map(lambda h: int(h, base=16), eeprom_raw))
Expand Down

0 comments on commit 9750cb4

Please sign in to comment.