Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for show vxlan tunnel command display issue #11902 #2391

Merged
merged 8 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions show/vxlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,17 @@ def name(vxlan_name):
vxlan_map_keys = config_db.keys(config_db.CONFIG_DB,
'VXLAN_TUNNEL_MAP{}{}{}*'.format(config_db.KEY_SEPARATOR, vxlan_name, config_db.KEY_SEPARATOR))
if vxlan_map_keys:
vxlan_map_mapping = config_db.get_all(config_db.CONFIG_DB, vxlan_map_keys[0])
r.append(vxlan_map_keys[0].split(config_db.KEY_SEPARATOR, 2)[2])
r.append("{} -> {}".format(vxlan_map_mapping.get('vni'), vxlan_map_mapping.get('vlan')))
table.append(r)
for key in natsorted(vxlan_map_keys):
vxlan_map_mapping = config_db.get_all(config_db.CONFIG_DB, key)
r.append(key.split(config_db.KEY_SEPARATOR, 2)[2])
r.append("{} -> {}".format(vxlan_map_mapping.get('vni'), vxlan_map_mapping.get('vlan')))
table.append(r)
r = []
r.append(' ')
r.append(' ')
r.append(' ')
else:
table.append(r)

click.echo(tabulate(table, header))

Expand All @@ -59,10 +66,17 @@ def tunnel():
vxlan_map_keys = config_db.keys(config_db.CONFIG_DB,
'VXLAN_TUNNEL_MAP{}{}{}*'.format(config_db.KEY_SEPARATOR, k, config_db.KEY_SEPARATOR))
if vxlan_map_keys:
vxlan_map_mapping = config_db.get_all(config_db.CONFIG_DB, vxlan_map_keys[0])
r.append(vxlan_map_keys[0].split(config_db.KEY_SEPARATOR, 2)[2])
r.append("{} -> {}".format(vxlan_map_mapping.get('vni'), vxlan_map_mapping.get('vlan')))
table.append(r)
for key in natsorted(vxlan_map_keys):
vxlan_map_mapping = config_db.get_all(config_db.CONFIG_DB, key)
r.append(key.split(config_db.KEY_SEPARATOR, 2)[2])
r.append("{} -> {}".format(vxlan_map_mapping.get('vni'), vxlan_map_mapping.get('vlan')))
table.append(r)
r = []
r.append(' ')
r.append(' ')
r.append(' ')
else:
table.append(r)

click.echo(tabulate(table, header))

Expand Down
25 changes: 25 additions & 0 deletions tests/vxlan_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@

"""

show_vxlan_name_output="""\
vxlan tunnel name source ip destination ip tunnel map name tunnel map mapping(vni -> vlan)
------------------- ----------- ---------------- ----------------- ---------------------------------
vtep1 1.1.1.1 map_100_Vlan100 100 -> Vlan100
map_101_Vlan101 101 -> Vlan101
map_102_Vlan102 102 -> Vlan102
map_200_Vlan200 200 -> Vlan200
"""

show_vxlan_remotevni_output="""\
+---------+--------------+-------+
| VLAN | RemoteVTEP | VNI |
Expand Down Expand Up @@ -137,6 +146,22 @@ def test_show_vxlan_tunnel(self):
assert result.exit_code == 0
assert result.output == show_vxlan_tunnel_output

def test_show_vxlan_tunnel_output(self):
runner = CliRunner()
result = runner.invoke(show.cli.commands["vxlan"].commands["tunnel"], [])
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert result.output == show_vxlan_name_output

def test_show_vxlan_name_vtep(self):
runner = CliRunner()
result = runner.invoke(show.cli.commands["vxlan"].commands["name"],["vtep1"])
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert result.output == show_vxlan_name_output

def test_show_vxlan_remotevni(self):
runner = CliRunner()
result = runner.invoke(show.cli.commands["vxlan"].commands["remotevni"], ["all"])
Expand Down