Skip to content

Commit

Permalink
[VXLAN]Fixing traceback in show remotemac when mac moves during comma…
Browse files Browse the repository at this point in the history
…nd execution (#2506)

- What I did
During the execution of show vxlan remotemac command, if a mac moves after the key is fetched but not the table fields, there will be the below traceback

show vxlan remotemac 2.2.2.2 
This is because the entry would have got removed before the CLI fetches the table.

- How I did it
Used get API to fetch table rather than indexing directly which resulted in traceback. Additionally fixed Python 3.8 SyntaxWarning.

show vxlan remotemac all
/usr/local/lib/python3.9/dist-packages/show/vxlan.py:101: SyntaxWarning: "is not" with a literal. Did you mean "!="?
if vtep_sip is not '0.0.0.0':
/usr/local/lib/python3.9/dist-packages/show/vxlan.py:108: SyntaxWarning: "is not" with a literal. Did you mean "!="?
if vtep_sip is not '0.0.0.0':

- How to verify it
Perform mac move during show command execution and verify there is no traceback.
  • Loading branch information
dgsudharsan authored and yxieca committed Nov 29, 2022
1 parent 1f26c8c commit 0157086
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 4 deletions.
8 changes: 4 additions & 4 deletions show/vxlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ def interface():
vtepname = key1.pop();
if 'src_ip' in vxlan_table[key]:
vtep_sip = vxlan_table[key]['src_ip']
if vtep_sip is not '0.0.0.0':
if vtep_sip != '0.0.0.0':
output = '\tVTEP Name : ' + vtepname + ', SIP : ' + vxlan_table[key]['src_ip']
else:
output = '\tVTEP Name : ' + vtepname

click.echo(output)

if vtep_sip is not '0.0.0.0':
if vtep_sip != '0.0.0.0':
vxlan_table = config_db.get_table('VXLAN_EVPN_NVO')
vxlan_keys = vxlan_table.keys()
if vxlan_keys is not None:
Expand Down Expand Up @@ -307,8 +307,8 @@ def remotemac(remote_vtep_ip, count):
vxlan_table = db.get_all(db.APPL_DB, key);
if vxlan_table is None:
continue
rmtip = vxlan_table['remote_vtep']
if remote_vtep_ip != 'all' and rmtip != remote_vtep_ip:
rmtip = vxlan_table.get('remote_vtep')
if remote_vtep_ip != 'all' and rmtip != remote_vtep_ip or rmtip is None:
continue
if count is None:
body.append([vlan, mac, rmtip, vxlan_table['vni'], vxlan_table['type']])
Expand Down
10 changes: 10 additions & 0 deletions tests/mock_tables/appl_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,16 @@
"VXLAN_REMOTE_VNI_TABLE:Vlan200:25.25.25.27": {
"vni": "200"
},
"VXLAN_FDB_TABLE:Vlan200:00:02:00:00:47:e2": {
"remote_vtep": "2.2.2.2",
"type": "dynamic",
"vni": "200"
},
"VXLAN_FDB_TABLE:Vlan200:00:02:00:00:47:e3": {
"remote_vtep": "2.2.2.3",
"type": "dynamic",
"vni": "200"
},
"MUX_CABLE_TABLE:Ethernet32": {
"state": "active"
},
Expand Down
64 changes: 64 additions & 0 deletions tests/vxlan_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,38 @@
"""

show_vxlan_remotemac_all_output="""\
+---------+-------------------+--------------+-------+---------+
| VLAN | MAC | RemoteVTEP | VNI | Type |
+=========+===================+==============+=======+=========+
| Vlan200 | 00:02:00:00:47:e2 | 2.2.2.2 | 200 | dynamic |
+---------+-------------------+--------------+-------+---------+
| Vlan200 | 00:02:00:00:47:e3 | 2.2.2.3 | 200 | dynamic |
+---------+-------------------+--------------+-------+---------+
Total count : 2
"""

show_vxlan_remotemac_specific_output="""\
+---------+-------------------+--------------+-------+---------+
| VLAN | MAC | RemoteVTEP | VNI | Type |
+=========+===================+==============+=======+=========+
| Vlan200 | 00:02:00:00:47:e2 | 2.2.2.2 | 200 | dynamic |
+---------+-------------------+--------------+-------+---------+
Total count : 1
"""

show_vxlan_remotemac_cnt_output="""\
Total count : 2
"""

show_vxlan_remotemac_specific_cnt_output="""\
Total count : 1
"""

class TestVxlan(object):
@classmethod
def setup_class(cls):
Expand Down Expand Up @@ -215,6 +247,38 @@ def test_show_vxlan_remotevni_specific_cnt(self):
assert result.exit_code == 0
assert result.output == show_vxlan_remotevni_specific_cnt_output

def test_show_vxlan_remotemac(self):
runner = CliRunner()
result = runner.invoke(show.cli.commands["vxlan"].commands["remotemac"], ["all"])
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert result.output == show_vxlan_remotemac_all_output

def test_show_vxlan_remotemac_specific(self):
runner = CliRunner()
result = runner.invoke(show.cli.commands["vxlan"].commands["remotemac"], ["2.2.2.2"])
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert result.output == show_vxlan_remotemac_specific_output

def test_show_vxlan_remotemac_cnt(self):
runner = CliRunner()
result = runner.invoke(show.cli.commands["vxlan"].commands["remotemac"], ["all", "count"])
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert result.output == show_vxlan_remotemac_cnt_output

def test_show_vxlan_remotemac_specific_cnt(self):
runner = CliRunner()
result = runner.invoke(show.cli.commands["vxlan"].commands["remotemac"], ["2.2.2.2", "count"])
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert result.output == show_vxlan_remotemac_specific_cnt_output

def test_config_vxlan_add(self):
runner = CliRunner()
db = Db()
Expand Down

0 comments on commit 0157086

Please sign in to comment.