Skip to content

Commit 8fdea8d

Browse files
authored
Fix the interface name length validation for subinterface (#3774)
- 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.
1 parent 899ed9b commit 8fdea8d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

config/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8873,7 +8873,7 @@ def add_subinterface(ctx, subinterface_name, vid):
88738873

88748874
if interface_alias is None:
88758875
ctx.fail("{} invalid subinterface".format(interface_alias))
8876-
if not isInterfaceNameValid(interface_alias):
8876+
if not isInterfaceNameValid(subinterface_name):
88778877
ctx.fail("Subinterface name length should not exceed {} characters".format(IFACE_NAME_MAX_LEN))
88788878

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

tests/subintf_test.py

Lines changed: 7 additions & 0 deletions
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)