From 9750cb48c642281157ddd405674bdca9710e1edc Mon Sep 17 00:00:00 2001 From: Junchao-Mellanox <57339448+Junchao-Mellanox@users.noreply.github.com> Date: Thu, 15 Sep 2022 01:41:43 +0800 Subject: [PATCH] [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 --- platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py b/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py index 617b4f33d636..d373b6a8f705 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py @@ -359,7 +359,8 @@ 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: @@ -367,6 +368,7 @@ def _read_eeprom_specific_bytes(self, offset, num_bytes): 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))