Skip to content
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
4 changes: 2 additions & 2 deletions show/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ def feature_autorestart(db, feature_name):
feature_table = db.cfgdb.get_table('FEATURE')
if feature_name:
if feature_table and feature_name in feature_table:
body.append([feature_name, feature_table[feature_name]['auto_restart']])
body.append([feature_name, feature_table[ feature_name ].get('auto_restart', 'unknown')])
else:
click.echo("Can not find feature {}".format(feature_name))
sys.exit(1)
else:
for name in natsorted(list(feature_table.keys())):
body.append([name, feature_table[name]['auto_restart']])
body.append([name, feature_table[ name ].get('auto_restart', 'unknown')])
click.echo(tabulate(body, header))
45 changes: 45 additions & 0 deletions tests/feature_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,32 @@
telemetry enabled
"""

show_feature_autorestart_missing_output="""\
Feature AutoRestart
---------- --------------
bar unknown
bgp enabled
database always_enabled
dhcp_relay enabled
lldp enabled
nat enabled
pmon enabled
radv enabled
restapi enabled
sflow enabled
snmp enabled
swss enabled
syncd enabled
teamd enabled
telemetry enabled
"""

show_feature_autorestart_bar_missing_output="""\
Feature AutoRestart
--------- -------------
bar unknown
"""

show_feature_bgp_autorestart_output="""\
Feature AutoRestart
--------- -------------
Expand Down Expand Up @@ -277,6 +303,25 @@ def test_show_unknown_autorestart_status(self, get_cmd_module):
print(result.output)
assert result.exit_code == 1

def test_show_feature_autorestart_missing(self, get_cmd_module):
(config, show) = get_cmd_module
db = Db()
dbconn = db.db
db.cfgdb.set_entry("FEATURE", "bar", { "state": "enabled" })
runner = CliRunner()

result = runner.invoke(show.cli.commands["feature"].commands["autorestart"], obj=db)
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert result.output == show_feature_autorestart_missing_output

result = runner.invoke(show.cli.commands["feature"].commands["autorestart"], ["bar"], obj=db)
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert result.output == show_feature_autorestart_bar_missing_output

def test_config_bgp_feature_state(self, get_cmd_module):
(config, show) = get_cmd_module
db = Db()
Expand Down