Skip to content

Commit fdad0e4

Browse files
committed
Making 'show feature autorestart' more resilient to missing auto_restart config in CONFIG_DB
Fixes BUG 762723
1 parent 4aa512c commit fdad0e4

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

show/feature.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ def feature_autorestart(db, feature_name):
156156
feature_table = db.cfgdb.get_table('FEATURE')
157157
if feature_name:
158158
if feature_table and feature_name in feature_table:
159-
body.append([feature_name, feature_table[feature_name]['auto_restart']])
159+
body.append([feature_name, feature_table[ feature_name ].get('auto_restart', 'unknown')])
160160
else:
161161
click.echo("Can not find feature {}".format(feature_name))
162162
sys.exit(1)
163163
else:
164164
for name in natsorted(list(feature_table.keys())):
165-
body.append([name, feature_table[name]['auto_restart']])
165+
body.append([name, feature_table[ name ].get('auto_restart', 'unknown')])
166166
click.echo(tabulate(body, header))

tests/feature_test.py

+45
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,32 @@
130130
telemetry enabled
131131
"""
132132

133+
show_feature_autorestart_missing_output="""\
134+
Feature AutoRestart
135+
---------- --------------
136+
bar unknown
137+
bgp enabled
138+
database always_enabled
139+
dhcp_relay enabled
140+
lldp enabled
141+
nat enabled
142+
pmon enabled
143+
radv enabled
144+
restapi enabled
145+
sflow enabled
146+
snmp enabled
147+
swss enabled
148+
syncd enabled
149+
teamd enabled
150+
telemetry enabled
151+
"""
152+
153+
show_feature_autorestart_bar_missing_output="""\
154+
Feature AutoRestart
155+
--------- -------------
156+
bar unknown
157+
"""
158+
133159
show_feature_bgp_autorestart_output="""\
134160
Feature AutoRestart
135161
--------- -------------
@@ -277,6 +303,25 @@ def test_show_unknown_autorestart_status(self, get_cmd_module):
277303
print(result.output)
278304
assert result.exit_code == 1
279305

306+
def test_show_feature_autorestart_missing(self, get_cmd_module):
307+
(config, show) = get_cmd_module
308+
db = Db()
309+
dbconn = db.db
310+
db.cfgdb.set_entry("FEATURE", "bar", { "state": "enabled" })
311+
runner = CliRunner()
312+
313+
result = runner.invoke(show.cli.commands["feature"].commands["autorestart"], obj=db)
314+
print(result.exit_code)
315+
print(result.output)
316+
assert result.exit_code == 0
317+
assert result.output == show_feature_autorestart_missing_output
318+
319+
result = runner.invoke(show.cli.commands["feature"].commands["autorestart"], ["bar"], obj=db)
320+
print(result.exit_code)
321+
print(result.output)
322+
assert result.exit_code == 0
323+
assert result.output == show_feature_autorestart_bar_missing_output
324+
280325
def test_config_bgp_feature_state(self, get_cmd_module):
281326
(config, show) = get_cmd_module
282327
db = Db()

0 commit comments

Comments
 (0)