Skip to content

Commit ca14133

Browse files
authored
[crm] add checking for CRM interval range (#2293)
- 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 <[email protected]>
1 parent 142185c commit ca14133

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

crm/main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ def polling(ctx):
237237

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

245245
@config.group()

tests/crm_test.py

+14
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,8 @@
10331033
10341034
"""
10351035

1036+
crm_config_interval_too_big = "Error: Invalid value for \"INTERVAL\": 30000 is not in the valid range of 1 to 9999."
1037+
10361038
class TestCrm(object):
10371039
@classmethod
10381040
def setup_class(cls):
@@ -1053,6 +1055,18 @@ def test_crm_show_summary(self):
10531055
assert result.exit_code == 0
10541056
assert result.output == crm_new_show_summary
10551057

1058+
def test_crm_config_polling_interval(self):
1059+
runner = CliRunner()
1060+
db = Db()
1061+
result = runner.invoke(crm.cli, ['config', 'polling', 'interval', '10'], obj=db)
1062+
print(sys.stderr, result.output)
1063+
assert result.exit_code == 0
1064+
result = runner.invoke(crm.cli, ['config', 'polling', 'interval', '30000'], obj=db)
1065+
print(sys.stderr, result.output)
1066+
assert result.exit_code == 2
1067+
assert crm_config_interval_too_big in result.output
1068+
1069+
10561070
def test_crm_show_thresholds_acl_group(self):
10571071
runner = CliRunner()
10581072
db = Db()

0 commit comments

Comments
 (0)