feat: Added support for TLV_CODE_VENDOR_NAME#542
feat: Added support for TLV_CODE_VENDOR_NAME#542gupurush wants to merge 2 commits intosonic-net:masterfrom
Conversation
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
| return t[2].decode("ascii") | ||
|
|
||
|
|
||
| def vendorstr(self, e): |
There was a problem hiding this comment.
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Hey @FengPan-Frank , please help review |
|
@yaqiangz Appreciate your help in reviewing this PR. |
There was a problem hiding this comment.
Pull request overview
Adds decoding support for the EEPROM TLV “Vendor Name” field (TLV code 0x2D) in TlvInfoDecoder, along with a new v2 EEPROM hex fixture and an accompanying unit test to validate Vendor Name decoding.
Changes:
- Added
vendorstr()API toTlvInfoDecoderto decode TLV code0x2Das an ASCII string. - Added a new EEPROM hex fixture (
syseeprom_v2.hex) that includes Vendor Name TLV data. - Extended unit tests to generate a v2 mock EEPROM blob and assert Vendor Name decoding.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
sonic_platform_base/sonic_eeprom/eeprom_tlvinfo.py |
Adds vendorstr() accessor for Vendor Name TLV decoding. |
tests/eeprom_base_test.py |
Creates v2 mock EEPROM file and adds assertions for Vendor Name. |
tests/syseeprom_v2.hex |
New test fixture EEPROM hex containing Vendor Name TLV. |
| ''' | ||
| (is_valid, t) = self.get_tlv_field(e, self._TLV_CODE_VENDOR_NAME) | ||
| if not is_valid: | ||
| return super(TlvInfoDecoder, self).vendorstr(e) |
There was a problem hiding this comment.
vendorstr() falls back to super(...).vendorstr(e) when the TLV isn't present, but the base EepromDecoder/parent classes don't define vendorstr. This will raise AttributeError for EEPROMs that don't include _TLV_CODE_VENDOR_NAME. Consider returning a safe default (e.g., empty string) when the TLV is missing, or add a vendorstr() implementation to the parent class that returns a default value.
| return super(TlvInfoDecoder, self).vendorstr(e) | |
| # Parent class does not define vendorstr(); return a safe default | |
| return "" |
| @@ -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]) | |||
There was a problem hiding this comment.
The new v2 EEPROM fixture is consumed via xxd without verifying the file exists first. Adding an explicit os.path.exists(EEPROM_HEX_FILE_V2) assertion (similar to the existing v1 check) would produce a clearer test failure than xxd's CalledProcessError if the fixture is missing or misnamed.
| 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_FULL_PATH, EEPROM_SYMLINK_FULL_PATH]) | |
| if not os.path.exists(EEPROM_HEX_FILE_V2): | |
| assert False, "File {} is not exist".format(EEPROM_HEX_FILE_V2) |
| @@ -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') | |||
There was a problem hiding this comment.
There is coverage for the happy path where Vendor Name TLV exists, but no test exercises vendorstr() behavior when the TLV is absent (e.g., using the existing v1 syseeprom.hex). After fixing the fallback behavior, consider adding an assertion in test_eeprom_tlvinfo_read_api for the expected default (empty string/None/etc.) to prevent regressions.
| 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') |
There was a problem hiding this comment.
The PR description references dhclient.conf.j2 changes for DHCP option 60/61, but this repository/PR only appears to update the EEPROM TLV decoder and tests (no dhclient.conf.j2 present/modified here). Consider updating the PR description to match the actual scope of this repo change, or link to the other PRs where the DHCP config changes live.
Description
Required PRs:
sonic-net/sonic-utilities#3765
sonic-net/sonic-buildimage#21722
Logs: