Skip to content

Commit 7a3f4ad

Browse files
authored
Fix the interface name length validation for subinterface (#3799)
<!-- Please make sure you've read and understood our contributing guidelines: https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md failure_prs.log skip_prs.log Make sure all your commits include a signature generated with `git commit -s` ** If this is a bug fix, make sure your description includes "closes #xxxx", "fixes #xxxx" or "resolves #xxxx" so that GitHub automatically closes the related issue when the PR is merged. If you are adding/modifying/removing any command or utility script, please also make sure to add/modify/remove any unit tests from the tests directory as appropriate. If you are modifying or removing an existing 'show', 'config' or 'sonic-clear' subcommand, or you are adding a new subcommand, please make sure you also update the Command Line Reference Guide (doc/Command-Reference.md) to reflect your changes. Please provide the following information: --> #### What I did Subinterface name length validation validates only the interface alias and not the entire subinterface name. This will result in wrong validation. #### How I did it Fixed the validation to use subinterface name and not just interface alias. #### How to verify it Added test case to verify. #### 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)
1 parent 357f95d commit 7a3f4ad

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

config/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8704,7 +8704,7 @@ def add_subinterface(ctx, subinterface_name, vid):
87048704

87058705
if interface_alias is None:
87068706
ctx.fail("{} invalid subinterface".format(interface_alias))
8707-
if not isInterfaceNameValid(interface_alias):
8707+
if not isInterfaceNameValid(subinterface_name):
87088708
ctx.fail("Subinterface name length should not exceed {} characters".format(IFACE_NAME_MAX_LEN))
87098709

87108710
if interface_alias.startswith("Po") is True:

tests/subintf_test.py

+7
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ def test_add_existing_subintf_again(self):
8787
assert result.exit_code != 0
8888
assert ('Eth0.1002') not in db.cfgdb.get_table('VLAN_SUB_INTERFACE')
8989

90+
# Check if interface name length doesn't exceed 15 characters
91+
result = runner.invoke(config.config.commands["subinterface"].commands["add"], ["Ethernet0.000002", "2"],
92+
obj=obj)
93+
print(result.exit_code, result.output)
94+
assert result.exit_code != 0
95+
assert "Error: Subinterface name length should not exceed 15 characters" in result.output
96+
assert ('Ethernet0.000002') not in db.cfgdb.get_table('VLAN_SUB_INTERFACE')
9097

9198
def test_delete_non_existing_subintf(self):
9299
runner = CliRunner()

0 commit comments

Comments
 (0)