From c7ab742435ab5fca000382aadc268b020f16309e Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Thu, 14 Dec 2017 22:54:02 +0000 Subject: [PATCH 1/2] [Dell S6100]: EEPROM plugin overrides serial_number_str() to return service tag instead of serial number --- .../x86_64-dell_s6100_c2538-r0/plugins/eeprom.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/device/dell/x86_64-dell_s6100_c2538-r0/plugins/eeprom.py b/device/dell/x86_64-dell_s6100_c2538-r0/plugins/eeprom.py index 6af56578c682..393f174cf9e7 100644 --- a/device/dell/x86_64-dell_s6100_c2538-r0/plugins/eeprom.py +++ b/device/dell/x86_64-dell_s6100_c2538-r0/plugins/eeprom.py @@ -21,3 +21,17 @@ def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/class/i2c-adapter/i2c-2/2-0050/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) + def serial_number_str(self, e): + """Return Service Tag instead of serial number""" + + if self._TLV_HDR_ENABLED: + tlv_no_header = e[self._TLV_INFO_HDR_LEN:] if self._TLV_HDR_ENABLED else e + + (is_valid, t) = self.get_tlv_index(tlv_no_header, self._TLV_CODE_SERVICE_TAG) + + if not is_valid: + return "Bad service tag" + + t = tlv_no_header[t:] + + return t[2:2 + ord(t[1])] From 7872c0330941c720966724668bb18d8f22b48076 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Thu, 14 Dec 2017 23:09:48 +0000 Subject: [PATCH 2/2] Refactor to simplify --- .../x86_64-dell_s6100_c2538-r0/plugins/eeprom.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/device/dell/x86_64-dell_s6100_c2538-r0/plugins/eeprom.py b/device/dell/x86_64-dell_s6100_c2538-r0/plugins/eeprom.py index 393f174cf9e7..7265b90efb1f 100644 --- a/device/dell/x86_64-dell_s6100_c2538-r0/plugins/eeprom.py +++ b/device/dell/x86_64-dell_s6100_c2538-r0/plugins/eeprom.py @@ -22,16 +22,12 @@ def __init__(self, name, path, cpld_root, ro): super(board, self).__init__(self.eeprom_path, 0, '', True) def serial_number_str(self, e): - """Return Service Tag instead of serial number""" + """Return service tag instead of serial number""" - if self._TLV_HDR_ENABLED: - tlv_no_header = e[self._TLV_INFO_HDR_LEN:] if self._TLV_HDR_ENABLED else e - - (is_valid, t) = self.get_tlv_index(tlv_no_header, self._TLV_CODE_SERVICE_TAG) - - if not is_valid: + (is_valid, results) = self.get_tlv_field(e, self._TLV_CODE_SERVICE_TAG) + if is_valid == False: return "Bad service tag" - t = tlv_no_header[t:] - - return t[2:2 + ord(t[1])] + # 'results' is a list containing 3 elements, type (int), length (int), + # and value (string) of the requested TLV + return results[2]