Skip to content

Commit

Permalink
test_add:test_fault_injection_core_in_raid
Browse files Browse the repository at this point in the history
Signed-off-by: Kamil Gierszewski <[email protected]>
  • Loading branch information
Kgierszx committed Oct 20, 2022
1 parent f5be72d commit 864d4ce
Show file tree
Hide file tree
Showing 19 changed files with 395 additions and 250 deletions.
45 changes: 35 additions & 10 deletions test/functional/api/cas/cli_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,23 +252,48 @@
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)
partition_not_suitable_for_array = [
r'\S+ is not suitable for this array'
]

device_or_resource_busy = [
r"cannot open \S+: Device or resource busy"
]


def check_stderr_msg_all(output: Output, expected_messages):
return __check_string_msg_all(output.stderr, expected_messages)


def check_stdout_msg_all(output: Output, expected_messages):
return __check_string_msg_all(output.stdout, expected_messages)


def check_stderr_msg_any(output: Output, expected_messages):
return __check_string_msg_any(output.stderr, expected_messages)

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

def check_stdout_msg_any(output: Output, expected_messages):
return __check_string_msg_any(output.stdout, expected_messages)

def __check_string_msg(text: str, expected_messages, negate=False):

def __check_string_msg_all(text: str, expected_messages):
msg_ok = True
for msg in expected_messages:
matches = re.search(msg, text)
if not matches and not negate:
if not matches:
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


def __check_string_msg_any(text: str, expected_messages):
msg_ok = False
for msg in expected_messages:
matches = re.search(msg, text)
if matches:
msg_ok = True
break
if not msg_ok:
TestRun.LOGGER.error(f"Message is incorrect: {text}.")
return msg_ok
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_stderr_msg_all(output, 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_stderr_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_stderr_msg_all(output, 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_stderr_msg_all(output, 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_stderr_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_stderr_msg_all(output, 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_stderr_msg_all, check_stdout_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_stdout_msg_all(output, 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_stdout_msg_all(output, 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_stdout_msg_all(output, 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_stdout_msg_all(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)
check_stdout_msg_all(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)
check_stdout_msg_all(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)
check_stdout_msg_all(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)
check_stdout_msg_all(output, remove_core_help)

output = TestRun.executor.run("casadm" + " --remove-detached"
+ (" -H" if shortcut else " --help"))
check_stdout_msg(output, remove_detached_help)
check_stdout_msg_all(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_help)
check_stdout_msg_all(output, list_help)

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

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

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

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

output = TestRun.executor.run("casadm" + " --zero-metadata"
+ (" -H" if shortcut else " --help"))
check_stdout_msg(output, zero_metadata_help)
check_stdout_msg_all(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)
check_stderr_msg_all(output, unrecognized_stderr)
check_stdout_msg_all(output, 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_stderr_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_stderr_msg_all(output, 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_stderr_msg_all(output, 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_stderr_msg_all(output, 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_stderr_msg_all(output, 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_stderr_msg_all(output, 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_stderr_msg_all(output, 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_stderr_msg_all(output, 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_stderr_msg_all(output, 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_stderr_msg_all(output, 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_stderr_msg_all(output, 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_stderr_msg_all(output, 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_stdout_msg_all(output, 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_stdout_msg_all(output, 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_stdout_msg_all(output, 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_stdout_msg_all(output, 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_stderr_msg_all(output, cli_messages.load_and_force)
Loading

0 comments on commit 864d4ce

Please sign in to comment.