Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions sonic_platform_base/sonic_eeprom/eeprom_tlvinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,16 @@ def modelstr(self, e):
return super(TlvInfoDecoder, self).modelstr(e)

return t[2].decode("ascii")


def vendorstr(self, e):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests added as requested.

'''
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):
Expand Down
18 changes: 18 additions & 0 deletions tests/eeprom_base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions tests/syseeprom_v2.hex
Original file line number Diff line number Diff line change
@@ -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
Loading