Skip to content

Commit

Permalink
[crm] add checking for CRM interval range (#2293)
Browse files Browse the repository at this point in the history
- What I did
Add checking for range for CRM interval

- How I did it
Add attribute click.IntRange(1, 9999) and UT to verify it (according to CRM HLD)

- How to verify it
Run UT
Manual testing: crm config polling interval 100000000 (receive error)

- Previous command output (if the output of a command-line utility has changed)
crm config polling interval 4566466
crm config polling interval --help
Usage: crm config polling interval [OPTIONS] INTERVAL

  CRM polling interval configuration

Options:
  --help  Show this message and exit.

- New command output (if the output of a command-line utility has changed)
crm config polling interval 4566466
Usage: crm config polling interval [OPTIONS] INTERVAL
Try "crm config polling interval --help" for help.

Error: Invalid value for "INTERVAL": 4566466 is not in the valid range of 1 to 9999.

crm config polling interval --help
Usage: crm config polling interval [OPTIONS] INTERVAL

  CRM polling interval configuration in seconds (range: 1-9999)

Options:
  --help  Show this message and exit.

Signed-off-by: Andriy Yurkiv <ayurkiv@nvidia.com>
  • Loading branch information
ayurkiv-nvda committed Aug 8, 2022
1 parent 142185c commit ca14133
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ def polling(ctx):

@polling.command()
@click.pass_context
@click.argument('interval', type=click.INT)
@click.argument('interval', type=click.IntRange(1, 9999))
def interval(ctx, interval):
"""CRM polling interval configuration"""
"""CRM polling interval configuration in seconds (range: 1-9999)"""
ctx.obj["crm"].config('polling_interval', interval)

@config.group()
Expand Down
14 changes: 14 additions & 0 deletions tests/crm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,8 @@
"""

crm_config_interval_too_big = "Error: Invalid value for \"INTERVAL\": 30000 is not in the valid range of 1 to 9999."

class TestCrm(object):
@classmethod
def setup_class(cls):
Expand All @@ -1053,6 +1055,18 @@ def test_crm_show_summary(self):
assert result.exit_code == 0
assert result.output == crm_new_show_summary

def test_crm_config_polling_interval(self):
runner = CliRunner()
db = Db()
result = runner.invoke(crm.cli, ['config', 'polling', 'interval', '10'], obj=db)
print(sys.stderr, result.output)
assert result.exit_code == 0
result = runner.invoke(crm.cli, ['config', 'polling', 'interval', '30000'], obj=db)
print(sys.stderr, result.output)
assert result.exit_code == 2
assert crm_config_interval_too_big in result.output


def test_crm_show_thresholds_acl_group(self):
runner = CliRunner()
db = Db()
Expand Down

0 comments on commit ca14133

Please sign in to comment.