Skip to content

Commit

Permalink
Fix bug: show vlan config for vlan with no members (sonic-net#1503)
Browse files Browse the repository at this point in the history
File show/vlan.py, function config(db) was modified to fill the table with VLAN even without members.

Signed-off-by: allas <[email protected]>
  • Loading branch information
allas-nvidia authored Mar 22, 2021
1 parent 3a482ac commit ae39883
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
45 changes: 22 additions & 23 deletions show/vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,33 +109,32 @@ def config(db):
data = db.cfgdb.get_table('VLAN')
keys = list(data.keys())
member_data = db.cfgdb.get_table('VLAN_MEMBER')

interface_naming_mode = clicommon.get_interface_naming_mode()
iface_alias_converter = clicommon.InterfaceAliasConverter(db)

def get_iface_name_for_display(member):
name_for_display = member
if interface_naming_mode == "alias" and member:
name_for_display = iface_alias_converter.name_to_alias(member)
return name_for_display

def get_tagging_mode(vlan, member):
if not member:
return ''
tagging_mode = db.cfgdb.get_entry('VLAN_MEMBER', (vlan, member)).get('tagging_mode')
return '?' if tagging_mode is None else tagging_mode

def tablelize(keys, data):
table = []

for k in natsorted(keys):
members = set(data[k].get('members', []))
for (vlan, interface_name) in member_data:
if vlan == k:
members.add(interface_name)

for m in natsorted(list(members)):
r = []
r.append(k)
r.append(data[k]['vlanid'])
if clicommon.get_interface_naming_mode() == "alias":
alias = clicommon.InterfaceAliasConverter(db).name_to_alias(m)
r.append(alias)
else:
r.append(m)

entry = db.cfgdb.get_entry('VLAN_MEMBER', (k, m))
mode = entry.get('tagging_mode')
if mode is None:
r.append('?')
else:
r.append(mode)

members = set([(vlan, member) for vlan, member in member_data if vlan == k] + [(k, member) for member in set(data[k].get('members', []))])
# vlan with no members
if not members:
members = [(k, '')]

for vlan, member in natsorted(members):
r = [vlan, data[vlan]['vlanid'], get_iface_name_for_display(member), get_tagging_mode(vlan, member)]
table.append(r)

return table
Expand Down
2 changes: 2 additions & 0 deletions tests/vlan_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
Vlan1000 1000 Ethernet16 untagged
Vlan2000 2000 Ethernet24 untagged
Vlan2000 2000 Ethernet28 untagged
Vlan3000 3000
"""

show_vlan_config_in_alias_mode_output="""\
Expand All @@ -96,6 +97,7 @@
Vlan1000 1000 etp5 untagged
Vlan2000 2000 etp7 untagged
Vlan2000 2000 etp8 untagged
Vlan3000 3000
"""

config_vlan_add_dhcp_relay_output="""\
Expand Down

0 comments on commit ae39883

Please sign in to comment.