Skip to content

Commit 864d4ce

Browse files
committed
test_add:test_fault_injection_core_in_raid
Signed-off-by: Kamil Gierszewski <[email protected]>
1 parent f5be72d commit 864d4ce

19 files changed

+395
-250
lines changed

test/functional/api/cas/cli_messages.py

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,23 +252,48 @@
252252
r"Option '--cache-line-size \(-x\)' is not allowed"
253253
]
254254

255-
def check_stderr_msg(output: Output, expected_messages, negate=False):
256-
return __check_string_msg(output.stderr, expected_messages, negate)
255+
partition_not_suitable_for_array = [
256+
r'\S+ is not suitable for this array'
257+
]
258+
259+
device_or_resource_busy = [
260+
r"cannot open \S+: Device or resource busy"
261+
]
262+
263+
264+
def check_stderr_msg_all(output: Output, expected_messages):
265+
return __check_string_msg_all(output.stderr, expected_messages)
266+
267+
268+
def check_stdout_msg_all(output: Output, expected_messages):
269+
return __check_string_msg_all(output.stdout, expected_messages)
270+
257271

272+
def check_stderr_msg_any(output: Output, expected_messages):
273+
return __check_string_msg_any(output.stderr, expected_messages)
258274

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

276+
def check_stdout_msg_any(output: Output, expected_messages):
277+
return __check_string_msg_any(output.stdout, expected_messages)
262278

263-
def __check_string_msg(text: str, expected_messages, negate=False):
279+
280+
def __check_string_msg_all(text: str, expected_messages):
264281
msg_ok = True
265282
for msg in expected_messages:
266283
matches = re.search(msg, text)
267-
if not matches and not negate:
284+
if not matches:
268285
TestRun.LOGGER.error(f"Message is incorrect, expected: {msg}\n actual: {text}.")
269286
msg_ok = False
270-
elif matches and negate:
271-
TestRun.LOGGER.error(f"Message is incorrect, expected to not find: {msg}\n "
272-
f"actual: {text}.")
273-
msg_ok = False
287+
return msg_ok
288+
289+
290+
def __check_string_msg_any(text: str, expected_messages):
291+
msg_ok = False
292+
for msg in expected_messages:
293+
matches = re.search(msg, text)
294+
if matches:
295+
msg_ok = True
296+
break
297+
if not msg_ok:
298+
TestRun.LOGGER.error(f"Message is incorrect: {text}.")
274299
return msg_ok

test/functional/tests/cache_ops/test_multilevel_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_remove_multilevel_core():
4949
output = TestRun.executor.run_expect_fail(cli.remove_core_cmd(cache_id=str(cache1.cache_id),
5050
core_id=str(core1.core_id),
5151
force=True))
52-
cli_messages.check_stderr_msg(output, cli_messages.remove_multilevel_core)
52+
cli_messages.check_stderr_msg_all(output, cli_messages.remove_multilevel_core)
5353

5454
with TestRun.step("Stop cache."):
5555
casadm.stop_all_caches()

test/functional/tests/ci/test_basic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from core.test_run import TestRun
1010
from api.cas import cli, casadm
1111
from api.cas.cli_messages import (
12-
check_stderr_msg,
12+
check_stderr_msg_all,
1313
start_cache_on_already_used_dev,
1414
start_cache_with_existing_id
1515
)
@@ -72,14 +72,14 @@ def test_negative_start_cache():
7272
output = TestRun.executor.run_expect_fail(
7373
cli.start_cmd(cache_dev_1.path, cache_id="2", force=True)
7474
)
75-
if not check_stderr_msg(output, start_cache_on_already_used_dev):
75+
if not check_stderr_msg_all(output, start_cache_on_already_used_dev):
7676
TestRun.fail(f"Received unexpected error message: {output.stderr}")
7777

7878
with TestRun.step("Start cache with the same ID on another cache device"):
7979
output = TestRun.executor.run_expect_fail(
8080
cli.start_cmd(cache_dev_2.path, cache_id="1", force=True)
8181
)
82-
if not check_stderr_msg(output, start_cache_with_existing_id):
82+
if not check_stderr_msg_all(output, start_cache_with_existing_id):
8383
TestRun.fail(f"Received unexpected error message: {output.stderr}")
8484

8585

test/functional/tests/ci/test_recovery.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from api.cas import casadm
99
from api.cas.cache_config import CacheMode
1010
from api.cas.cli import casadm_bin
11-
from api.cas.cli_messages import check_stderr_msg, stop_cache_errors
11+
from api.cas.cli_messages import check_stderr_msg_all, stop_cache_errors
1212
from core.test_run import TestRun
1313
from storage_devices.disk import DiskTypeLowerThan, DiskTypeSet, DiskType, Disk
1414
from test_tools.dd import Dd
@@ -204,7 +204,7 @@ def dirty_stop(cache_disk, caches: list):
204204
for cache in caches:
205205
cmd = f"{casadm_bin} --stop-cache --cache-id {cache.cache_id} --no-data-flush"
206206
output = TestRun.executor.run(cmd)
207-
if not check_stderr_msg(output, stop_cache_errors):
207+
if not check_stderr_msg_all(output, stop_cache_errors):
208208
TestRun.fail(f"Cache {cache.cache_id} stopping should fail.")
209209

210210
with TestRun.step("Turn on devices."):

test/functional/tests/cli/test_cli_help_and_version.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from api.cas import casadm
1111
from api.cas.casadm_params import OutputFormat
1212
from api.cas.cli_help_messages import *
13-
from api.cas.cli_messages import check_stderr_msg, check_stdout_msg
13+
from api.cas.cli_messages import check_stderr_msg_all, check_stdout_msg_all
1414
from core.test_run import TestRun
1515

1616

@@ -24,80 +24,80 @@ def test_cli_help(shortcut):
2424
"""
2525
TestRun.LOGGER.info("Run 'help' for every 'casadm' command.")
2626
output = casadm.help(shortcut)
27-
check_stdout_msg(output, casadm_help)
27+
check_stdout_msg_all(output, casadm_help)
2828

2929
output = TestRun.executor.run("casadm" + (" -S" if shortcut else " --start-cache")
3030
+ (" -H" if shortcut else " --help"))
31-
check_stdout_msg(output, start_cache_help)
31+
check_stdout_msg_all(output, start_cache_help)
3232

3333
output = TestRun.executor.run("casadm" + (" -T" if shortcut else " --stop-cache")
3434
+ (" -H" if shortcut else " --help"))
35-
check_stdout_msg(output, stop_cache_help)
35+
check_stdout_msg_all(output, stop_cache_help)
3636

3737
output = TestRun.executor.run("casadm" + (" -X" if shortcut else " --set-param")
3838
+ (" -H" if shortcut else " --help"))
39-
check_stdout_msg(output, set_params_help)
39+
check_stdout_msg_all(output, set_params_help)
4040

4141
output = TestRun.executor.run("casadm" + (" -G" if shortcut else " --get-param")
4242
+ (" -H" if shortcut else " --help"))
43-
check_stdout_msg(output, get_params_help)
43+
check_stdout_msg_all(output, get_params_help)
4444

4545
output = TestRun.executor.run("casadm" + (" -Q" if shortcut else " --set-cache-mode")
4646
+ (" -H" if shortcut else " --help"))
47-
check_stdout_msg(output, set_cache_mode_help)
47+
check_stdout_msg_all(output, set_cache_mode_help)
4848

4949
output = TestRun.executor.run("casadm" + (" -A" if shortcut else " --add-core")
5050
+ (" -H" if shortcut else " --help"))
51-
check_stdout_msg(output, add_core_help)
51+
check_stdout_msg_all(output, add_core_help)
5252

5353
output = TestRun.executor.run("casadm" + (" -R" if shortcut else " --remove-core")
5454
+ (" -H" if shortcut else " --help"))
55-
check_stdout_msg(output, remove_core_help)
55+
check_stdout_msg_all(output, remove_core_help)
5656

5757
output = TestRun.executor.run("casadm" + " --remove-detached"
5858
+ (" -H" if shortcut else " --help"))
59-
check_stdout_msg(output, remove_detached_help)
59+
check_stdout_msg_all(output, remove_detached_help)
6060

6161
output = TestRun.executor.run("casadm" + (" -L" if shortcut else " --list-caches")
6262
+ (" -H" if shortcut else " --help"))
63-
check_stdout_msg(output, list_help)
63+
check_stdout_msg_all(output, list_help)
6464

6565
output = TestRun.executor.run("casadm" + (" -P" if shortcut else " --stats")
6666
+ (" -H" if shortcut else " --help"))
67-
check_stdout_msg(output, stats_help)
67+
check_stdout_msg_all(output, stats_help)
6868

6969
output = TestRun.executor.run("casadm" + (" -Z" if shortcut else " --reset-counters")
7070
+ (" -H" if shortcut else " --help"))
71-
check_stdout_msg(output, reset_counters_help)
71+
check_stdout_msg_all(output, reset_counters_help)
7272

7373
output = TestRun.executor.run("casadm" + (" -F" if shortcut else " --flush-cache")
7474
+ (" -H" if shortcut else " --help"))
75-
check_stdout_msg(output, flush_cache_help)
75+
check_stdout_msg_all(output, flush_cache_help)
7676

7777
output = TestRun.executor.run("casadm" + (" -C" if shortcut else " --io-class")
7878
+ (" -H" if shortcut else " --help"))
79-
check_stdout_msg(output, ioclass_help)
79+
check_stdout_msg_all(output, ioclass_help)
8080

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

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

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

9393
output = TestRun.executor.run("casadm" + " --zero-metadata"
9494
+ (" -H" if shortcut else " --help"))
95-
check_stdout_msg(output, zero_metadata_help)
95+
check_stdout_msg_all(output, zero_metadata_help)
9696

9797
output = TestRun.executor.run("casadm" + (" -Y" if shortcut else " --yell")
9898
+ (" -H" if shortcut else " --help"))
99-
check_stderr_msg(output, unrecognized_stderr)
100-
check_stdout_msg(output, unrecognized_stdout)
99+
check_stderr_msg_all(output, unrecognized_stderr)
100+
check_stdout_msg_all(output, unrecognized_stdout)
101101

102102

103103
@pytest.mark.parametrize("output_format", OutputFormat)

test/functional/tests/cli/test_cli_standby.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from test_utils.output import CmdException
1919
from test_utils.size import Size, Unit
2020
from api.cas.cli_messages import (
21-
check_stderr_msg,
21+
check_stderr_msg_all,
2222
missing_param,
2323
disallowed_param,
2424
operation_forbiden_in_standby,
@@ -72,7 +72,7 @@ def test_standby_neg_cli_params():
7272
TestRun.LOGGER.error(
7373
f'"{tested_cmd}" command succeeded despite missing required "{name}" parameter!'
7474
)
75-
if not check_stderr_msg(output, missing_param) or name not in output.stderr:
75+
if not check_stderr_msg_all(output, missing_param) or name not in output.stderr:
7676
TestRun.LOGGER.error(
7777
f'Expected error message in format "{missing_param[0]}" with "{name}" '
7878
f'(the missing param). Got "{output.stderr}" instead.'
@@ -98,7 +98,7 @@ def test_standby_neg_cli_params():
9898
TestRun.LOGGER.error(
9999
f'"{tested_cmd}" command succeeded despite disallowed "{name}" parameter!'
100100
)
101-
if not check_stderr_msg(output, disallowed_param):
101+
if not check_stderr_msg_all(output, disallowed_param):
102102
TestRun.LOGGER.error(
103103
f'Expected error message in format "{disallowed_param[0]}" '
104104
f'Got "{output.stderr}" instead.'
@@ -153,7 +153,7 @@ def test_activate_neg_cli_params():
153153
f'"{tested_cmd}" command succeeded despite missing obligatory'
154154
f' "{name}" parameter!'
155155
)
156-
if not check_stderr_msg(output, missing_param) or name not in output.stderr:
156+
if not check_stderr_msg_all(output, missing_param) or name not in output.stderr:
157157
TestRun.LOGGER.error(
158158
f'Expected error message in format "{missing_param[0]}" with "{name}" '
159159
f'(the missing param). Got "{output.stderr}" instead.'
@@ -178,7 +178,7 @@ def test_activate_neg_cli_params():
178178
TestRun.LOGGER.error(
179179
f'"{tested_cmd}" command succeeded despite disallowed "{name}" parameter!'
180180
)
181-
if not check_stderr_msg(output, expected_error_message):
181+
if not check_stderr_msg_all(output, expected_error_message):
182182
TestRun.LOGGER.error(
183183
f'Expected error message in format "{expected_error_message[0]}" '
184184
f'Got "{output.stderr}" instead.'
@@ -250,7 +250,7 @@ def test_standby_neg_cli_management():
250250

251251
TestRun.LOGGER.info(f"Verify {cmd}")
252252
output = TestRun.executor.run_expect_fail(cmd)
253-
if not check_stderr_msg(output, operation_forbiden_in_standby):
253+
if not check_stderr_msg_all(output, operation_forbiden_in_standby):
254254
TestRun.LOGGER.error(
255255
f'Expected the following error message "{operation_forbiden_in_standby[0]}" '
256256
f'Got "{output.stderr}" instead.'
@@ -289,7 +289,7 @@ def test_start_neg_cli_flags():
289289
mutually_exclusive_cmd_init = f"{casadm_bin} --standby --init --load" \
290290
f" {init_required_params}"
291291
output = TestRun.executor.run_expect_fail(mutually_exclusive_cmd_init)
292-
if not check_stderr_msg(output, mutually_exclusive_params_init):
292+
if not check_stderr_msg_all(output, mutually_exclusive_params_init):
293293
TestRun.LOGGER.error(
294294
f'Expected error message in format '
295295
f'"{mutually_exclusive_params_init[0]}"'
@@ -307,7 +307,7 @@ def test_start_neg_cli_flags():
307307

308308
for cmd in mutually_exclusive_cmd_load:
309309
output = TestRun.executor.run_expect_fail(cmd)
310-
if not check_stderr_msg(output, mutually_exclusive_params_load):
310+
if not check_stderr_msg_all(output, mutually_exclusive_params_load):
311311
TestRun.LOGGER.error(
312312
f'Expected error message in format '
313313
f'"{mutually_exclusive_params_load[0]}"'
@@ -353,7 +353,7 @@ def test_activate_without_detach():
353353
cmd = f"{casadm_bin} --standby --activate --cache-id {cache_id} --cache-device " \
354354
f"{cache_dev.path}"
355355
output = TestRun.executor.run(cmd)
356-
if not check_stderr_msg(output, activate_without_detach):
356+
if not check_stderr_msg_all(output, activate_without_detach):
357357
TestRun.LOGGER.error(
358358
f'Expected error message in format '
359359
f'"{activate_without_detach[0]}"'
@@ -452,7 +452,7 @@ def test_activate_neg_cache_line_size():
452452
with TestRun.step("Try to activate cache instance"):
453453
with pytest.raises(CmdException) as cmdExc:
454454
output = standby_cache.standby_activate(standby_cache_dev)
455-
if not check_stderr_msg(output, cache_line_size_mismatch):
455+
if not check_stderr_msg_all(output, cache_line_size_mismatch):
456456
TestRun.LOGGER.error(
457457
f'Expected error message in format '
458458
f'"{cache_line_size_mismatch[0]}"'
@@ -507,7 +507,7 @@ def test_standby_init_with_preexisting_metadata():
507507
cache_line_size=str(int(cls.value.value / Unit.KibiByte.value)),
508508
)
509509
)
510-
if not check_stderr_msg(output, start_cache_with_existing_metadata):
510+
if not check_stderr_msg_all(output, start_cache_with_existing_metadata):
511511
TestRun.LOGGER.error(
512512
f"Invalid error message. Expected {start_cache_with_existing_metadata}."
513513
f"Got {output.stderr}"
@@ -558,7 +558,7 @@ def test_standby_init_with_preexisting_filesystem(filesystem):
558558
cache_line_size=str(int(cls.value.value / Unit.KibiByte.value)),
559559
)
560560
)
561-
if not check_stderr_msg(output, standby_init_with_existing_filesystem):
561+
if not check_stderr_msg_all(output, standby_init_with_existing_filesystem):
562562
TestRun.LOGGER.error(
563563
f"Invalid error message. Expected {standby_init_with_existing_filesystem}."
564564
f"Got {output.stderr}"

test/functional/tests/cli/test_cli_start_stop.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright(c) 2019-2021 Intel Corporation
2+
# Copyright(c) 2019-2022 Intel Corporation
33
# SPDX-License-Identifier: BSD-3-Clause
44
#
55

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

5959

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

102102

103103
@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.nand, DiskType.optane]))
@@ -148,7 +148,7 @@ def test_cli_add_remove_default_id(shortcut):
148148
if len(caches) != 0:
149149
TestRun.fail("No cache should be present after stopping the cache.")
150150
output = casadm.list_caches(shortcut=shortcut)
151-
cli_messages.check_stdout_msg(output, cli_messages.no_caches_running)
151+
cli_messages.check_stdout_msg_all(output, cli_messages.no_caches_running)
152152

153153

154154
@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.nand, DiskType.optane]))
@@ -201,7 +201,7 @@ def test_cli_add_remove_custom_id(shortcut):
201201
if len(caches) != 0:
202202
TestRun.fail("No cache should be present after stopping the cache.")
203203
output = casadm.list_caches(shortcut=shortcut)
204-
cli_messages.check_stdout_msg(output, cli_messages.no_caches_running)
204+
cli_messages.check_stdout_msg_all(output, cli_messages.no_caches_running)
205205

206206

207207
@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
@@ -231,4 +231,4 @@ def test_cli_load_and_force(shortcut):
231231
)
232232
if output.exit_code == 0:
233233
TestRun.fail("Loading cache with 'force' option should fail.")
234-
cli_messages.check_stderr_msg(output, cli_messages.load_and_force)
234+
cli_messages.check_stderr_msg_all(output, cli_messages.load_and_force)

0 commit comments

Comments
 (0)