diff --git a/show/feature.py b/show/feature.py index 547d8d1729..60ff80321a 100644 --- a/show/feature.py +++ b/show/feature.py @@ -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)) diff --git a/tests/feature_test.py b/tests/feature_test.py index fa5c2870ea..8706e2a92f 100644 --- a/tests/feature_test.py +++ b/tests/feature_test.py @@ -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 --------- ------------- @@ -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()