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 Dec 6, 2022
1 parent b7de338 commit c470d87
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 16 deletions.
38 changes: 22 additions & 16 deletions test/functional/api/cas/cli_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,24 +252,30 @@
r"Option '--cache-line-size \(-x\)' is not allowed"
]

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"
]


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:
TestRun.LOGGER.error(f"Message is incorrect, expected: {msg}\n actual: {text}.")
msg_ok = False
return msg_ok
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):
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
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#
# Copyright(c) 2022 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause
#

import pytest
from api.cas import casadm
from api.cas.cache_config import CacheMode
from core.test_run import TestRun
from storage_devices.disk import DiskType, DiskTypeSet
from storage_devices.raid import Raid, RaidConfiguration, MetadataVariant, Level
from test_utils.size import Size, Unit
from api.cas.cli_messages import (
mdadm_partition_not_suitable_for_array,
mdadm_device_or_resource_busy,
check_string_msg_any,
)

expected_msg_1 = mdadm_partition_not_suitable_for_array
expected_msg_2 = mdadm_device_or_resource_busy


@pytest.mark.parametrizex("cache_mode", [CacheMode.WB, CacheMode.WT])
@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
@pytest.mark.require_disk("core", DiskTypeSet([DiskType.sata, DiskType.hdd]))
@pytest.mark.require_disk("core2", DiskTypeSet([DiskType.sata, DiskType.hdd]))
def test_fault_injection_core_in_raid(cache_mode):
"""
title: Try to create raid on device used as a core device
description: Verify that it is impossible to use an underlying core disk as raid member
pass_criteria:
- Expected to reject RAID creation with proper warning.
"""
with TestRun.step("Prepare CAS device."):
cache_disk = TestRun.disks["cache"]
first_core_disk = TestRun.disks["core"]
second_core_disk = TestRun.disks["core2"]
cache_disk.create_partitions([Size(2, Unit.GibiByte)])
first_core_disk.create_partitions([Size(2, Unit.GibiByte)])
second_core_disk.create_partitions([Size(2, Unit.GibiByte)])
cache_dev = cache_disk.partitions[0]
first_core_dev = first_core_disk.partitions[0]
second_core_dev = second_core_disk.partitions[0]

with TestRun.step("Start cas and add core."):
cache = casadm.start_cache(cache_dev, cache_mode, force=True)
casadm.add_core(cache, first_core_dev)

with TestRun.step("Attempt to use core device to build SW RAID."):
config = RaidConfiguration(
level=Level.Raid1, metadata=MetadataVariant.Legacy, number_of_devices=2
)

try:
Raid.create(config, [first_core_dev, second_core_dev])
TestRun.fail(f"RAID created successfully. Expected otherwise.")
except Exception as ex:
output = ex.output.stderr

with TestRun.step("Looking for any of 2 expected messages."):

if check_string_msg_any(output, expected_msg_1 + expected_msg_2):
TestRun.LOGGER.info("RAID not created. Found expected warning in exception message.")
else:
TestRun.LOGGER.error(f"RAID not created but warning message not as expected.\n")

0 comments on commit c470d87

Please sign in to comment.