Skip to content

Commit

Permalink
tests: update tests
Browse files Browse the repository at this point in the history
Signed-off-by: Kamil Gierszewski <kamil.gierszewski@huawei.com>
  • Loading branch information
Kamil Gierszewski committed Sep 9, 2024
1 parent ec0e03f commit e8bdcda
Show file tree
Hide file tree
Showing 23 changed files with 2,153 additions and 1,689 deletions.
4 changes: 4 additions & 0 deletions test/functional/tests/512b/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#
65 changes: 29 additions & 36 deletions test/functional/tests/512b/test_different_io_sizes_support.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright(c) 2022 Intel Corporation
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#

Expand All @@ -13,14 +14,14 @@
from api.cas.cache_config import CacheMode
from test_tools import fs_utils
from test_tools.disk_utils import Filesystem
from test_utils.filesystem.directory import Directory
from test_utils.filesystem.file import File
from test_utils.size import Size, Unit
from test_tools.fio.fio import Fio
from test_tools.fio.fio_param import ReadWrite, IoEngine


mountpoint = "/tmp/diff_io_size_support_test"
opencas_ioclass_conf_path = "/etc/opencas/ioclass-config.csv"
block_sizes = [1, 2, 4, 5, 8, 16, 32, 64, 128]


@pytest.mark.parametrizex("cache_mode", [CacheMode.WB, CacheMode.WT])
Expand All @@ -29,65 +30,57 @@
def test_support_different_io_size(cache_mode):
"""
title: OpenCAS supports different IO sizes
description: OpenCAS supports IO of size in rage from 512b to 128K
description: |
OpenCAS supports IO of size in rage from 512b to 128K
pass_criteria:
- No IO errors
"""
with TestRun.step("Prepare devices"):

with TestRun.step("Prepare cache and core devices"):
cache_disk = TestRun.disks["cache"]
core_disk = TestRun.disks["core"]
cache_disk.create_partitions([Size(1, Unit.GibiByte)])
cache_disk = cache_disk.partitions[0]
core_disk.create_partitions([Size(50, Unit.GibiByte)])
core_disk = core_disk.partitions[0]
core_disk.create_partitions([Size(45, Unit.GibiByte)])

with TestRun.step("Start cache"):
cache = casadm.start_cache(cache_dev=cache_disk, cache_mode=cache_mode, force=True)
core = cache.add_core(core_disk)
cache = casadm.start_cache(
cache_dev=cache_disk.partitions[0], cache_mode=cache_mode, force=True
)
core = cache.add_core(core_disk.partitions[0])

with TestRun.step("Load the default ioclass config file"):
cache.load_io_class("/etc/opencas/ioclass-config.csv")
cache.load_io_class(opencas_ioclass_conf_path)

with TestRun.step("Create a filesystem on the core device and mount it"):
TestRun.executor.run(f"rm -rf {mountpoint}")
fs_utils.remove(path=mountpoint, force=True, recursive=True, ignore_errors=True)
fs_utils.create_directory(path=mountpoint)
core.create_filesystem(Filesystem.xfs)
core.mount(mountpoint)

with TestRun.step("Run fio with block sizes: 512, 1k, 4k, 5k, 8k, 16k, 32k, 64 and 128k"):
bs_list = [
Size(512, Unit.Byte),
Size(1, Unit.KibiByte),
Size(4, Unit.KibiByte),
Size(5, Unit.KibiByte),
Size(8, Unit.KibiByte),
Size(16, Unit.KibiByte),
Size(32, Unit.KibiByte),
Size(64, Unit.KibiByte),
Size(128, Unit.KibiByte),
]
with TestRun.step(f"Run fio"):
bs_list = [Size(x, Unit.KibiByte) for x in block_sizes]

fio = Fio().create_command()
fio.io_engine(IoEngine.libaio)
fio.time_based()
fio.do_verify()
fio.direct()
fio.read_write(ReadWrite.randwrite)
fio.run_time(datetime.timedelta(seconds=1200))
fio.io_depth(16)
fio.verify_pattern(0xABCD)
fio = (
Fio()
.create_command()
.io_engine(IoEngine.libaio)
.time_based()
.do_verify()
.direct()
.read_write(ReadWrite.randwrite)
.run_time(datetime.timedelta(seconds=1200))
.io_depth(16)
.verify_pattern(0xABCD)
)

for i, bs in enumerate(bs_list):
fio_job = fio.add_job()
fio_job.target(os.path.join(mountpoint, str(bs.value)))
fio_job.block_size(bs)
fio_job.file_size(Size((i + 1) * 200, Unit.MebiByte))

fio_output = fio.run()

fio_errors = fio_output[0].total_errors()
if fio_errors != 0:
TestRun.fail(f"fio errors: {fio_errors}, should equal 0")

with TestRun.step("Cleanup"):
core.unmount()
TestRun.executor.run(f"rm -rf {mountpoint}")
170 changes: 170 additions & 0 deletions test/functional/tests/basic/test_basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#
# Copyright(c) 2022 Intel Corporation
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#

import pytest

from api.cas.cache_config import CacheMode, CacheLineSize
from api.cas.casadm_params import OutputFormat
from api.cas.cli import start_cmd
from core.test_run import TestRun
from api.cas import casadm
from api.cas.cli_messages import (
check_stderr_msg,
start_cache_on_already_used_dev,
start_cache_with_existing_id,
)
from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan
from test_tools import fs_utils
from test_tools.dd import Dd
from test_tools.disk_utils import Filesystem
from test_utils.filesystem.file import File
from test_utils.output import CmdException
from test_utils.size import Size, Unit

version_file_path = r"/var/lib/opencas/cas_version"
mountpoint = "/mnt"


@pytest.mark.CI
def test_cas_version():
"""
title: Test for CAS version
description:
Check if CAS print version cmd returns consistent version with version file
pass criteria:
- casadm version command succeeds
- versions from cmd and file in /var/lib/opencas/cas_version are consistent
"""

with TestRun.step("Read cas version using casadm cmd"):
output = casadm.print_version(output_format=OutputFormat.csv)
cmd_version = output.stdout
cmd_cas_versions = [version.split(",")[1] for version in cmd_version.split("\n")[1:]]

with TestRun.step(f"Read cas version from {version_file_path} location"):
file_read = fs_utils.read_file(version_file_path).split("\n")
file_cas_version = next(
(line.split("=")[1] for line in file_read if "CAS_VERSION=" in line)
)

with TestRun.step("Compare cmd and file versions"):
if not all(file_cas_version == cmd_cas_version for cmd_cas_version in cmd_cas_versions):
TestRun.LOGGER.error(f"Cmd and file versions doesn`t match")


@pytest.mark.CI
@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.nand, DiskType.optane]))
def test_negative_start_cache():
"""
title: Test start cache negative on cache device
description:
Check for negative cache start scenarios
pass criteria:
- Cache start succeeds
- Fails to start cache on the same device with another id
- Fails to start cache on another partition with the same id
"""

with TestRun.step("Prepare cache device"):
cache_dev = TestRun.disks["cache"]

cache_dev.create_partitions([Size(2, Unit.GibiByte)] * 2)

cache_dev_1 = cache_dev.partitions[0]
cache_dev_2 = cache_dev.partitions[1]

with TestRun.step("Start cache on cache device"):
casadm.start_cache(cache_dev=cache_dev_1, force=True)

with TestRun.step("Start cache on the same device but with another ID"):
try:
output = TestRun.executor.run(
start_cmd(
cache_dev=cache_dev_1.path,
cache_id="2",
force=True,
)
)
TestRun.fail("Two caches started on same device")
except CmdException:
if not check_stderr_msg(output, start_cache_on_already_used_dev):
TestRun.fail(f"Received unexpected error message: {output.stderr}")

with TestRun.step("Start cache with the same ID on another cache device"):
try:
output = TestRun.executor.run(
start_cmd(
cache_dev=cache_dev_2.path,
cache_id="1",
force=True,
)
)
TestRun.fail("Two caches started with same ID")
except CmdException:
if not check_stderr_msg(output, start_cache_with_existing_id):
TestRun.fail(f"Received unexpected error message: {output.stderr}")


@pytest.mark.CI
@pytest.mark.parametrizex("filesystem", Filesystem)
@pytest.mark.parametrizex("cache_mode", CacheMode)
@pytest.mark.parametrizex("cache_line_size", CacheLineSize)
@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
@pytest.mark.require_disk("core", DiskTypeLowerThan("cache"))
def test_data_integrity(filesystem, cache_mode, cache_line_size):
"""
title: Basic data integrity test
description:
Check basic data integrity after stopping the cache
pass criteria:
- System does not crash.
- All operations complete successfully.
- Data consistency is preserved.
"""

with TestRun.step("Prepare cache and core devices"):
cache_device = TestRun.disks["cache"]
core_device = TestRun.disks["core"]

cache_device.create_partitions([Size(200, Unit.MebiByte)])
core_device.create_partitions([Size(100, Unit.MebiByte)])

cache_part = cache_device.partitions[0]
core_part = core_device.partitions[0]

with TestRun.step("Start cache and add core device"):
cache = casadm.start_cache(
cache_dev=cache_part, cache_mode=cache_mode, cache_line_size=cache_line_size, force=True
)
core = cache.add_core(core_dev=core_part)

with TestRun.step("Create filesystem on CAS device and mount it"):
core.create_filesystem(filesystem)
core.mount(mountpoint)

with TestRun.step("Create test file and calculate md5 checksum"):
(
Dd()
.input("/dev/urandom")
.output(f"{mountpoint}/test_file")
.count(1)
.block_size(Size(50, Unit.MebiByte))
.run()
)
test_file = File(f"{mountpoint}/test_file")
md5_before = test_file.md5sum()

with TestRun.step("Unmount core"):
core.unmount()

with TestRun.step("Stop cache"):
cache.stop()

with TestRun.step("Mount the core device and check for file"):
core_part.mount(mountpoint)
md5_after = test_file.md5sum()
if md5_before != md5_after:
TestRun.fail("md5 checksum mismatch!")
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright(c) 2022 Intel Corporation
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#

Expand All @@ -16,21 +17,22 @@
@pytest.mark.require_disk("core", DiskTypeLowerThan("cache"))
def test_start_cache_add_core():
"""
title: Basic test for starting cache and adding core.
description: |
Test for start cache and add core.
pass_criteria:
- Cache started successfully.
- Core added successfully.
title: Basic test for starting cache and adding core.
description: |
Test for start cache and add core.
pass_criteria:
- Cache started successfully.
- Core added successfully.
"""
with TestRun.step("Prepare cache and core devices."):
with TestRun.step("Prepare cache and core devices"):
cache_dev = TestRun.disks["cache"]
cache_dev.create_partitions([Size(500, Unit.MebiByte)])
core_dev = TestRun.disks["core"]

cache_dev.create_partitions([Size(500, Unit.MebiByte)])
core_dev.create_partitions([Size(2, Unit.GibiByte)])

with TestRun.step("Start cache."):
with TestRun.step("Start cache"):
cache = casadm.start_cache(cache_dev.partitions[0], force=True)

with TestRun.step("Add core."):
core = cache.add_core(core_dev.partitions[0])
with TestRun.step("Add core"):
cache.add_core(core_dev.partitions[0])
4 changes: 4 additions & 0 deletions test/functional/tests/cache_ops/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#
Loading

0 comments on commit e8bdcda

Please sign in to comment.