From 316cd469429209f42f8a8e456f6bd2e280d4db10 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Thu, 14 Apr 2022 10:32:59 +0200 Subject: [PATCH 1/4] test api: casadm commands for promotion policy Signed-off-by: Michal Mielewczyk --- test/functional/api/cas/cli.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/functional/api/cas/cli.py b/test/functional/api/cas/cli.py index 6cd5f9a..82df0d4 100644 --- a/test/functional/api/cas/cli.py +++ b/test/functional/api/cas/cli.py @@ -273,6 +273,22 @@ def set_param_cutoff_cmd(cache_id: str, core_id: str = None, threshold: str = No additional_params=add_params, shortcut=shortcut) +def set_param_promotion_cmd(cache_id: str, policy: str, shortcut: bool = False): + add_params = (" -p " if shortcut else " --policy ") + policy + return _set_param_cmd(namespace="promotion", cache_id=cache_id, + additional_params=add_params, shortcut=shortcut) + + +def set_param_promotion_nhit_cmd( + cache_id: str, threshold=None, trigger=None, shortcut: bool = False +): + add_param = "" + if threshold is not None: + add_param += (" -t " if shortcut else " --threshold ") + str(threshold) + if trigger is not None: + add_param += (" -o " if shortcut else " --trigger ") + str(trigger) + + def set_param_cleaning_cmd(cache_id: str, policy: str, shortcut: bool = False): add_params = (" -p " if shortcut else " --policy ") + policy return _set_param_cmd(namespace="cleaning", cache_id=cache_id, From cfb4841ddc8617a3e9379194b7ef34b79f504802 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Tue, 12 Apr 2022 10:32:14 +0200 Subject: [PATCH 2/4] test api: allow alru optional params be optional Signed-off-by: Michal Mielewczyk --- test/functional/api/cas/cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/functional/api/cas/cli.py b/test/functional/api/cas/cli.py index 82df0d4..afd0bcd 100644 --- a/test/functional/api/cas/cli.py +++ b/test/functional/api/cas/cli.py @@ -295,8 +295,8 @@ def set_param_cleaning_cmd(cache_id: str, policy: str, shortcut: bool = False): additional_params=add_params, shortcut=shortcut) -def set_param_cleaning_alru_cmd(cache_id, wake_up, staleness_time, - flush_max_buffers, activity_threshold, +def set_param_cleaning_alru_cmd(cache_id, wake_up=None, staleness_time=None, + flush_max_buffers=None, activity_threshold=None, shortcut: bool = False): add_param = "" if wake_up is not None: From 46de8f21f6e50f3a5e92b285143bc37b774edd6a Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Thu, 14 Apr 2022 10:24:51 +0200 Subject: [PATCH 3/4] test api: add err msg for ops forbidden in standby Signed-off-by: Michal Mielewczyk --- test/functional/api/cas/cli_messages.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/functional/api/cas/cli_messages.py b/test/functional/api/cas/cli_messages.py index e5bcd78..e3cb896 100644 --- a/test/functional/api/cas/cli_messages.py +++ b/test/functional/api/cas/cli_messages.py @@ -131,6 +131,10 @@ disallowed_param = [ r"Unrecognized option \S+" ] +operation_forbiden_in_standby = [ + r"The operation is not permited while the cache is in the standby mode" +] + def check_stderr_msg(output: Output, expected_messages): return __check_string_msg(output.stderr, expected_messages) From 66df560c4afe828d44dfd6ec05a80d07a0e31b33 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Tue, 12 Apr 2022 10:33:50 +0200 Subject: [PATCH 4/4] tests: add test_standby_neg_cli_management Signed-off-by: Michal Mielewczyk --- test/functional/tests/cli/test_cli_standby.py | 89 ++++++++++++++++++- 1 file changed, 86 insertions(+), 3 deletions(-) diff --git a/test/functional/tests/cli/test_cli_standby.py b/test/functional/tests/cli/test_cli_standby.py index 0cf4a23..67ed74d 100644 --- a/test/functional/tests/cli/test_cli_standby.py +++ b/test/functional/tests/cli/test_cli_standby.py @@ -10,7 +10,15 @@ from api.cas.cli import casadm_bin from core.test_run import TestRun from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan from test_utils.size import Size, Unit -from api.cas.cli_messages import check_stderr_msg, missing_param, disallowed_param +from api.cas.cli_messages import ( + check_stderr_msg, + missing_param, + disallowed_param, + operation_forbiden_in_standby, +) +from api.cas.cache_config import CacheLineSize +from api.cas import cli +from api.cas.ioclass_config import IoClass @pytest.mark.require_disk("cache", DiskTypeSet([DiskType.nand, DiskType.optane])) @@ -101,8 +109,9 @@ def test_activate_neg_cli_params(): with TestRun.step("Init standby cache"): cache_dev = Device(cache_device.path) - cache = standby_init(cache_dev=cache_dev, cache_id=cache_id, - cache_line_size=cache_line_size, force=True) + cache = standby_init( + cache_dev=cache_dev, cache_id=cache_id, cache_line_size=cache_line_size, force=True + ) with TestRun.step("Detach standby cache"): cache.standby_detach() @@ -159,3 +168,77 @@ def test_activate_neg_cli_params(): f'Expected error message in format "{disallowed_param[0]}" ' f'Got "{output.stderr}" instead.' ) + + +@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.nand, DiskType.optane])) +def test_standby_neg_cli_management(): + """ + title: Blocking management commands in standby state + description: | + Try executing management commands for a cache in standby state + pass_criteria: + - The execution is unsuccessful for blocked management commands + - The execution is successful for allowed management commands + - A proper error message is displayed for unsuccessful executions + """ + with TestRun.step("Prepare the device for the cache."): + device = TestRun.disks["cache"] + device.create_partitions([Size(500, Unit.MebiByte), Size(500, Unit.MebiByte)]) + cache_device = device.partitions[0] + core_device = device.partitions[1] + + with TestRun.step("Prepare the standby instance"): + cache_id = 1 + cache = casadm.standby_init( + cache_dev=cache_device, cache_id=cache_id, cache_line_size=32, force=True + ) + + ioclass_config_path = "/tmp/standby_cli_neg_mngt_test_ioclass_config_file.csv" + TestRun.executor.run(f"rm -rf {ioclass_config_path}") + random_ioclass_config = IoClass.generate_random_ioclass_list(5) + IoClass.save_list_to_config_file( + random_ioclass_config, ioclass_config_path=ioclass_config_path + ) + + blocked_mngt_commands = [ + cli.get_param_cutoff_cmd(str(cache_id), "1"), + cli.get_param_cleaning_cmd(str(cache_id)), + cli.get_param_cleaning_alru_cmd(str(cache_id)), + cli.get_param_cleaning_acp_cmd(str(cache_id)), + cli.set_param_cutoff_cmd(str(cache_id), "1", threshold="1"), + cli.set_param_cutoff_cmd(str(cache_id), policy="never"), + cli.set_param_cleaning_cmd(str(cache_id), policy="nop"), + cli.set_param_cleaning_alru_cmd(str(cache_id), wake_up="30"), + cli.set_param_cleaning_acp_cmd(str(cache_id), wake_up="100"), + cli.set_param_promotion_cmd(str(cache_id), policy="nhit"), + cli.set_param_promotion_nhit_cmd(str(cache_id), threshold="5"), + cli.set_cache_mode_cmd("wb", str(cache_id)), + cli.add_core_cmd(str(cache_id), core_device.path), + cli.remove_core_cmd(str(cache_id), "1"), + cli.remove_inactive_cmd(str(cache_id), "1"), + cli.reset_counters_cmd(str(cache_id)), + cli.flush_cache_cmd(str(cache_id)), + cli.flush_core_cmd(str(cache_id), "1"), + cli.load_io_classes_cmd(str(cache_id), ioclass_config_path), + cli.list_io_classes_cmd(str(cache_id), output_format="csv"), + cli.script_try_add_cmd(str(cache_id), core_device.path, core_id=1), + cli.script_purge_cache_cmd(str(cache_id)), + cli.script_purge_core_cmd(str(cache_id), "1"), + cli.script_detach_core_cmd(str(cache_id), "1"), + cli.script_remove_core_cmd(str(cache_id), "1"), + ] + + with TestRun.step("Try to execute forbidden management commands in standby mode"): + for cmd in blocked_mngt_commands: + + TestRun.LOGGER.info(f"Verify {cmd}") + output = TestRun.executor.run_expect_fail(cmd) + if not check_stderr_msg(output, operation_forbiden_in_standby): + TestRun.LOGGER.error( + f'Expected the following error message "{operation_forbiden_in_standby[0]}" ' + f'Got "{output.stderr}" instead.' + ) + + with TestRun.step("Stop the standby instance"): + TestRun.executor.run(f"rm -rf {ioclass_config_path}") + cache.stop()