Skip to content

Commit

Permalink
[show/vlan]: fix show vlan config (sonic-net#1050)
Browse files Browse the repository at this point in the history
use VLAN_MEMBER table to get vlan configuration

Signed-off-by: Guohan Lu <[email protected]>
  • Loading branch information
lguohan authored Aug 13, 2020
1 parent e741c7c commit 027553c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
15 changes: 7 additions & 8 deletions show/vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,23 @@ def brief(db, verbose):
def config(db):
data = db.cfgdb.get_table('VLAN')
keys = data.keys()
member_data = db.cfgdb.get_table('VLAN_MEMBER')

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

for k in natsorted(keys):
if 'members' not in data[k] :
r = []
r.append(k)
r.append(data[k]['vlanid'])
table.append(r)
continue
members = set(data[k].get('members', []))
for (vlan, interface_name) in member_data:
if vlan == k:
members.add(interface_name)

for m in data[k].get('members', []):
for m in members:
r = []
r.append(k)
r.append(data[k]['vlanid'])
if clicommon.get_interface_naming_mode() == "alias":
alias = iface_alias_converter.name_to_alias(m)
alias = clicommon.InterfaceAliasConverter(db).name_to_alias(m)
r.append(alias)
else:
r.append(m)
Expand Down
30 changes: 26 additions & 4 deletions tests/vlan_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,21 @@
"""

show_vlan_config_output="""\
Name VID
-------- -----
Vlan1000 1000
Name VID Member Mode
-------- ----- ---------- --------
Vlan1000 1000 Ethernet8 untagged
Vlan1000 1000 Ethernet12 untagged
Vlan1000 1000 Ethernet4 untagged
Vlan1000 1000 Ethernet16 untagged
"""

show_vlan_config_in_alias_mode_output="""\
Name VID Member Mode
-------- ----- -------- --------
Vlan1000 1000 etp3 untagged
Vlan1000 1000 etp4 untagged
Vlan1000 1000 etp2 untagged
Vlan1000 1000 etp5 untagged
"""

config_vlan_add_dhcp_relay_output="""\
Expand Down Expand Up @@ -134,11 +146,11 @@ def test_show_vlan_brief_in_alias_mode(self):
runner = CliRunner()
os.environ['SONIC_CLI_IFACE_MODE'] = "alias"
result = runner.invoke(show.cli.commands["vlan"].commands["brief"])
os.environ['SONIC_CLI_IFACE_MODE'] = "default"
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert result.output == show_vlan_brief_in_alias_mode_output
os.environ['SONIC_CLI_IFACE_MODE'] = ""

def test_show_vlan_config(self):
runner = CliRunner()
Expand All @@ -148,6 +160,16 @@ def test_show_vlan_config(self):
assert result.exit_code == 0
assert result.output == show_vlan_config_output

def test_show_vlan_config_in_alias_mode(self):
runner = CliRunner()
os.environ['SONIC_CLI_IFACE_MODE'] = "alias"
result = runner.invoke(show.cli.commands["vlan"].commands["config"], [])
os.environ['SONIC_CLI_IFACE_MODE'] = "default"
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert result.output == show_vlan_config_in_alias_mode_output

def test_config_vlan_add_vlan_with_invalid_vlanid(self):
runner = CliRunner()
result = runner.invoke(config.config.commands["vlan"].commands["add"], ["4096"])
Expand Down

0 comments on commit 027553c

Please sign in to comment.