From 1b7c425fae73064da3134ddfddb42978317c56c4 Mon Sep 17 00:00:00 2001 From: Slawomir Jankowski Date: Wed, 13 May 2020 12:06:08 +0200 Subject: [PATCH 1/3] Disable the possibility to use the 'load' and 'force' flags at once Signed-off-by: Slawomir Jankowski --- casadm/cas_main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/casadm/cas_main.c b/casadm/cas_main.c index 3414586..5e3172c 100644 --- a/casadm/cas_main.c +++ b/casadm/cas_main.c @@ -294,6 +294,11 @@ int handle_start() int status; struct stat device_info; + if (command_args_values.state == CACHE_INIT_LOAD && command_args_values.force) { + cas_printf(LOG_ERR, "Use of 'load' and 'force' simultaneously is forbidden.\n"); + return FAILURE; + } + cache_device = open(command_args_values.cache_device, O_RDONLY); if (cache_device < 0) { From 394313002bd295107a813d61eac15bde77dc0f37 Mon Sep 17 00:00:00 2001 From: Slawomir Jankowski Date: Wed, 13 May 2020 13:00:00 +0200 Subject: [PATCH 2/3] Add test for wrong flag combination in start command Signed-off-by: Slawomir Jankowski --- .../tests/cli/test_cli_start_stop.py | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/test/functional/tests/cli/test_cli_start_stop.py b/test/functional/tests/cli/test_cli_start_stop.py index e2ea233..f81be35 100644 --- a/test/functional/tests/cli/test_cli_start_stop.py +++ b/test/functional/tests/cli/test_cli_start_stop.py @@ -6,7 +6,8 @@ import pytest -from api.cas import casadm, casadm_parser +from api.cas import casadm, casadm_parser, cli_messages +from api.cas.cli import start_cmd from core.test_run import TestRun from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan from test_utils.size import Unit, Size @@ -80,3 +81,32 @@ def test_cli_add_remove_default_value(shortcut): TestRun.fail("No cache should be present after stopping the cache") if output.stdout != "No caches running": TestRun.fail(f"Invalid message, expected 'No caches running', got {output.stdout}") + + +@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand])) +def test_cli_load_and_force(): + """ + title: Test if it is possible to use start command with 'load' and 'force' flag at once + description: | + Try to start cache with 'load' and 'force' options at the same time + and check if it is not possible to do + pass_criteria: + - Start cache command with both 'force' and 'load' options should fail + - Proper message should be received + """ + with TestRun.step("Prepare cache."): + cache_device = TestRun.disks['cache'] + cache_device.create_partitions([Size(50, Unit.MebiByte)]) + cache_device = cache_device.partitions[0] + cache = casadm.start_cache(cache_device) + + with TestRun.step("Stop cache."): + cache.stop() + + with TestRun.step("Try to load cache with 'force'."): + output = TestRun.executor.run( + start_cmd(cache_dev=cache_device.system_path, force=True, load=True) + ) + if output.exit_code == 0: + TestRun.fail("Loading cache with 'force' option should fail.") + cli_messages.check_stderr_msg(output, cli_messages.load_and_force) From 0903541160c9dc8476f4debbbe09bf4eeb6d44ef Mon Sep 17 00:00:00 2001 From: Slawomir Jankowski Date: Wed, 13 May 2020 13:00:29 +0200 Subject: [PATCH 3/3] Add new error message to 'cli_mesages' Signed-off-by: Slawomir Jankowski --- 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 18feb8f..1ba8d87 100644 --- a/test/functional/api/cas/cli_messages.py +++ b/test/functional/api/cas/cli_messages.py @@ -59,6 +59,10 @@ stop_cache_mounted_core = [ r"Can\'t stop cache instance \d+\. Device /dev/cas\d+-\d+ is mounted\!" ] +load_and_force = [ + r"Use of \'load\' and \'force\' simultaneously is forbidden\." +] + def check_stderr_msg(output: Output, expected_messages): return __check_string_msg(output.stderr, expected_messages)