From ca14133fd013548b9eb7fe40c53a7df99ed67c73 Mon Sep 17 00:00:00 2001 From: Andriy Yurkiv <70649192+ayurkiv-nvda@users.noreply.github.com> Date: Mon, 8 Aug 2022 15:26:06 +0300 Subject: [PATCH] [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 --- crm/main.py | 4 ++-- tests/crm_test.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/crm/main.py b/crm/main.py index f728f87dd9..9b0d06e89a 100644 --- a/crm/main.py +++ b/crm/main.py @@ -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() diff --git a/tests/crm_test.py b/tests/crm_test.py index 24ced116ce..6b3f32ed9d 100644 --- a/tests/crm_test.py +++ b/tests/crm_test.py @@ -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): @@ -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()