Skip to content

Commit

Permalink
[sflow] Fix traceback seen for show sflow interface (#1282)
Browse files Browse the repository at this point in the history
Fixed a traceback seen when show sflow interface is executed.
Updated the script to follow Python3 conventions.

Signed-off-by: Garrick He <garrick_he@dell.com>
  • Loading branch information
GarrickHe authored Dec 9, 2020
1 parent e22980f commit 2b4a58c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
7 changes: 4 additions & 3 deletions show/sflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ def show_sflow_interface(config_db):
for pname in natsorted(list(port_tbl.keys())):
intf_key = 'SFLOW_SESSION_TABLE:' + pname
sess_info = sess_db.get_all(sess_db.APPL_DB, intf_key)
if sess_info is None:
if (sess_info is None or sess_info.get('admin_state') is None or
sess_info.get('sample_rate') is None):
continue
body_info = [pname]
body_info.append(sess_info['admin_state'])
body_info.append(sess_info['sample_rate'])
body_info.append(sess_info.get('admin_state'))
body_info.append(sess_info.get('sample_rate'))
body.append(body_info)
click.echo(tabulate(body, header, tablefmt='grid'))

Expand Down
9 changes: 9 additions & 0 deletions tests/mock_tables/appl_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
"admin_state": "up",
"sample_rate": "5000"
},
"SFLOW_SESSION_TABLE:Ethernet8": {
"BAD": "BAD"
},
"SFLOW_SESSION_TABLE:Ethernet12": {
"sample_rate": "5000"
},
"SFLOW_SESSION_TABLE:Ethernet16": {
"admin_state": "up"
},
"PORT_TABLE:Ethernet0": {
"index": "0",
"lanes": "0",
Expand Down
29 changes: 29 additions & 0 deletions tests/sflow_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,35 @@ def test_config_sflow_intf_sample_rate(self):

return

def test_config_disable_all_intf(self):
db = Db()
runner = CliRunner()
obj = {'db':db.cfgdb}

# disable all interfaces
result = runner.invoke(config.config.commands["sflow"].
commands["interface"].commands["disable"], ["all"], obj=obj)
print(result.exit_code, result.output)
assert result.exit_code == 0

# verify in configDb
sflowSession = db.cfgdb.get_table('SFLOW_SESSION')
assert sflowSession["all"]["admin_state"] == "down"

def test_config_enable_all_intf(self):
db = Db()
runner = CliRunner()
obj = {'db':db.cfgdb}
# enable all interfaces
result = runner.invoke(config.config.commands["sflow"].commands["interface"].
commands["enable"], ["all"], obj=obj)
print(result.exit_code, result.output)
assert result.exit_code == 0

# verify in configDb
sflowSession = db.cfgdb.get_table('SFLOW_SESSION')
assert sflowSession["all"]["admin_state"] == "up"

@classmethod
def teardown_class(cls):
print("TEARDOWN")
Expand Down

0 comments on commit 2b4a58c

Please sign in to comment.