Skip to content

Commit c283e55

Browse files
committed
adding new test
Signed-off-by: Karolina Rogowska <karolina.rogowska@intel.com>
1 parent ddd7d16 commit c283e55

File tree

2 files changed

+79
-6
lines changed

2 files changed

+79
-6
lines changed

test/functional/api/cas/cli_messages.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,29 @@
7070
r"or try other device with the same logical sector size as core device\."
7171
]
7272

73+
partition_not_suitable_for_array = [
74+
r"\S+ is not suitable for this array"
75+
]
76+
77+
device_or_resource_busy = [
78+
r"cannot open \S+: Device or resource busy"
79+
]
80+
7381

74-
def check_stderr_msg(output: Output, expected_messages):
75-
return __check_string_msg(output.stderr, expected_messages)
82+
def check_stderr_msg(output: Output, expected_messages, error_info=True):
83+
return __check_string_msg(output.stderr, expected_messages, error_info)
7684

7785

78-
def check_stdout_msg(output: Output, expected_messages):
79-
return __check_string_msg(output.stdout, expected_messages)
86+
def check_stdout_msg(output: Output, expected_messages, error_info=True):
87+
return __check_string_msg(output.stdout, expected_messages, error_info)
8088

8189

82-
def __check_string_msg(text: str, expected_messages):
90+
def __check_string_msg(text: str, expected_messages, error_info=True):
8391
msg_ok = True
8492
for msg in expected_messages:
8593
matches = re.search(msg, text)
8694
if not matches:
87-
TestRun.LOGGER.error(f"Message is incorrect, expected: {msg}\n actual: {text}.")
95+
if error_info:
96+
TestRun.LOGGER.error(f"Message is incorrect, expected: {msg}\n actual: {text}.")
8897
msg_ok = False
8998
return msg_ok
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#
2+
# Copyright(c) 2020 Intel Corporation
3+
# SPDX-License-Identifier: BSD-3-Clause-Clear
4+
#
5+
6+
import pytest
7+
8+
from api.cas import casadm, cli_messages
9+
from api.cas.cache_config import CacheMode
10+
from core.test_run import TestRun
11+
from storage_devices.disk import DiskType, DiskTypeSet
12+
from storage_devices.raid import Raid, RaidConfiguration, MetadataVariant, Level
13+
from test_utils.size import Size, Unit
14+
15+
16+
@pytest.mark.parametrizex("cache_mode", CacheMode)
17+
@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
18+
@pytest.mark.require_disk("core", DiskTypeSet([DiskType.sata, DiskType.hdd]))
19+
def test_fault_injection_core_in_raid(cache_mode):
20+
"""
21+
title: Test if OpenCAS rejects using core device to build SW RAID.
22+
description: |
23+
Test if OpenCAS handles properly attempting of use core device to build SW RAID.
24+
pass_criteria:
25+
- Expected to reject RAID creation with proper warning.
26+
"""
27+
with TestRun.step("Prepare CAS device."):
28+
cache_disk = TestRun.disks['cache']
29+
core_disk = TestRun.disks['core']
30+
cache_disk.create_partitions([Size(2, Unit.GibiByte)])
31+
core_disk.create_partitions([Size(2, Unit.GibiByte)] * 2)
32+
cache_dev = cache_disk.partitions[0]
33+
core_dev = core_disk.partitions[0]
34+
second_core_dev = core_disk.partitions[1]
35+
36+
cache = casadm.start_cache(cache_dev, cache_mode, force=True)
37+
core = cache.add_core(core_dev)
38+
39+
with TestRun.step("Attempt to use core device to build SW RAID."):
40+
raid_disk_1 = core_dev
41+
raid_disk_2 = second_core_dev
42+
43+
expected_msg_1 = cli_messages.partition_not_suitable_for_array
44+
expected_msg_2 = cli_messages.device_or_resource_busy
45+
46+
config = RaidConfiguration(
47+
level=Level.Raid1,
48+
metadata=MetadataVariant.Legacy,
49+
number_of_devices=2)
50+
51+
try:
52+
raid = Raid.create(config, [raid_disk_1, raid_disk_2])
53+
TestRun.LOGGER.error(f"RAID created successfully. Expected otherwise.")
54+
except Exception as ex:
55+
output = ex.output
56+
57+
with TestRun.step("Looking for any of 2 expected messages."):
58+
if cli_messages.check_stderr_msg(output, expected_msg_1, error_info=False) or \
59+
cli_messages.check_stderr_msg(output, expected_msg_2, error_info=False):
60+
TestRun.LOGGER.info("RAID not created. Found expected warning in exception message.")
61+
else:
62+
TestRun.LOGGER.error(f"RAID not created but warning message not as expected.\n"
63+
f"Actual: '{output}'.\n"
64+
f"Expected: '{expected_msg_1}' or '{expected_msg_2}'.")

0 commit comments

Comments
 (0)