From f6545f2b06218c8373eed511e428e68d38557916 Mon Sep 17 00:00:00 2001 From: Kamil Gierszewski Date: Tue, 10 Dec 2024 06:00:17 +0100 Subject: [PATCH 1/3] tests: remove duplicated test Signed-off-by: Kamil Gierszewski --- ...i_help_and_version.py => test_cli_help.py} | 31 +------------------ 1 file changed, 1 insertion(+), 30 deletions(-) rename test/functional/tests/cli/{test_cli_help_and_version.py => test_cli_help.py} (81%) diff --git a/test/functional/tests/cli/test_cli_help_and_version.py b/test/functional/tests/cli/test_cli_help.py similarity index 81% rename from test/functional/tests/cli/test_cli_help_and_version.py rename to test/functional/tests/cli/test_cli_help.py index 24eebe8..e87f172 100644 --- a/test/functional/tests/cli/test_cli_help_and_version.py +++ b/test/functional/tests/cli/test_cli_help.py @@ -1,15 +1,12 @@ # # Copyright(c) 2020-2022 Intel Corporation -# Copyright(c) 2024 Huawei Technologies Co., Ltd. +# Copyright(c) 2024-2025 Huawei Technologies Co., Ltd. # SPDX-License-Identifier: BSD-3-Clause # -import re - import pytest from api.cas import casadm -from api.cas.casadm_params import OutputFormat from api.cas.cli_help_messages import * from api.cas.cli_messages import check_stderr_msg, check_stdout_msg from core.test_run import TestRun @@ -99,29 +96,3 @@ def test_cli_help(shortcut): + (" -H" if shortcut else " --help")) check_stderr_msg(output, unrecognized_stderr) check_stdout_msg(output, unrecognized_stdout) - - -@pytest.mark.parametrize("output_format", OutputFormat) -@pytest.mark.parametrize("shortcut", [True, False]) -def test_cli_version(shortcut, output_format): - """ - title: Test for 'version' command. - description: Test if version displays. - pass_criteria: - - Proper OCL's components names displays in table with its versions. - """ - TestRun.LOGGER.info("Check OCL's version.") - output = casadm.print_version(output_format, shortcut).stdout - TestRun.LOGGER.info(output) - if not names_in_output(output) or not versions_in_output(output): - TestRun.fail("'Version' command failed.") - - -def names_in_output(output): - return ("CAS Cache Kernel Module" in output - and "CAS CLI Utility" in output) - - -def versions_in_output(output): - version_pattern = re.compile(r"(\d){2}\.(\d){2}\.(\d)\.(\d){4}.(\S)") - return len(version_pattern.findall(output)) == 2 From 4c78a9f0671aa07bd3f6d2646ccf33f39237394a Mon Sep 17 00:00:00 2001 From: Kamil Gierszewski Date: Wed, 11 Dec 2024 03:58:59 +0100 Subject: [PATCH 2/3] test-api: fix cli msg Signed-off-by: Kamil Gierszewski --- test/functional/api/cas/cli_help_messages.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/functional/api/cas/cli_help_messages.py b/test/functional/api/cas/cli_help_messages.py index 2e4ed67..a99f6c8 100644 --- a/test/functional/api/cas/cli_help_messages.py +++ b/test/functional/api/cas/cli_help_messages.py @@ -1,6 +1,6 @@ # # Copyright(c) 2020-2022 Intel Corporation -# Copyright(c) 2024 Huawei Technologies +# Copyright(c) 2024-2025 Huawei Technologies # SPDX-License-Identifier: BSD-3-Clause # @@ -192,7 +192,7 @@ remove_core_help = [ remove_inactive_help = [ - r"casadm --remove-inactive --cache-id \ --core-id \ \[option\.\.\.\]", + r"Usage: casadm --remove-inactive --cache-id \ --core-id \ \[option\.\.\.\]", r"Remove inactive core device from cache instance", r"Options that are valid with --remove-inactive are:", r"-i --cache-id \ Identifier of cache instance \<1-16384\>", From 7f2b8fb229c36cdb51b8c85ceb893ad8f3b76ee9 Mon Sep 17 00:00:00 2001 From: Kamil Gierszewski Date: Fri, 28 Feb 2025 16:02:00 +0100 Subject: [PATCH 3/3] tests: refactor test_cli_help test Signed-off-by: Kamil Gierszewski --- test/functional/tests/cli/test_cli_help.py | 115 +++++++-------------- 1 file changed, 39 insertions(+), 76 deletions(-) diff --git a/test/functional/tests/cli/test_cli_help.py b/test/functional/tests/cli/test_cli_help.py index e87f172..a0d4dbf 100644 --- a/test/functional/tests/cli/test_cli_help.py +++ b/test/functional/tests/cli/test_cli_help.py @@ -6,7 +6,6 @@ import pytest -from api.cas import casadm from api.cas.cli_help_messages import * from api.cas.cli_messages import check_stderr_msg, check_stdout_msg from core.test_run import TestRun @@ -16,83 +15,47 @@ from core.test_run import TestRun def test_cli_help(shortcut): """ title: Test for 'help' command. - description: Test if help for commands displays. + description: | + Verifies that running command with 'help' param displays correct message for each + available command. pass_criteria: - - Proper help displays for every command. + - Proper help message is displayed for every command. + - Proper help message is displayed after running command with wrong param. """ - TestRun.LOGGER.info("Run 'help' for every 'casadm' command.") - output = casadm.help(shortcut) - check_stdout_msg(output, casadm_help) + check_list_cmd = [ + (" -S", " --start-cache", start_cache_help), + (None, " --attach-cache", attach_cache_help), + (None, " --detach-cache", detach_cache_help), + (" -T", " --stop-cache", stop_cache_help), + (" -X", " --set-param", set_params_help), + (" -G", " --get-param", get_params_help), + (" -Q", " --set-cache-mode", set_cache_mode_help), + (" -A", " --add-core", add_core_help), + (" -R", " --remove-core", remove_core_help), + (None, " --remove-inactive", remove_inactive_help), + (None, " --remove-detached", remove_detached_help), + (" -L", " --list-caches", list_caches_help), + (" -P", " --stats", stats_help), + (" -Z", " --reset-counters", reset_counters_help), + (" -F", " --flush-cache", flush_cache_help), + (" -C", " --io-class", ioclass_help), + (" -V", " --version", version_help), + # (None, " --standby", standby_help), + (" -H", " --help", help_help), + (None, " --zero-metadata", zero_metadata_help), + ] + help = " -H" if shortcut else " --help" - output = TestRun.executor.run("casadm" + (" -S" if shortcut else " --start-cache") - + (" -H" if shortcut else " --help")) - check_stdout_msg(output, start_cache_help) + with TestRun.step("Run 'help' for every 'casadm' command and check output"): + for cmds in check_list_cmd: + cmd = cmds[0] if shortcut else cmds[1] - output = TestRun.executor.run("casadm" + (" -T" if shortcut else " --stop-cache") - + (" -H" if shortcut else " --help")) - check_stdout_msg(output, stop_cache_help) + if cmd: + output = TestRun.executor.run("casadm" + cmd + help) + check_stdout_msg(output, cmds[-1]) - output = TestRun.executor.run("casadm" + (" -X" if shortcut else " --set-param") - + (" -H" if shortcut else " --help")) - check_stdout_msg(output, set_params_help) - - output = TestRun.executor.run("casadm" + (" -G" if shortcut else " --get-param") - + (" -H" if shortcut else " --help")) - check_stdout_msg(output, get_params_help) - - output = TestRun.executor.run("casadm" + (" -Q" if shortcut else " --set-cache-mode") - + (" -H" if shortcut else " --help")) - check_stdout_msg(output, set_cache_mode_help) - - output = TestRun.executor.run("casadm" + (" -A" if shortcut else " --add-core") - + (" -H" if shortcut else " --help")) - check_stdout_msg(output, add_core_help) - - output = TestRun.executor.run("casadm" + (" -R" if shortcut else " --remove-core") - + (" -H" if shortcut else " --help")) - check_stdout_msg(output, remove_core_help) - - output = TestRun.executor.run("casadm" + " --remove-detached" - + (" -H" if shortcut else " --help")) - check_stdout_msg(output, remove_detached_help) - - output = TestRun.executor.run("casadm" + (" -L" if shortcut else " --list-caches") - + (" -H" if shortcut else " --help")) - check_stdout_msg(output, list_caches_help) - - output = TestRun.executor.run("casadm" + (" -P" if shortcut else " --stats") - + (" -H" if shortcut else " --help")) - check_stdout_msg(output, stats_help) - - output = TestRun.executor.run("casadm" + (" -Z" if shortcut else " --reset-counters") - + (" -H" if shortcut else " --help")) - check_stdout_msg(output, reset_counters_help) - - output = TestRun.executor.run("casadm" + (" -F" if shortcut else " --flush-cache") - + (" -H" if shortcut else " --help")) - check_stdout_msg(output, flush_cache_help) - - output = TestRun.executor.run("casadm" + (" -C" if shortcut else " --io-class") - + (" -H" if shortcut else " --help")) - check_stdout_msg(output, ioclass_help) - - output = TestRun.executor.run("casadm" + (" -V" if shortcut else " --version") - + (" -H" if shortcut else " --help")) - check_stdout_msg(output, version_help) - - output = TestRun.executor.run("casadm" + (" -H" if shortcut else " --help") - + (" -H" if shortcut else " --help")) - check_stdout_msg(output, help_help) - - output = TestRun.executor.run("casadm" + " --standby" - + (" -H" if shortcut else " --help")) - check_stdout_msg(output, standby_help) - - output = TestRun.executor.run("casadm" + " --zero-metadata" - + (" -H" if shortcut else " --help")) - check_stdout_msg(output, zero_metadata_help) - - output = TestRun.executor.run("casadm" + (" -Y" if shortcut else " --yell") - + (" -H" if shortcut else " --help")) - check_stderr_msg(output, unrecognized_stderr) - check_stdout_msg(output, unrecognized_stdout) + with TestRun.step("Run 'help' for command that doesn`t exist and check output"): + cmd = " -Y" if shortcut else " --yell" + output = TestRun.executor.run("casadm" + cmd + help) + check_stderr_msg(output, unrecognized_stderr) + check_stdout_msg(output, unrecognized_stdout)