From ae39883558b1ce22da00feb7324a1684b25ef1c7 Mon Sep 17 00:00:00 2001 From: allas-nvidia <76047578+allas-nvidia@users.noreply.github.com> Date: Mon, 22 Mar 2021 20:06:07 +0200 Subject: [PATCH] Fix bug: show vlan config for vlan with no members (#1503) File show/vlan.py, function config(db) was modified to fill the table with VLAN even without members. Signed-off-by: allas --- show/vlan.py | 45 ++++++++++++++++++++++----------------------- tests/vlan_test.py | 2 ++ 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/show/vlan.py b/show/vlan.py index f95d21a40284..df4149fca904 100644 --- a/show/vlan.py +++ b/show/vlan.py @@ -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 diff --git a/tests/vlan_test.py b/tests/vlan_test.py index 8be9db1e2e0f..438f3acbbbae 100644 --- a/tests/vlan_test.py +++ b/tests/vlan_test.py @@ -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="""\ @@ -96,6 +97,7 @@ Vlan1000 1000 etp5 untagged Vlan2000 2000 etp7 untagged Vlan2000 2000 etp8 untagged +Vlan3000 3000 """ config_vlan_add_dhcp_relay_output="""\