SFPUtil Loopback: Assume zero subport value when subport is not present in port config#4589
Open
abhi-nexthop wants to merge 1 commit into
Open
SFPUtil Loopback: Assume zero subport value when subport is not present in port config#4589abhi-nexthop wants to merge 1 commit into
abhi-nexthop wants to merge 1 commit into
Conversation
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Signed-off-by: Abhi Singh <abhi@nexthop.ai>
354695d to
4eca463
Compare
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
prgeor
approved these changes
Jun 11, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates SONiC’s sfputil debug loopback path to avoid crashing when the subport field is omitted from the PORT entry in CONFIG_DB, by treating a missing/empty subport as 0 (use all lanes).
Changes:
- Default
get_subport()to0when thesubportfield is absent or empty, instead of exiting. - Update
sfputil debug loopbackunit test expectations to reflect non-crashing behavior when subport can’t be read. - Add unit test coverage for
get_subport()defaulting behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| utilities_common/platform_sfputil_helper.py | Changes get_subport() behavior to default to subport 0 when missing/empty. |
| tests/sfputil_test.py | Updates loopback CLI test to reflect new non-failing behavior when subport retrieval fails. |
| tests/sfp_test.py | Adds test cases verifying get_subport() defaults to 0 for missing/empty values. |
Comment on lines
+1363
to
+1366
| # A missing (None) or empty subport defaults to subport 0 instead of crashing | ||
| mock_get_value_from_db_by_field.return_value = None | ||
| assert get_subport("Ethernet0") == 0 | ||
|
|
Comment on lines
281
to
+285
|
|
||
| if subport is None: | ||
| click.echo(f"{port_name}: subport is not present in CONFIG_DB") | ||
| sys.exit(EXIT_FAIL) | ||
| elif subport == '': | ||
| # An absent or empty subport means the port is not breakout/split, so it | ||
| # occupies all lanes as subport 0. Default to 0 instead of bailing out so a | ||
| # missing subport does not crash loopback/output diagnostics. | ||
| if subport is None or subport == '': |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What I did
I removed the crash for sfputil when subport is missing. When missing, we should assume all lanes are used and subport should be set to zero
How I did it
By logging the missing subport entry instead and setting it to zero
How to verify it
sfputil debug loopback should now work even if the subport number is omitted
Previous command output (if the output of a command-line utility has changed)
New command output (if the output of a command-line utility has changed)