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