[Mellanox] Redirect ethtool stderr to subprocess for better error log (#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
This commit is contained in:
Junchao-Mellanox 2022-09-15 01:41:43 +08:00 committed by GitHub
parent c674b3c634
commit 9750cb48c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -359,7 +359,8 @@ class SFP(NvidiaSFPCommon):
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:
@ -367,6 +368,7 @@ class SFP(NvidiaSFPCommon):
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))