Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_add:test_fault_injection_core_in_raid #1387

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions test/functional/api/cas/cli_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,23 +252,30 @@
r"Option '--cache-line-size \(-x\)' is not allowed"
]

def check_stderr_msg(output: Output, expected_messages, negate=False):
return __check_string_msg(output.stderr, expected_messages, negate)


def check_stdout_msg(output: Output, expected_messages, negate=False):
return __check_string_msg(output.stdout, expected_messages, negate)


def __check_string_msg(text: str, expected_messages, negate=False):
msg_ok = True
for msg in expected_messages:
matches = re.search(msg, text)
if not matches and not negate:
TestRun.LOGGER.error(f"Message is incorrect, expected: {msg}\n actual: {text}.")
msg_ok = False
elif matches and negate:
TestRun.LOGGER.error(f"Message is incorrect, expected to not find: {msg}\n "
f"actual: {text}.")
msg_ok = False
return msg_ok
mdadm_partition_not_suitable_for_array = [
r"\S+ is not suitable for this array"
]

mdadm_device_or_resource_busy = [
r"mdadm: cannot open \S+: Device or resource busy"
]
Comment on lines +255 to +261
Copy link
Contributor

@Deixx Deixx Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be probably moved to test-framework/test_tools/mdadm.py or just to test/functional/tests/fault_injection/test_fault_injection_core_in_raid.py



def check_string_msg_all(text: str, expected_messages):
if all([re.search(msg, text) for msg in expected_messages]):
return True
TestRun.LOGGER.error(
f"Message is incorrect, expected all of messages: {expected_messages}\n "
f'Got: "{text}" '
f"At least one expected message not found"
)
return False


def check_string_msg_any(text: str, expected_messages):
if any([re.search(m, text) for m in expected_messages]):
return True
TestRun.LOGGER.error(
f"Message is incorrect, expected one of: {expected_messages}\n " f'Got: "{text}"'
)
return False
2 changes: 1 addition & 1 deletion test/functional/tests/cache_ops/test_multilevel_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_remove_multilevel_core():
output = TestRun.executor.run_expect_fail(cli.remove_core_cmd(cache_id=str(cache1.cache_id),
core_id=str(core1.core_id),
force=True))
cli_messages.check_stderr_msg(output, cli_messages.remove_multilevel_core)
cli_messages.check_string_msg_all(output.stderr, cli_messages.remove_multilevel_core)

with TestRun.step("Stop cache."):
casadm.stop_all_caches()
6 changes: 3 additions & 3 deletions test/functional/tests/ci/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from core.test_run import TestRun
from api.cas import cli, casadm
from api.cas.cli_messages import (
check_stderr_msg,
check_string_msg_all,
start_cache_on_already_used_dev,
start_cache_with_existing_id
)
Expand Down Expand Up @@ -72,14 +72,14 @@ def test_negative_start_cache():
output = TestRun.executor.run_expect_fail(
cli.start_cmd(cache_dev_1.path, cache_id="2", force=True)
)
if not check_stderr_msg(output, start_cache_on_already_used_dev):
if not check_string_msg_all(output.stderr, start_cache_on_already_used_dev):
TestRun.fail(f"Received unexpected error message: {output.stderr}")

with TestRun.step("Start cache with the same ID on another cache device"):
output = TestRun.executor.run_expect_fail(
cli.start_cmd(cache_dev_2.path, cache_id="1", force=True)
)
if not check_stderr_msg(output, start_cache_with_existing_id):
if not check_string_msg_all(output.stderr, start_cache_with_existing_id):
TestRun.fail(f"Received unexpected error message: {output.stderr}")


Expand Down
4 changes: 2 additions & 2 deletions test/functional/tests/ci/test_recovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from api.cas import casadm
from api.cas.cache_config import CacheMode
from api.cas.cli import casadm_bin
from api.cas.cli_messages import check_stderr_msg, stop_cache_errors
from api.cas.cli_messages import check_string_msg_all, stop_cache_errors
from core.test_run import TestRun
from storage_devices.disk import DiskTypeLowerThan, DiskTypeSet, DiskType, Disk
from test_tools.dd import Dd
Expand Down Expand Up @@ -204,7 +204,7 @@ def dirty_stop(cache_disk, caches: list):
for cache in caches:
cmd = f"{casadm_bin} --stop-cache --cache-id {cache.cache_id} --no-data-flush"
output = TestRun.executor.run(cmd)
if not check_stderr_msg(output, stop_cache_errors):
if not check_string_msg_all(output.stderr, stop_cache_errors):
TestRun.fail(f"Cache {cache.cache_id} stopping should fail.")

with TestRun.step("Turn on devices."):
Expand Down
42 changes: 21 additions & 21 deletions test/functional/tests/cli/test_cli_help_and_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
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 api.cas.cli_messages import check_string_msg_all
from core.test_run import TestRun


Expand All @@ -24,80 +24,80 @@ def test_cli_help(shortcut):
"""
TestRun.LOGGER.info("Run 'help' for every 'casadm' command.")
output = casadm.help(shortcut)
check_stdout_msg(output, casadm_help)
check_string_msg_all(output.stdout, casadm_help)

output = TestRun.executor.run("casadm" + (" -S" if shortcut else " --start-cache")
+ (" -H" if shortcut else " --help"))
check_stdout_msg(output, start_cache_help)
check_string_msg_all(output.stdout, start_cache_help)

output = TestRun.executor.run("casadm" + (" -T" if shortcut else " --stop-cache")
+ (" -H" if shortcut else " --help"))
check_stdout_msg(output, stop_cache_help)
check_string_msg_all(output.stdout, stop_cache_help)

output = TestRun.executor.run("casadm" + (" -X" if shortcut else " --set-param")
+ (" -H" if shortcut else " --help"))
check_stdout_msg(output, set_params_help)
check_string_msg_all(output.stdout, 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)
check_string_msg_all(output.stdout, 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)
check_string_msg_all(output.stdout, 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)
check_string_msg_all(output.stdout, 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)
check_string_msg_all(output.stdout, remove_core_help)

output = TestRun.executor.run("casadm" + " --remove-detached"
+ (" -H" if shortcut else " --help"))
check_stdout_msg(output, remove_detached_help)
check_string_msg_all(output.stdout, remove_detached_help)

output = TestRun.executor.run("casadm" + (" -L" if shortcut else " --list-caches")
+ (" -H" if shortcut else " --help"))
check_stdout_msg(output, list_help)
check_string_msg_all(output.stdout, list_help)

output = TestRun.executor.run("casadm" + (" -P" if shortcut else " --stats")
+ (" -H" if shortcut else " --help"))
check_stdout_msg(output, stats_help)
check_string_msg_all(output.stdout, 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)
check_string_msg_all(output.stdout, 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)
check_string_msg_all(output.stdout, 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)
check_string_msg_all(output.stdout, ioclass_help)

output = TestRun.executor.run("casadm" + (" -V" if shortcut else " --version")
+ (" -H" if shortcut else " --help"))
check_stdout_msg(output, version_help)
check_string_msg_all(output.stdout, version_help)

output = TestRun.executor.run("casadm" + (" -H" if shortcut else " --help")
+ (" -H" if shortcut else " --help"))
check_stdout_msg(output, help_help)
check_string_msg_all(output.stdout, help_help)

output = TestRun.executor.run("casadm" + " --standby"
+ (" -H" if shortcut else " --help"))
check_stdout_msg(output, standby_help)
check_string_msg_all(output.stdout, standby_help)

output = TestRun.executor.run("casadm" + " --zero-metadata"
+ (" -H" if shortcut else " --help"))
check_stdout_msg(output, zero_metadata_help)
check_string_msg_all(output.stdout, 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)
check_string_msg_all(output.stderr, unrecognized_stderr)
check_string_msg_all(output.stdout, unrecognized_stdout)


@pytest.mark.parametrize("output_format", OutputFormat)
Expand Down
24 changes: 12 additions & 12 deletions test/functional/tests/cli/test_cli_standby.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from test_utils.output import CmdException
from test_utils.size import Size, Unit
from api.cas.cli_messages import (
check_stderr_msg,
check_string_msg_all,
missing_param,
disallowed_param,
operation_forbiden_in_standby,
Expand Down Expand Up @@ -72,7 +72,7 @@ def test_standby_neg_cli_params():
TestRun.LOGGER.error(
f'"{tested_cmd}" command succeeded despite missing required "{name}" parameter!'
)
if not check_stderr_msg(output, missing_param) or name not in output.stderr:
if not check_string_msg_all(output.stderr, missing_param) or name not in output.stderr:
TestRun.LOGGER.error(
f'Expected error message in format "{missing_param[0]}" with "{name}" '
f'(the missing param). Got "{output.stderr}" instead.'
Expand All @@ -98,7 +98,7 @@ def test_standby_neg_cli_params():
TestRun.LOGGER.error(
f'"{tested_cmd}" command succeeded despite disallowed "{name}" parameter!'
)
if not check_stderr_msg(output, disallowed_param):
if not check_string_msg_all(output.stderr, disallowed_param):
TestRun.LOGGER.error(
f'Expected error message in format "{disallowed_param[0]}" '
f'Got "{output.stderr}" instead.'
Expand Down Expand Up @@ -153,7 +153,7 @@ def test_activate_neg_cli_params():
f'"{tested_cmd}" command succeeded despite missing obligatory'
f' "{name}" parameter!'
)
if not check_stderr_msg(output, missing_param) or name not in output.stderr:
if not check_string_msg_all(ououtput.stderrtput, missing_param) or name not in output.stderr:
TestRun.LOGGER.error(
f'Expected error message in format "{missing_param[0]}" with "{name}" '
f'(the missing param). Got "{output.stderr}" instead.'
Expand All @@ -178,7 +178,7 @@ def test_activate_neg_cli_params():
TestRun.LOGGER.error(
f'"{tested_cmd}" command succeeded despite disallowed "{name}" parameter!'
)
if not check_stderr_msg(output, expected_error_message):
if not check_string_msg_all(output.stderr, expected_error_message):
TestRun.LOGGER.error(
f'Expected error message in format "{expected_error_message[0]}" '
f'Got "{output.stderr}" instead.'
Expand Down Expand Up @@ -250,7 +250,7 @@ def test_standby_neg_cli_management():

TestRun.LOGGER.info(f"Verify {cmd}")
output = TestRun.executor.run_expect_fail(cmd)
if not check_stderr_msg(output, operation_forbiden_in_standby):
if not check_string_msg_all(output.stderr, operation_forbiden_in_standby):
TestRun.LOGGER.error(
f'Expected the following error message "{operation_forbiden_in_standby[0]}" '
f'Got "{output.stderr}" instead.'
Expand Down Expand Up @@ -289,7 +289,7 @@ def test_start_neg_cli_flags():
mutually_exclusive_cmd_init = f"{casadm_bin} --standby --init --load" \
f" {init_required_params}"
output = TestRun.executor.run_expect_fail(mutually_exclusive_cmd_init)
if not check_stderr_msg(output, mutually_exclusive_params_init):
if not check_string_msg_all(output.stderr, mutually_exclusive_params_init):
TestRun.LOGGER.error(
f'Expected error message in format '
f'"{mutually_exclusive_params_init[0]}"'
Expand All @@ -307,7 +307,7 @@ def test_start_neg_cli_flags():

for cmd in mutually_exclusive_cmd_load:
output = TestRun.executor.run_expect_fail(cmd)
if not check_stderr_msg(output, mutually_exclusive_params_load):
if not check_string_msg_all(output.stderr, mutually_exclusive_params_load):
TestRun.LOGGER.error(
f'Expected error message in format '
f'"{mutually_exclusive_params_load[0]}"'
Expand Down Expand Up @@ -353,7 +353,7 @@ def test_activate_without_detach():
cmd = f"{casadm_bin} --standby --activate --cache-id {cache_id} --cache-device " \
f"{cache_dev.path}"
output = TestRun.executor.run(cmd)
if not check_stderr_msg(output, activate_without_detach):
if not check_string_msg_all(output.stderr, activate_without_detach):
TestRun.LOGGER.error(
f'Expected error message in format '
f'"{activate_without_detach[0]}"'
Expand Down Expand Up @@ -452,7 +452,7 @@ def test_activate_neg_cache_line_size():
with TestRun.step("Try to activate cache instance"):
with pytest.raises(CmdException) as cmdExc:
output = standby_cache.standby_activate(standby_cache_dev)
if not check_stderr_msg(output, cache_line_size_mismatch):
if not check_string_msg_all(output.stderr, cache_line_size_mismatch):
TestRun.LOGGER.error(
f'Expected error message in format '
f'"{cache_line_size_mismatch[0]}"'
Expand Down Expand Up @@ -507,7 +507,7 @@ def test_standby_init_with_preexisting_metadata():
cache_line_size=str(int(cls.value.value / Unit.KibiByte.value)),
)
)
if not check_stderr_msg(output, start_cache_with_existing_metadata):
if not check_string_msg_all(output.stderr, start_cache_with_existing_metadata):
TestRun.LOGGER.error(
f"Invalid error message. Expected {start_cache_with_existing_metadata}."
f"Got {output.stderr}"
Expand Down Expand Up @@ -558,7 +558,7 @@ def test_standby_init_with_preexisting_filesystem(filesystem):
cache_line_size=str(int(cls.value.value / Unit.KibiByte.value)),
)
)
if not check_stderr_msg(output, standby_init_with_existing_filesystem):
if not check_string_msg_all(output.stderr, standby_init_with_existing_filesystem):
TestRun.LOGGER.error(
f"Invalid error message. Expected {standby_init_with_existing_filesystem}."
f"Got {output.stderr}"
Expand Down
12 changes: 6 additions & 6 deletions test/functional/tests/cli/test_cli_start_stop.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright(c) 2019-2021 Intel Corporation
# Copyright(c) 2019-2022 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause
#

Expand Down Expand Up @@ -54,7 +54,7 @@ def test_cli_start_stop_default_id(shortcut):
TestRun.fail(f"There is a wrong number of caches found in the OS: {len(caches)}."
f"\nNo cache should be present after stopping the cache.")
output = casadm.list_caches(shortcut=shortcut)
cli_messages.check_stdout_msg(output, cli_messages.no_caches_running)
cli_messages.check_string_msg_all(output.stdout, cli_messages.no_caches_running)


@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.nand, DiskType.optane]))
Expand Down Expand Up @@ -97,7 +97,7 @@ def test_cli_start_stop_custom_id(shortcut):
TestRun.fail(f"There is a wrong number of caches found in the OS: {len(caches)}."
f"\nNo cache should be present after stopping the cache.")
output = casadm.list_caches(shortcut=shortcut)
cli_messages.check_stdout_msg(output, cli_messages.no_caches_running)
cli_messages.check_string_msg_all(output.stdout, cli_messages.no_caches_running)


@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.nand, DiskType.optane]))
Expand Down Expand Up @@ -148,7 +148,7 @@ def test_cli_add_remove_default_id(shortcut):
if len(caches) != 0:
TestRun.fail("No cache should be present after stopping the cache.")
output = casadm.list_caches(shortcut=shortcut)
cli_messages.check_stdout_msg(output, cli_messages.no_caches_running)
cli_messages.check_string_msg_all(output.stdout, cli_messages.no_caches_running)


@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.nand, DiskType.optane]))
Expand Down Expand Up @@ -201,7 +201,7 @@ def test_cli_add_remove_custom_id(shortcut):
if len(caches) != 0:
TestRun.fail("No cache should be present after stopping the cache.")
output = casadm.list_caches(shortcut=shortcut)
cli_messages.check_stdout_msg(output, cli_messages.no_caches_running)
cli_messages.check_string_msg_all(output.stdout, cli_messages.no_caches_running)


@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
Expand Down Expand Up @@ -231,4 +231,4 @@ def test_cli_load_and_force(shortcut):
)
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)
cli_messages.check_string_msg_all(output.stderr, cli_messages.load_and_force)
Loading