diff --git a/test/functional/api/cas/cli_messages.py b/test/functional/api/cas/cli_messages.py index b275737ac..fc3104bcb 100644 --- a/test/functional/api/cas/cli_messages.py +++ b/test/functional/api/cas/cli_messages.py @@ -84,7 +84,7 @@ ] remove_mounted_core = [ - r"Can\'t remove core \d+ from cache \d+\. Device /dev/cas\d+-\d+(p\d+|) is mounted\!" + r"Can\'t remove core \d+ from cache \d+ due to mounted devices:" ] remove_mounted_core_kernel = [ @@ -93,7 +93,7 @@ ] stop_cache_mounted_core = [ - r"Can\'t stop cache instance \d+\. Device /dev/cas\d+-\d+(p\d+|) is mounted\!" + r"Can\'t stop cache instance \d+ due to mounted devices:" ] stop_cache_mounted_core_kernel = [ diff --git a/test/functional/tests/fault_injection/test_fault_injection_with_mounted_core.py b/test/functional/tests/fault_injection/test_fault_injection_with_mounted_core.py index e13ed7167..de78cac40 100644 --- a/test/functional/tests/fault_injection/test_fault_injection_with_mounted_core.py +++ b/test/functional/tests/fault_injection/test_fault_injection_with_mounted_core.py @@ -9,12 +9,12 @@ from api.cas import casadm, casadm_parser, cli, cli_messages from core.test_run import TestRun from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan -from test_tools import fs_utils +from test_tools import fs_utils, disk_utils from test_tools.disk_utils import Filesystem from test_utils.filesystem.symlink import Symlink from test_utils.size import Size, Unit -mount_point = "/mnt/cas" +mount_point, mount_point2 = "/mnt/cas", "/mnt/cas2" test_file_path = f"{mount_point}/test_file" @@ -80,6 +80,7 @@ def test_load_cache_with_mounted_core(): @pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand])) @pytest.mark.require_disk("core", DiskTypeLowerThan("cache")) +@pytest.mark.require_disk("core2", DiskTypeLowerThan("cache")) def test_stop_cache_with_mounted_partition(): """ title: Fault injection test for removing core and stopping cache with mounted core. @@ -92,35 +93,63 @@ def test_stop_cache_with_mounted_partition(): - Unable to remove core when partition is mounted. - casadm displays proper message. """ - with TestRun.step("Prepare cache and core devices. Start CAS."): + with TestRun.step("Prepare cache device."): cache_dev = TestRun.disks['cache'] cache_dev.create_partitions([Size(1, Unit.GibiByte)]) cache_part = cache_dev.partitions[0] - core_dev = TestRun.disks['core'] - core_dev.create_partitions([Size(4, Unit.GibiByte)]) - core_part = core_dev.partitions[0] + + with TestRun.step("Prepare 2 core devices."): + core_dev, core_dev2 = TestRun.disks['core'], TestRun.disks['core2'] + + with TestRun.step("Start cache."): cache = casadm.start_cache(cache_part, force=True) - with TestRun.step("Add core device with xfs filesystem and mount it."): - core_part.create_filesystem(Filesystem.xfs) - core = cache.add_core(core_part) - core.mount(mount_point) + with TestRun.step("Add core devices to cache."): + core = cache.add_core(core_dev) + core2 = cache.add_core(core_dev2) + + with TestRun.step("Create partitions on one exported object."): + core.block_size = Size(disk_utils.get_block_size(core.get_device_id())) + disk_utils.create_partitions(core, 2 * [Size(4, Unit.GibiByte)]) + fs_part = core.partitions[0] + + with TestRun.step("Create xfs filesystems on one exported object partition " + "and on the non-partitioned exported object."): + fs_part.create_filesystem(Filesystem.xfs) + core2.create_filesystem(Filesystem.xfs) + + with TestRun.step("Mount created filesystems."): + fs_part.mount(mount_point) + core2.mount(mount_point2) with TestRun.step("Ensure /etc/mtab exists."): if not fs_utils.check_if_symlink_exists("/etc/mtab"): Symlink.create_symlink("/proc/self/mounts", "/etc/mtab") - with TestRun.step("Try to remove core from cache."): + with (TestRun.step("Try to remove the core with partitions from cache.")): output = TestRun.executor.run_expect_fail(cli.remove_core_cmd(cache_id=str(cache.cache_id), core_id=str(core.core_id))) - cli_messages.check_stderr_msg(output, cli_messages.remove_mounted_core) + messages = cli_messages.remove_mounted_core.copy() + messages.append(fs_part.path) + cli_messages.check_stderr_msg(output, messages) - with TestRun.step("Try to stop CAS."): + with TestRun.step("Try to remove the core without partitions from cache."): + output = TestRun.executor.run_expect_fail(cli.remove_core_cmd(cache_id=str(cache.cache_id), + core_id=str(core2.core_id))) + messages = cli_messages.remove_mounted_core.copy() + messages.append(core2.path) + cli_messages.check_stderr_msg(output, messages) + + with ((TestRun.step("Try to stop CAS."))): output = TestRun.executor.run_expect_fail(cli.stop_cmd(cache_id=str(cache.cache_id))) - cli_messages.check_stderr_msg(output, cli_messages.stop_cache_mounted_core) + messages = cli_messages.stop_cache_mounted_core.copy() + messages.append(fs_part.path) + messages.append(core2.path) + cli_messages.check_stderr_msg(output, messages) - with TestRun.step("Unmount core device."): - core.unmount() + with TestRun.step("Unmount core devices."): + fs_part.unmount() + core2.unmount() with TestRun.step("Stop cache."): casadm.stop_all_caches() @@ -147,7 +176,7 @@ def test_stop_cache_with_mounted_partition_no_mtab(): core_dev = TestRun.disks['core'] core_dev.create_partitions([Size(4, Unit.GibiByte)]) core_part = core_dev.partitions[0] - cache = casadm.start_cache([cache_part], force=True) + cache = casadm.start_cache(cache_part, force=True) with TestRun.step("Add core device with xfs filesystem and mount it."): core_part.create_filesystem(Filesystem.xfs)