Skip to content

Commit f41e4d1

Browse files
skbhavayxieca
authored andcommitted
Fix for show vxlan tunnel command display issue #11902 (#2391)
* Issue: Only one vni to vlan map entry in the output of show vxlan tunnel command Fix: Fix: Added fix to display all vni to vlan map entries for "show vxlan tunnel" and "show vxlan name commands.
1 parent e1d827e commit f41e4d1

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

show/vxlan.py

+22-8
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,17 @@ def name(vxlan_name):
3232
vxlan_map_keys = config_db.keys(config_db.CONFIG_DB,
3333
'VXLAN_TUNNEL_MAP{}{}{}*'.format(config_db.KEY_SEPARATOR, vxlan_name, config_db.KEY_SEPARATOR))
3434
if vxlan_map_keys:
35-
vxlan_map_mapping = config_db.get_all(config_db.CONFIG_DB, vxlan_map_keys[0])
36-
r.append(vxlan_map_keys[0].split(config_db.KEY_SEPARATOR, 2)[2])
37-
r.append("{} -> {}".format(vxlan_map_mapping.get('vni'), vxlan_map_mapping.get('vlan')))
38-
table.append(r)
35+
for key in natsorted(vxlan_map_keys):
36+
vxlan_map_mapping = config_db.get_all(config_db.CONFIG_DB, key)
37+
r.append(key.split(config_db.KEY_SEPARATOR, 2)[2])
38+
r.append("{} -> {}".format(vxlan_map_mapping.get('vni'), vxlan_map_mapping.get('vlan')))
39+
table.append(r)
40+
r = []
41+
r.append(' ')
42+
r.append(' ')
43+
r.append(' ')
44+
else:
45+
table.append(r)
3946

4047
click.echo(tabulate(table, header))
4148

@@ -59,10 +66,17 @@ def tunnel():
5966
vxlan_map_keys = config_db.keys(config_db.CONFIG_DB,
6067
'VXLAN_TUNNEL_MAP{}{}{}*'.format(config_db.KEY_SEPARATOR, k, config_db.KEY_SEPARATOR))
6168
if vxlan_map_keys:
62-
vxlan_map_mapping = config_db.get_all(config_db.CONFIG_DB, vxlan_map_keys[0])
63-
r.append(vxlan_map_keys[0].split(config_db.KEY_SEPARATOR, 2)[2])
64-
r.append("{} -> {}".format(vxlan_map_mapping.get('vni'), vxlan_map_mapping.get('vlan')))
65-
table.append(r)
69+
for key in natsorted(vxlan_map_keys):
70+
vxlan_map_mapping = config_db.get_all(config_db.CONFIG_DB, key)
71+
r.append(key.split(config_db.KEY_SEPARATOR, 2)[2])
72+
r.append("{} -> {}".format(vxlan_map_mapping.get('vni'), vxlan_map_mapping.get('vlan')))
73+
table.append(r)
74+
r = []
75+
r.append(' ')
76+
r.append(' ')
77+
r.append(' ')
78+
else:
79+
table.append(r)
6680

6781
click.echo(tabulate(table, header))
6882

tests/vxlan_test.py

+25
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@
6060
6161
"""
6262

63+
show_vxlan_name_output="""\
64+
vxlan tunnel name source ip destination ip tunnel map name tunnel map mapping(vni -> vlan)
65+
------------------- ----------- ---------------- ----------------- ---------------------------------
66+
vtep1 1.1.1.1 map_100_Vlan100 100 -> Vlan100
67+
map_101_Vlan101 101 -> Vlan101
68+
map_102_Vlan102 102 -> Vlan102
69+
map_200_Vlan200 200 -> Vlan200
70+
"""
71+
6372
show_vxlan_remotevni_output="""\
6473
+---------+--------------+-------+
6574
| VLAN | RemoteVTEP | VNI |
@@ -141,6 +150,22 @@ def test_show_vxlan_tunnel(self):
141150
assert result.exit_code == 0
142151
assert result.output == show_vxlan_tunnel_output
143152

153+
def test_show_vxlan_tunnel_output(self):
154+
runner = CliRunner()
155+
result = runner.invoke(show.cli.commands["vxlan"].commands["tunnel"], [])
156+
print(result.exit_code)
157+
print(result.output)
158+
assert result.exit_code == 0
159+
assert result.output == show_vxlan_name_output
160+
161+
def test_show_vxlan_name_vtep(self):
162+
runner = CliRunner()
163+
result = runner.invoke(show.cli.commands["vxlan"].commands["name"],["vtep1"])
164+
print(result.exit_code)
165+
print(result.output)
166+
assert result.exit_code == 0
167+
assert result.output == show_vxlan_name_output
168+
144169
def test_show_vxlan_remotevni(self):
145170
runner = CliRunner()
146171
result = runner.invoke(show.cli.commands["vxlan"].commands["remotevni"], ["all"])

0 commit comments

Comments
 (0)