Skip to content

SFPUtil Loopback: Assume zero subport value when subport is not present in port config#4589

Open
abhi-nexthop wants to merge 1 commit into
sonic-net:masterfrom
nexthop-ai:abhi.assume_zero_lanemask
Open

SFPUtil Loopback: Assume zero subport value when subport is not present in port config#4589
abhi-nexthop wants to merge 1 commit into
sonic-net:masterfrom
nexthop-ai:abhi.assume_zero_lanemask

Conversation

@abhi-nexthop

Copy link
Copy Markdown
Contributor

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)

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Abhi Singh <abhi@nexthop.ai>
@abhi-nexthop abhi-nexthop force-pushed the abhi.assume_zero_lanemask branch from 354695d to 4eca463 Compare June 4, 2026 17:37
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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() to 0 when the subport field is absent or empty, instead of exiting.
  • Update sfputil debug loopback unit 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 thread tests/sfp_test.py
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 == '':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants