Fix show int transceiver EEPROM crash for for Backplane cartridge + enhance EEPROM CLI output#4020
Conversation
…nhance EEPROM CLI output Signed-off-by: Mihir Patel <patelmi@microsoft.com>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@az-pz Can you please help in reviewing this? |
<!-- Provide a general summary of your changes in the Title above -->
#### Description
<!--
Describe your changes in detail
-->
This PR updates the `get_transceiver_info()` API in the CMIS module to remove fields from the returned `XCVR_INFO` dictionary that are dependent on the active application ID. These fields include:
- host_electrical_interface
- media_interface_code
- host_lane_assignment_option
- media_lane_assignment_option
#### Motivation and Context
<!--
Why is this change required? What problem does it solve?
If this pull request closes/resolves an open Issue, make sure you
include the text "fixes #xxxx", "closes #xxxx" or "resolves #xxxx" here
-->
These fields are only meaningful when the active application ID is explicitly shown. Including them without context can lead to confusion or misinterpretation of transceiver capabilities. This change ensures the API response reflects only valid and context-aware data.
#### How Has This Been Tested?
<!--
Please describe in detail how you tested your changes.
Include details of your testing environment, and the tests you ran to
see how your change affects other areas of the code, etc.
-->
Please refer to the test section of sonic-net/sonic-utilities#4020
#### Additional Information (Optional)
MSFT ADO - 34325583
…593) <!-- Provide a general summary of your changes in the Title above --> #### Description <!-- Describe your changes in detail --> This PR updates the `get_transceiver_info()` API in the CMIS module to remove fields from the returned `XCVR_INFO` dictionary that are dependent on the active application ID. These fields include: - host_electrical_interface - media_interface_code - host_lane_assignment_option - media_lane_assignment_option #### Motivation and Context <!-- Why is this change required? What problem does it solve? If this pull request closes/resolves an open Issue, make sure you include the text "fixes #xxxx", "closes #xxxx" or "resolves #xxxx" here --> These fields are only meaningful when the active application ID is explicitly shown. Including them without context can lead to confusion or misinterpretation of transceiver capabilities. This change ensures the API response reflects only valid and context-aware data. #### How Has This Been Tested? <!-- Please describe in detail how you tested your changes. Include details of your testing environment, and the tests you ran to see how your change affects other areas of the code, etc. --> Please refer to the test section of sonic-net/sonic-utilities#4020 #### Additional Information (Optional) MSFT ADO - 34325583
utilities_common/sfp_helper.py
Outdated
| return QSFP_DATA_MAP # Default fallback | ||
|
|
||
| is_sfp_cmis = is_transceiver_cmis(sfp_info_dict) | ||
| is_sfp_c_cmis = 'supported_max_tx_power' in sfp_info_dict |
There was a problem hiding this comment.
@mihirpat1 use optoe API is_coherent_module() ?
There was a problem hiding this comment.
@prgeor I think invoking the is_coherent_module API may not be the ideal thing to do since is_coherent_module API accesses the transceiver EEPROM directly. However, the current caller of get_transceiver_data_map API is meant to retrieve data from the redis-db rather than accessing the transceiver EEPROM directly.
There was a problem hiding this comment.
@mihirpat1 in that case should we define is_transceiver_coherent(sfp_dict) ? And use that?
prgeor
left a comment
There was a problem hiding this comment.
@mihirpat1 can you check the copilot review comments?
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a crash in the show interface transceiver eeprom command when dealing with Backplane cartridge modules and enhances EEPROM CLI output consistency between sfputil and sfpshow commands.
- Fixed KeyError crash for Backplane cartridge modules by using dynamic field iteration instead of hardcoded data maps
- Created shared utility functions for consistent field ordering and transceiver type detection
- Improved code maintainability by eliminating duplicate sorting logic between CLI utilities
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| utilities_common/sfp_helper.py | Added shared utility functions for transceiver type detection and consistent field sorting |
| sfputil/main.py | Updated to use shared utilities and dynamic field iteration to prevent KeyError crashes |
| scripts/sfpshow | Updated to use shared utilities and handle unknown fields gracefully |
| tests/sfputil_test.py | Updated test expectations for new field ordering and output format |
| tests/sfp_test.py | Updated test expectations for additional fields in output |
| tests/mock_tables/state_db.json | Updated mock data to reflect new field handling |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Cherry-pick PR to 202505: #4032 |
…nhance EEPROM CLI output (sonic-net#4020) * Fix show int transceiver EEPROM crash for for Backplane cartridge + enhance EEPROM CLI output Signed-off-by: Mihir Patel <patelmi@microsoft.com> * Fixed SA warning * Added None check for sfp_firmware_info_dict * Added is_transceiver_c_cmis * Added new line before get_data_map_sort_key --------- Signed-off-by: Mihir Patel <patelmi@microsoft.com>
Summary
This PR fixes a crash in the
show interface transceiver eepromcommand when dealing with Backplane cartridge modules and enhances the overall EEPROM CLI (show + sfputil) output consistency and organization.This change should be merged along with sonic-net/sonic-platform-common#590
Following traceback is seen with the Backplane cartridge cables. Hence, we need to resolve the traceback.
🐛 Primary Bug Fix
show interface transceiver eepromcommand would crash when processing Backplane cartridge transceivers🚀 EEPROM CLI Enhancements
Code Refactoring & Shared Utilities
utilities_common/sfp_helper.py:get_data_map_sort_key(): Provides consistent sorting logic for SFP info keysget_transceiver_data_map(): Automatically selects appropriate data map based on transceiver typeImproved Field Organization
sfputilandsfpshownow display transceiver fields in logical, sorted orderCode Quality Improvements
🧪 Testing
Field differences between nightly (left) and current changes (right) for CLI output of different types of transceivers
(the red and greyed out portion depict differences)
show int transceiver info CLI
sfputil show eeprom CLI

show int transceiver info CLI
sfputil show eeprom CLI

show int transceiver info CLI
sfputil show eeprom CLI

show int transceiver info CLI
sfputil show eeprom CLI

show int transceiver info CLI
sfputil show eeprom CLI

show int transceiver info CLI
sfputil show eeprom CLI

show int transceiver info CLI
sfputil show eeprom CLI
