Skip to content

Add validation for malformed interface ranges#4575

Open
bgallagher-nexthop wants to merge 1 commit into
sonic-net:masterfrom
nexthop-ai:invalid-range
Open

Add validation for malformed interface ranges#4575
bgallagher-nexthop wants to merge 1 commit into
sonic-net:masterfrom
nexthop-ai:invalid-range

Conversation

@bgallagher-nexthop
Copy link
Copy Markdown

Fixes #4574.

What I did

It is possible to run sudo config interface startup Ethernet320-Ethernet376 or sudo config interface shutdown Ethernet320-Ethernet376 and the command will return silently without actually having done anything because the valid format for a range specifier is Ethernet320-376.

This PR adds validation to these CLI commands so that malformed range specifiers will cause the CLI to print an error message.

How I did it

I added logic to raise an exception when a malformed range specifier is provided by the user to the CLI.

How to verify it

Added unit-tests, manually tested below.

Previous command output (if the output of a command-line utility has changed)

Before the change:

admin@device:~$ show int stat Ethernet0-8
  Interface                   Lanes    Speed    MTU    FEC    Alias    Vlan    Oper    Admin    Type    Asym PFC
-----------  ----------------------  -------  -----  -----  -------  ------  ------  -------  ------  ----------
  Ethernet0  9,10,11,12,13,14,15,16     800G   9100     rs    Port1  routed    down       up     N/A         N/A
  Ethernet8         1,2,3,4,5,6,7,8     800G   9100     rs    Port2  routed    down       up     N/A         N/A
admin@device:~$ sudo config interface shutdown Ethernet0-Ethernet8
admin@device:~$ show int stat Ethernet0-8
  Interface                   Lanes    Speed    MTU    FEC    Alias    Vlan    Oper    Admin    Type    Asym PFC
-----------  ----------------------  -------  -----  -----  -------  ------  ------  -------  ------  ----------
  Ethernet0  9,10,11,12,13,14,15,16     800G   9100     rs    Port1  routed    down       up     N/A         N/A
  Ethernet8         1,2,3,4,5,6,7,8     800G   9100     rs    Port2  routed    down       up     N/A         N/A

New command output (if the output of a command-line utility has changed)

After the change:

admin@device:~$ sudo config interface shutdown Ethernet0-Ethernet8
Usage: config interface shutdown [OPTIONS] <interface_name>
Try 'config interface shutdown -h' for help.

Error: Invalid interface range 'Ethernet0-Ethernet8'. Expected a range like 'Ethernet0-3'.
admin@device:~$ sudo config interface startup Ethernet0-Ethernet8
Usage: config interface startup [OPTIONS] <interface_name>
Try 'config interface startup -h' for help.

Error: Invalid interface range 'Ethernet0-Ethernet8'. Expected a range like 'Ethernet0-3'.

@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: Brian Gallagher <bgallagher@nexthop.ai>
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@bgallagher-nexthop bgallagher-nexthop marked this pull request as ready for review May 29, 2026 18:46
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.

CLI commands allow malformed interface ranges

2 participants