Skip to content

Commit

Permalink
[config]: Add loopback interfaces to interface name checker (sonic-ne…
Browse files Browse the repository at this point in the history
…t#1869)

* Add loopback interfaces to interface name checker

Signed-off-by: Ze Gan <[email protected]>

* Add unitest for interface name checker

Signed-off-by: Ze Gan <[email protected]>
  • Loading branch information
Pterosaur authored Oct 14, 2021
1 parent c950a55 commit 25bb184
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ def interface_name_is_valid(config_db, interface_name):
port_dict = config_db.get_table('PORT')
port_channel_dict = config_db.get_table('PORTCHANNEL')
sub_port_intf_dict = config_db.get_table('VLAN_SUB_INTERFACE')
loopback_dict = config_db.get_table('LOOPBACK_INTERFACE')

if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
Expand All @@ -311,6 +312,10 @@ def interface_name_is_valid(config_db, interface_name):
for sub_port_intf_name in sub_port_intf_dict:
if interface_name == sub_port_intf_name:
return True
if loopback_dict:
for loopback_name in loopback_dict:
if interface_name == loopback_name:
return True
return False

def interface_name_to_alias(config_db, interface_name):
Expand Down
12 changes: 12 additions & 0 deletions tests/config_int_name_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from unittest import mock

from utilities_common.db import Db

import config.main as config


def test_interface_name_checker():
db = Db()
db.cfgdb.set_entry("LOOPBACK_INTERFACE", "Loopback0", {"NULL": "NULL"})

assert config.interface_name_is_valid(db.cfgdb, "Loopback0")

0 comments on commit 25bb184

Please sign in to comment.