From 9fe128c8e8bb44fa9959c482116541ce64b87486 Mon Sep 17 00:00:00 2001 From: Xin Wang Date: Wed, 23 Feb 2022 10:33:34 +0800 Subject: [PATCH] Fix issue of parsing syseeprom value with whitespace in middle (#10021) Fixes #10020 Why I did it The platform api for parsing syseeprom information read from STATE DB has issue with parsing the value part that has whitespace in the middle. The current code assumes that the value part does not have whitespace. So everything after the whitespace will be ignored. The syseeprom values returned from platform API do not match the output of "show platform syseeprom". How I did it This change improved the regular expression for parsing syseeprom values to accommodate whitespaces in the value. How to verify it Locally updated the code on a dx010 device. Call the platform API: ``` >>> import sonic_platform >>> platform = sonic_platform.platform.Platform() >>> chassis = platform.get_chassis() >>> chassis.get_system_eeprom_info() {'0x21': 'DX010', '0x22': 'R0872-F0020-02', '0x23': 'DX010B2F030A27BY200002', '0x24': '00:E0:EC:E7:71:0F', '0x25': '11/03/2020 21:22:56', '0x26': '3', '0x27': 'Seastone', '0x28': 'RANGELEY', '0x29': '2014.08', '0x2A': '131', '0x2B': 'CELESTICA', '0x2C': 'THA', '0x2D': 'Celestica', '0x2E': '1.0.5', '0x2F': 'LB', '0xFD': '', '0xFE': '0xAAB39BDB'} ``` Signed-off-by: Xin Wang --- .../services/platform_api/sonic_platform/eeprom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/broadcom/sonic-platform-modules-cel/services/platform_api/sonic_platform/eeprom.py b/platform/broadcom/sonic-platform-modules-cel/services/platform_api/sonic_platform/eeprom.py index 7756c0f2f8..1e06e7b80e 100644 --- a/platform/broadcom/sonic-platform-modules-cel/services/platform_api/sonic_platform/eeprom.py +++ b/platform/broadcom/sonic-platform-modules-cel/services/platform_api/sonic_platform/eeprom.py @@ -45,7 +45,7 @@ class Tlv(eeprom_tlvinfo.TlvInfoDecoder): for line in lines: try: match = re.search( - '(0x[0-9a-fA-F]{2})([\s]+[\S]+[\s]+)([\S]+)', line) + '(0x[0-9a-fA-F]{2})([\s]+[\S]+[\s]+)(.*$)', line) if match is not None: idx = match.group(1) value = match.group(3).rstrip('\0')