Skip to content

Commit 48a63ff

Browse files
Junchao-MellanoxStormLiangMS
authored andcommitted
Fix issue: out of range sflow polling interval is accepted and stored in config_db (#2847)
#### What I did Fixed issue: out of range sflow polling interval is accepted and stored in config_db. Reproduce step: ``` 1. Enable sflow feature: config feature state sflow enabled 2. Enable sflow itself: config sflow enable 3. Configure out of range polling interval: config sflow polling-interval 1. Error message is shown as expected 4. Save config: config save -y 5. Check "SFLOW" section inside config_db ``` As the interval is invalid, the expected behavior is that the interval is not saved to redis. But we see the invalid value was written to redis. #### How I did it Change `click.echo` to `ctx.fail` #### How to verify it 1. Manual test 2. Add a check in existing unit test case to cover the change
1 parent 984983e commit 48a63ff

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

config/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6483,7 +6483,7 @@ def polling_int(ctx, interval):
64836483
"""Set polling-interval for counter-sampling (0 to disable)"""
64846484
if ADHOC_VALIDATION:
64856485
if interval not in range(5, 301) and interval != 0:
6486-
click.echo("Polling interval must be between 5-300 (0 to disable)")
6486+
ctx.fail("Polling interval must be between 5-300 (0 to disable)")
64876487

64886488
config_db = ValidatedConfigDBConnector(ctx.obj['db'])
64896489
sflow_tbl = config_db.get_table('SFLOW')

tests/sflow_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ def test_config_sflow_polling_interval(self):
217217
result = runner.invoke(config.config.commands["sflow"].
218218
commands["polling-interval"], ["500"], obj=obj)
219219
print(result.exit_code, result.output)
220+
assert result.exit_code != 0
220221
assert "Polling interval must be between 5-300" in result.output
221222

222223
# set to 20

0 commit comments

Comments
 (0)