Add support for get_power_override_support in sfp API#641
Add support for get_power_override_support in sfp API#641arista-hpandya wants to merge 1 commit intosonic-net:masterfrom
Conversation
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Signed-off-by: arista-hpandya <hpandya@arista.com>
317650c to
0bd88f3
Compare
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Adds a new SFP API method to query whether a module supports power override, to let callers check capability before invoking get_power_override() / set_power_override().
Changes:
- Introduces
get_power_override_support()onSfpBaseas part of the common SFP interface. - Implements
get_power_override_support()inSfpOptoeBaseby delegating to the underlyingxcvr_api.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
sonic_platform_base/sfp_base.py |
Adds the new SFP interface method for power-override support querying. |
sonic_platform_base/sonic_xcvr/sfp_optoe_base.py |
Implements the new method for optoe-based SFPs via get_xcvr_api() delegation. |
| Retrieves whether power override is supported by this SFP | ||
|
|
||
| Returns: | ||
| A Boolean, True if power-override is supported, False if not supported | ||
| """ | ||
| raise NotImplementedError |
There was a problem hiding this comment.
Adding a new method to SfpBase that raises NotImplementedError introduces a new required override for every downstream platform SFP implementation. This is a backwards-incompatible API change because callers can now hit a runtime exception on platforms that haven’t implemented the new method. Provide a safe default implementation (e.g., return False when unsupported) and document the default/unsupported behavior in the docstring so existing platforms don’t break.
| Retrieves whether power override is supported by this SFP | |
| Returns: | |
| A Boolean, True if power-override is supported, False if not supported | |
| """ | |
| raise NotImplementedError | |
| Retrieves whether power override is supported by this SFP. | |
| Returns: | |
| bool: True if power-override is supported, False if not supported. | |
| The default implementation returns False to indicate that | |
| power override is not supported unless overridden by a | |
| platform-specific implementation. | |
| """ | |
| return False |
|
|
||
| def get_power_override_support(self): | ||
| api = self.get_xcvr_api() | ||
| return api.get_power_override_support() if api is not None else None |
There was a problem hiding this comment.
This implementation returns None when get_xcvr_api() is unavailable, but the new SfpBase API contract describes a boolean return value. Consider returning False when api is None (treat as unsupported) or update the SfpBase docstring/contract to explicitly allow None for read/initialization failures, so callers can rely on a consistent type.
| return api.get_power_override_support() if api is not None else None | |
| return api.get_power_override_support() if api is not None else False |
Description
This PR introduces the get_power_override_support method to the SFP API within sonic-platform-common. Needed to address: sonic-net/sonic-buildimage#26372
sfp_base.py: Added the abstract method definition to the SfpBase class to define the interface.
sfp_optoe_base.py: Provided an implementation in SfpOptoeBase that delegates the call to the underlying transceiver API (xcvr_api).
This allows platform-specific implementations and upper-layer applications to query whether a specific SFP module supports power override capabilities before attempting to get or set override values.
Motivation and Context
Currently, while get_power_override and set_power_override exist, there isn't a standardized way to check for feature support across different hardware modules. This change improves the robustness of the SFP interface by allowing callers to verify support programmatically, preventing unnecessary errors or invalid calls on modules that do not support this feature.
This will help us move away from hardcoded functions like these that need constant maintenance: https://github.com/sonic-net/sonic-mgmt/blob/a1d1fd8717c4525055a3a4a9e3250232ee3b0d86/tests/platform_tests/api/test_sfp.py#L374-L378
How Has This Been Tested?
Verified by running the test_sfp sonic-mgmt tests to use this API
Additional Information (Optional)
NA