Skip to content

Normalize NetBox interface speeds to Mbps at collection time#2479

Merged
ideaship merged 2 commits into
mainfrom
2478
Jul 17, 2026
Merged

Normalize NetBox interface speeds to Mbps at collection time#2479
ideaship merged 2 commits into
mainfrom
2478

Conversation

@berendt

@berendt berendt commented Jul 17, 2026

Copy link
Copy Markdown
Member

Summary

Fixes the broken SONiC breakout port speeds reported in #2478 (e.g. "speed": "100" with "valid_speeds": "100,10000,1000" on a 100G breakout of an Edgecore 9726-32DB).

netbox_interfaces mixed two units: explicitly set NetBox speeds are stored in kbps, while speeds derived from the interface type via get_speed_from_port_type are already Mbps. The kbps-to-Mbps division applied downstream in the breakout paths therefore turned a derived 100G breakout port (100000 Mbps) into "100". The regression window matches 1dbcb2b, which added the division to _add_missing_breakout_ports — the path breakout subports take on platforms whose port_config only lists master ports.

Changes

Config generation (config_generator.py):

  • Normalize the unit once at collection time in generate_sonic_config: explicit NetBox speeds (kbps) are converted to Mbps when netbox_interfaces is built, derived speeds pass through unchanged. The mapping now always carries Mbps.
  • Drop the three per-site // 1000 divisions in _add_port_configurations and _add_missing_breakout_ports.
  • Determine speed_explicit with bool() so an explicit speed of 0 is no longer labeled explicit while the value is actually derived from the port type.

Breakout detection (interface.py):

  • detect_breakout_ports compared raw NetBox speeds against Mbps constants, so interfaces with an explicitly set speed (kbps) could never match a breakout mode. The new get_interface_speed helper returns Mbps regardless of the source and is used at all four detection sites.

Tests:

  • Update the unit tests that encoded the mixed-unit behavior, model explicit NetBox speeds in kbps as NetBox stores them, and add coverage for the normalization, the get_interface_speed helper, and the 100G breakout scenario from the issue.

Closes #2478

🤖 Generated with Claude Code

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

berendt added 2 commits July 17, 2026 12:41
netbox_interfaces mixed two units: explicitly set NetBox speeds are
stored in kbps, while speeds derived from the interface type via
get_speed_from_port_type are already Mbps. The downstream kbps-to-Mbps
division in the breakout paths therefore turned a derived 100G breakout
port (100000 Mbps) into "100", producing an invalid SONiC port
configuration such as speed "100" with valid_speeds "100,10000,1000".

Convert explicit speeds to Mbps once when netbox_interfaces is built,
so the mapping always carries a single unit, and drop the per-site
divisions in _add_port_configurations and _add_missing_breakout_ports.
This also corrects speed_explicit for interfaces whose explicit speed
is 0, which were previously labeled explicit even though the value was
derived from the port type.

Closes #2478

Assisted-by: Claude:claude-fable-5
Signed-off-by: Christian Berendt <berendt@osism.tech>
The breakout detection in detect_breakout_ports compared raw NetBox
interface speeds against Mbps constants. Explicitly set NetBox speeds
are stored in kbps, so an interface with an explicit speed could never
match its breakout mode (e.g. 100 G = 100000000 kbps never equalled
100000), and only speeds derived from the interface type were detected
correctly.

Introduce get_interface_speed, which returns the interface speed in
Mbps regardless of the source (explicit kbps converted, port-type
derivation passed through unchanged), and use it at all four detection
sites. Update the detection tests to model explicit speeds in kbps as
NetBox stores them.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Christian Berendt <berendt@osism.tech>
@berendt berendt moved this from In progress to Ready for review in Human Board Jul 17, 2026
@berendt
berendt requested a review from ideaship July 17, 2026 10:58
@ideaship
ideaship merged commit 475f8f5 into main Jul 17, 2026
3 checks passed
@ideaship
ideaship deleted the 2478 branch July 17, 2026 11:15
@github-project-automation github-project-automation Bot moved this from Ready for review to Done in Human Board Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[bug] Generation of SONiC Config Breakout Port speed from Port Type fails

3 participants