Skip to content

Commit 70a15aa

Browse files
dgsudharsanStormLiangMS
authored andcommitted
[VXLAN]Fixing traceback in show remotemac when mac moves during command 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.
1 parent 24b86ee commit 70a15aa

File tree

3 files changed

+78
-4
lines changed

3 files changed

+78
-4
lines changed

show/vxlan.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ def interface():
9898
vtepname = key1.pop();
9999
if 'src_ip' in vxlan_table[key]:
100100
vtep_sip = vxlan_table[key]['src_ip']
101-
if vtep_sip is not '0.0.0.0':
101+
if vtep_sip != '0.0.0.0':
102102
output = '\tVTEP Name : ' + vtepname + ', SIP : ' + vxlan_table[key]['src_ip']
103103
else:
104104
output = '\tVTEP Name : ' + vtepname
105105

106106
click.echo(output)
107107

108-
if vtep_sip is not '0.0.0.0':
108+
if vtep_sip != '0.0.0.0':
109109
vxlan_table = config_db.get_table('VXLAN_EVPN_NVO')
110110
vxlan_keys = vxlan_table.keys()
111111
if vxlan_keys is not None:
@@ -307,8 +307,8 @@ def remotemac(remote_vtep_ip, count):
307307
vxlan_table = db.get_all(db.APPL_DB, key);
308308
if vxlan_table is None:
309309
continue
310-
rmtip = vxlan_table['remote_vtep']
311-
if remote_vtep_ip != 'all' and rmtip != remote_vtep_ip:
310+
rmtip = vxlan_table.get('remote_vtep')
311+
if remote_vtep_ip != 'all' and rmtip != remote_vtep_ip or rmtip is None:
312312
continue
313313
if count is None:
314314
body.append([vlan, mac, rmtip, vxlan_table['vni'], vxlan_table['type']])

tests/mock_tables/appl_db.json

+10
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,16 @@
290290
"VXLAN_REMOTE_VNI_TABLE:Vlan200:25.25.25.27": {
291291
"vni": "200"
292292
},
293+
"VXLAN_FDB_TABLE:Vlan200:00:02:00:00:47:e2": {
294+
"remote_vtep": "2.2.2.2",
295+
"type": "dynamic",
296+
"vni": "200"
297+
},
298+
"VXLAN_FDB_TABLE:Vlan200:00:02:00:00:47:e3": {
299+
"remote_vtep": "2.2.2.3",
300+
"type": "dynamic",
301+
"vni": "200"
302+
},
293303
"MUX_CABLE_TABLE:Ethernet32": {
294304
"state": "active"
295305
},

tests/vxlan_test.py

+64
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,38 @@
112112
113113
"""
114114

115+
show_vxlan_remotemac_all_output="""\
116+
+---------+-------------------+--------------+-------+---------+
117+
| VLAN | MAC | RemoteVTEP | VNI | Type |
118+
+=========+===================+==============+=======+=========+
119+
| Vlan200 | 00:02:00:00:47:e2 | 2.2.2.2 | 200 | dynamic |
120+
+---------+-------------------+--------------+-------+---------+
121+
| Vlan200 | 00:02:00:00:47:e3 | 2.2.2.3 | 200 | dynamic |
122+
+---------+-------------------+--------------+-------+---------+
123+
Total count : 2
124+
125+
"""
126+
127+
show_vxlan_remotemac_specific_output="""\
128+
+---------+-------------------+--------------+-------+---------+
129+
| VLAN | MAC | RemoteVTEP | VNI | Type |
130+
+=========+===================+==============+=======+=========+
131+
| Vlan200 | 00:02:00:00:47:e2 | 2.2.2.2 | 200 | dynamic |
132+
+---------+-------------------+--------------+-------+---------+
133+
Total count : 1
134+
135+
"""
136+
137+
show_vxlan_remotemac_cnt_output="""\
138+
Total count : 2
139+
140+
"""
141+
142+
show_vxlan_remotemac_specific_cnt_output="""\
143+
Total count : 1
144+
145+
"""
146+
115147
class TestVxlan(object):
116148
@classmethod
117149
def setup_class(cls):
@@ -215,6 +247,38 @@ def test_show_vxlan_remotevni_specific_cnt(self):
215247
assert result.exit_code == 0
216248
assert result.output == show_vxlan_remotevni_specific_cnt_output
217249

250+
def test_show_vxlan_remotemac(self):
251+
runner = CliRunner()
252+
result = runner.invoke(show.cli.commands["vxlan"].commands["remotemac"], ["all"])
253+
print(result.exit_code)
254+
print(result.output)
255+
assert result.exit_code == 0
256+
assert result.output == show_vxlan_remotemac_all_output
257+
258+
def test_show_vxlan_remotemac_specific(self):
259+
runner = CliRunner()
260+
result = runner.invoke(show.cli.commands["vxlan"].commands["remotemac"], ["2.2.2.2"])
261+
print(result.exit_code)
262+
print(result.output)
263+
assert result.exit_code == 0
264+
assert result.output == show_vxlan_remotemac_specific_output
265+
266+
def test_show_vxlan_remotemac_cnt(self):
267+
runner = CliRunner()
268+
result = runner.invoke(show.cli.commands["vxlan"].commands["remotemac"], ["all", "count"])
269+
print(result.exit_code)
270+
print(result.output)
271+
assert result.exit_code == 0
272+
assert result.output == show_vxlan_remotemac_cnt_output
273+
274+
def test_show_vxlan_remotemac_specific_cnt(self):
275+
runner = CliRunner()
276+
result = runner.invoke(show.cli.commands["vxlan"].commands["remotemac"], ["2.2.2.2", "count"])
277+
print(result.exit_code)
278+
print(result.output)
279+
assert result.exit_code == 0
280+
assert result.output == show_vxlan_remotemac_specific_cnt_output
281+
218282
def test_config_vxlan_add(self):
219283
runner = CliRunner()
220284
db = Db()

0 commit comments

Comments
 (0)