diff --git a/sonic_platform_base/sonic_eeprom/eeprom_tlvinfo.py b/sonic_platform_base/sonic_eeprom/eeprom_tlvinfo.py index a044b7328..41af51c93 100644 --- a/sonic_platform_base/sonic_eeprom/eeprom_tlvinfo.py +++ b/sonic_platform_base/sonic_eeprom/eeprom_tlvinfo.py @@ -406,6 +406,16 @@ def modelstr(self, e): return super(TlvInfoDecoder, self).modelstr(e) return t[2].decode("ascii") + + + def vendorstr(self, e): + ''' + Returns the value field of the Vendor Name TLV as a string + ''' + (is_valid, t) = self.get_tlv_field(e, self._TLV_CODE_VENDOR_NAME) + if not is_valid: + return super(TlvInfoDecoder, self).vendorstr(e) + return t[2].decode("ascii") def serial_number_str(self, e): diff --git a/tests/eeprom_base_test.py b/tests/eeprom_base_test.py index da89e2b95..b9aa3fa61 100644 --- a/tests/eeprom_base_test.py +++ b/tests/eeprom_base_test.py @@ -9,6 +9,8 @@ TEST_PATH = os.path.dirname(os.path.abspath(__file__)) EEPROM_HEX_FILE_FULL_PATH = os.path.join(TEST_PATH, EEPROM_HEX_FILE) EEPROM_SYMLINK_FULL_PATH = os.path.join(TEST_PATH, EEPROM_SYMLINK) +EEPROM_HEX_FILE_V2 = os.path.join(TEST_PATH, "syseeprom_v2.hex") +EEPROM_SYMLINK_V2 = os.path.join(TEST_PATH, "vpd_info_v2") class TestEepromTlvinfo: @classmethod @@ -38,12 +40,15 @@ def setup_class(cls): if not os.path.exists(os.path.dirname(EEPROM_HEX_FILE_FULL_PATH)): assert False, "File {} is not exist".format(EEPROM_HEX_FILE_FULL_PATH) subprocess.check_call(['/usr/bin/xxd', '-r', '-p', EEPROM_HEX_FILE_FULL_PATH, EEPROM_SYMLINK_FULL_PATH]) + subprocess.check_call(['/usr/bin/xxd', '-r', '-p', EEPROM_HEX_FILE_V2, EEPROM_SYMLINK_V2]) @classmethod def teardown_class(cls): # Remove the mock eeprom after test if os.path.exists(os.path.dirname(EEPROM_HEX_FILE_FULL_PATH)): subprocess.check_call(['rm', '-f', EEPROM_SYMLINK_FULL_PATH]) + if os.path.exists(os.path.dirname(EEPROM_HEX_FILE_V2)): + subprocess.check_call(['rm', '-f', EEPROM_SYMLINK_V2]) def test_eeprom_tlvinfo_read_api(self): # Test using the api to fetch Base MAC, Switch Addr Range, Model, @@ -57,6 +62,19 @@ def test_eeprom_tlvinfo_read_api(self): assert(eeprom_class.serial_number_str(eeprom).rstrip('\0') == 'MT1623X09522') assert(eeprom_class.part_number_str(eeprom).rstrip('\0') == 'MSN2700-CS2FO') + def test_eeprom_tlvinfo_read_api_v2(self): + # Test using the updated api (addition of Vendor Name) to fetch Base MAC, Model, Vendor Name, + # Serial Number and Part Number. + eeprom_class = eeprom_tlvinfo.TlvInfoDecoder(EEPROM_SYMLINK_V2, 0, '', True) + eeprom = eeprom_class.read_eeprom() + eeprom_class.decode_eeprom(eeprom) + assert(eeprom_class.base_mac_addr(eeprom).rstrip('\0') == '34:73:2D:30:70:D8') + assert(eeprom_class.switchaddrrange(eeprom).rstrip('\0') == '516') + assert(eeprom_class.modelstr(eeprom).rstrip('\0') == '8102-64H-O') + assert(eeprom_class.vendorstr(eeprom).rstrip('\0') == 'Cisco') + assert(eeprom_class.serial_number_str(eeprom).rstrip('\0') == 'FLM251907U7') + assert(eeprom_class.part_number_str(eeprom).rstrip('\0') == 'ECI123') + def test_eeprom_tlvinfo_get_tlv_field(self): # Test getting fields by field code eeprom_class = eeprom_tlvinfo.TlvInfoDecoder(EEPROM_SYMLINK_FULL_PATH, 0, '', True) diff --git a/tests/syseeprom_v2.hex b/tests/syseeprom_v2.hex new file mode 100644 index 000000000..ded0e881c --- /dev/null +++ b/tests/syseeprom_v2.hex @@ -0,0 +1,7 @@ +54 6c 76 49 6e 66 6f 00 01 00 5e 22 06 45 43 49 +31 32 33 2a 02 02 04 23 0b 46 4c 4d 32 35 31 39 +30 37 55 37 21 0a 38 31 30 32 2d 36 34 48 2d 4f +26 01 00 24 06 34 73 2d 30 70 d8 28 14 78 38 36 +5f 36 34 2d 38 31 30 32 5f 36 34 68 5f 6f 2d 72 +30 2b 05 43 69 73 63 6f 2d 05 43 69 73 63 6f 2c +02 55 53 fe 04 e0 30 3f 8e \ No newline at end of file