Skip to content

Commit

Permalink
[tests] Update CLI messages and test
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Madej <daniel.madej@huawei.com>
  • Loading branch information
Deixx committed Sep 30, 2024
1 parent abfc3d1 commit 626d549
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
4 changes: 2 additions & 2 deletions test/functional/api/cas/cli_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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 = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down Expand Up @@ -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.
Expand All @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit 626d549

Please sign in to comment.