Skip to content

[config] Support interface ranges with --from and --to - #4822

Draft
dlanov wants to merge 1 commit into
sonic-net:masterfrom
dlanov:fix-interface-range-790
Draft

[config] Support interface ranges with --from and --to#4822
dlanov wants to merge 1 commit into
sonic-net:masterfrom
dlanov:fix-interface-range-790

Conversation

@dlanov

@dlanov dlanov commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

[config] Support interface ranges with --from and --to

What I did

Added --from and --to options to config interface startup and config interface shutdown to operate on an inclusive range of configured physical interfaces.

This implements the syntax suggested in #790 while preserving the existing positional single-interface, comma-list, and dash-range behavior.

Examples:

config interface shutdown --from Ethernet0 --to Ethernet40
config interface startup --from Ethernet0 --to Ethernet40

How I did it

  • Added --from / --to options to config interface startup and shutdown.
  • Selected the range from interfaces actually present in the PORT table.
  • Used natural ordering so sparse interface numbering is handled correctly.
  • Resolved --from and --to endpoints individually in interface alias mode.
  • Preserved the existing multi-ASIC range restriction.
  • Added validation for incomplete, reversed, missing-endpoint, and mixed positional/range input.
  • Updated doc/Command-Reference.md.
  • Added unit coverage for success and validation paths.

For example, if configured ports are:

Ethernet0
Ethernet4
Ethernet8
...
Ethernet40

then --from Ethernet0 --to Ethernet40 operates only on those configured ports and does not generate nonexistent interfaces such as Ethernet1, Ethernet2, or Ethernet3.

How to verify it

Local validation completed successfully:

python3 -m py_compile config/main.py tests/config_test.py
git diff --check

Targeted unit tests were added to tests/config_test.py.

The full unit test environment requires SONiC-specific dependencies such as sonic_py_common and swsscommon, which are not available in the local WSL environment. The PR CI environment can run the complete dependency-backed checks.

Previous command output

Existing positional syntax remains unchanged, for example:

config interface shutdown Ethernet0
config interface startup Ethernet0
config interface shutdown Ethernet8,Ethernet16-20,Ethernet32
config interface startup Ethernet8,Ethernet16-20,Ethernet32

New command output

New range syntax:

config interface shutdown --from Ethernet0 --to Ethernet40
config interface startup --from Ethernet0 --to Ethernet40

Fixes #790

Signed-off-by: Dennis Lanov <dennis.lanov@gmail.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

@mssonicbld

Copy link
Copy Markdown
Collaborator

Hi, there are workflow run(s) waiting for approval, you may be first-time contributor. I will notify maintainers to help approve once PR is approved. Thanks!

---Powered by SONiC BuildBot

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.

Extend config interface shutdown/startup to accept a range of interfaces

2 participants