[tests] Update CLI messages and test

Signed-off-by: Daniel Madej <daniel.madej@huawei.com>
This commit is contained in:
Daniel Madej 2024-09-12 12:47:46 +02:00
parent f11f14d31a
commit 0c0b10535e
2 changed files with 47 additions and 18 deletions

View File

@ -84,7 +84,7 @@ already_cached_core = [
] ]
remove_mounted_core = [ 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 = [ remove_mounted_core_kernel = [
@ -93,7 +93,7 @@ remove_mounted_core_kernel = [
] ]
stop_cache_mounted_core = [ 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 = [ stop_cache_mounted_core_kernel = [

View File

@ -9,13 +9,13 @@ import pytest
from api.cas import casadm, casadm_parser, cli, cli_messages from api.cas import casadm, casadm_parser, cli, cli_messages
from core.test_run import TestRun from core.test_run import TestRun
from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan 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_tools.disk_utils import Filesystem
from test_utils.filesystem.file import File from test_utils.filesystem.file import File
from test_utils.filesystem.symlink import Symlink from test_utils.filesystem.symlink import Symlink
from test_utils.size import Size, Unit 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" test_file_path = f"{mount_point}/test_file"
@ -81,6 +81,7 @@ def test_load_cache_with_mounted_core():
@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand])) @pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
@pytest.mark.require_disk("core", DiskTypeLowerThan("cache")) @pytest.mark.require_disk("core", DiskTypeLowerThan("cache"))
@pytest.mark.require_disk("core2", DiskTypeLowerThan("cache"))
def test_stop_cache_with_mounted_partition(): def test_stop_cache_with_mounted_partition():
""" """
title: Fault injection test for removing core and stopping cache with mounted core. title: Fault injection test for removing core and stopping cache with mounted core.
@ -93,35 +94,63 @@ def test_stop_cache_with_mounted_partition():
- Unable to remove core when partition is mounted. - Unable to remove core when partition is mounted.
- casadm displays proper message. - 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 = TestRun.disks['cache']
cache_dev.create_partitions([Size(1, Unit.GibiByte)]) cache_dev.create_partitions([Size(1, Unit.GibiByte)])
cache_part = cache_dev.partitions[0] cache_part = cache_dev.partitions[0]
core_dev = TestRun.disks['core']
core_dev.create_partitions([Size(4, Unit.GibiByte)]) with TestRun.step("Prepare 2 core devices."):
core_part = core_dev.partitions[0] core_dev, core_dev2 = TestRun.disks['core'], TestRun.disks['core2']
with TestRun.step("Start cache."):
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."): with TestRun.step("Add core devices to cache."):
core_part.create_filesystem(Filesystem.xfs) core = cache.add_core(core_dev)
core = cache.add_core(core_part) core2 = cache.add_core(core_dev2)
core.mount(mount_point)
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."): with TestRun.step("Ensure /etc/mtab exists."):
if not fs_utils.check_if_file_exists("/etc/mtab"): if not fs_utils.check_if_file_exists("/etc/mtab"):
Symlink.create_symlink("/proc/self/mounts", "/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), output = TestRun.executor.run_expect_fail(cli.remove_core_cmd(cache_id=str(cache.cache_id),
core_id=str(core.core_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 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."): with TestRun.step("Try to stop CAS."):
output = TestRun.executor.run_expect_fail(cli.stop_cmd(cache_id=str(cache.cache_id))) 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."): with TestRun.step("Unmount core devices."):
core.unmount() fs_part.unmount()
core2.unmount()
with TestRun.step("Stop cache."): with TestRun.step("Stop cache."):
casadm.stop_all_caches() casadm.stop_all_caches()
@ -148,7 +177,7 @@ def test_stop_cache_with_mounted_partition_no_mtab():
core_dev = TestRun.disks['core'] core_dev = TestRun.disks['core']
core_dev.create_partitions([Size(4, Unit.GibiByte)]) core_dev.create_partitions([Size(4, Unit.GibiByte)])
core_part = core_dev.partitions[0] 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."): with TestRun.step("Add core device with xfs filesystem and mount it."):
core_part.create_filesystem(Filesystem.xfs) core_part.create_filesystem(Filesystem.xfs)