Skip to content

Add support for get_power_override_support in sfp API#641

Open
arista-hpandya wants to merge 1 commit intosonic-net:masterfrom
arista-hpandya:power_override_api
Open

Add support for get_power_override_support in sfp API#641
arista-hpandya wants to merge 1 commit intosonic-net:masterfrom
arista-hpandya:power_override_api

Conversation

@arista-hpandya
Copy link

@arista-hpandya arista-hpandya commented Mar 24, 2026

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

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: arista-hpandya <hpandya@arista.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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() on SfpBase as part of the common SFP interface.
  • Implements get_power_override_support() in SfpOptoeBase by delegating to the underlying xcvr_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.

Comment on lines +294 to +299
Retrieves whether power override is supported by this SFP

Returns:
A Boolean, True if power-override is supported, False if not supported
"""
raise NotImplementedError
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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

Copilot uses AI. Check for mistakes.

def get_power_override_support(self):
api = self.get_xcvr_api()
return api.get_power_override_support() if api is not None else None
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants