From 704da357521ebc56be4ec86f94c11980e24c8f0d Mon Sep 17 00:00:00 2001 From: Katarzyna Treder Date: Tue, 5 Nov 2024 13:58:58 +0100 Subject: [PATCH] Add tests for CAS device serial Signed-off-by: Katarzyna Treder --- test/functional/api/cas/core.py | 7 +- .../tests/cache_ops/test_cas_device_serial.py | 69 +++++++++++++++ .../test_many_lvms_on_many_cores_by_serial.py | 87 +++++++++++++++++++ 3 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 test/functional/tests/cache_ops/test_cas_device_serial.py create mode 100644 test/functional/tests/volumes/test_many_lvms_on_many_cores_by_serial.py diff --git a/test/functional/api/cas/core.py b/test/functional/api/cas/core.py index e85eef977..57c411d2f 100644 --- a/test/functional/api/cas/core.py +++ b/test/functional/api/cas/core.py @@ -3,7 +3,7 @@ # Copyright(c) 2024 Huawei Technologies Co., Ltd. # SPDX-License-Identifier: BSD-3-Clause # - +import posixpath from datetime import timedelta from typing import List from enum import Enum @@ -154,3 +154,8 @@ def wait_for_status_change(self, expected_status: CoreStatus): timeout = timedelta(minutes=1) if not wait(lambda: self.get_status() == expected_status, timeout, timedelta(seconds=1)): TestRun.fail(f"Core status did not change after {timeout.total_seconds()}s.") + + def get_serial(self): + sysfs_path = disk_utils.get_sysfs_path(self.get_device_id()) + serial_path = posixpath.join(sysfs_path, "device", "serial") + return TestRun.executor.run_expect_success(f"cat {serial_path}").stdout diff --git a/test/functional/tests/cache_ops/test_cas_device_serial.py b/test/functional/tests/cache_ops/test_cas_device_serial.py new file mode 100644 index 000000000..ff439e6c5 --- /dev/null +++ b/test/functional/tests/cache_ops/test_cas_device_serial.py @@ -0,0 +1,69 @@ +# +# Copyright(c) 2024 Huawei Technologies Co., Ltd. +# SPDX-License-Identifier: BSD-3-Clause +# + +import os +import random +import pytest + +from api.cas import casadm +from api.cas.init_config import InitConfig +from core.test_run import TestRun +from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan +from test_utils.size import Size, Unit + + +serial_template = "opencas-" + + +@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand])) +@pytest.mark.require_disk("core", DiskTypeLowerThan("cache")) +def test_cas_device_serial(): + """ + title: Open CAS device serial creation. + description: Validate if Open CAS generates proper serial for each created CAS device. + pass_criteria: + - Each CAS device has proper serial in following format: + opencas-casX-Y where X is cache ID and Y is core ID + - CAS device serial is not changed after system reboot + """ + caches_count = 4 + cores_count = [random.randint(1,4) for _ in range(caches_count)] + + with TestRun.step("Prepare devices"): + cache_dev = TestRun.disks["cache"] + core_dev = TestRun.disks["core"] + + cache_dev.create_partitions([Size(1, Unit.GibiByte)] * 4) + core_dev.create_partitions([Size(1, Unit.GibiByte)] * sum(cores_count)) + + with TestRun.step("Start caches and add cores"): + caches = [ + casadm.start_cache(cache_dev.partitions[i], force=True) for i in range(caches_count) + ] + cores = [] + core_num=0 + for cache_num in range(caches_count): + for i in range(cores_count[cache_num]): + cores.append(caches[cache_num].add_core(core_dev.partitions[core_num])) + core_num += 1 + + with TestRun.step("Check if each CAS device has proper serial"): + check_serial(cores) + + with TestRun.step("Create CAS init configuration"): + InitConfig.create_init_config_from_running_configuration() + + with TestRun.step("Reboot platform"): + TestRun.executor.reboot() + + with TestRun.step("Check if CAS devices have proper serial after reboot"): + check_serial(cores) + + +def check_serial(cores): + for core in cores: + serial = core.get_serial() + if serial != serial_template + os.path.basename(core.path): + TestRun.LOGGER.error(f"CAS device {core.path} has wrong serial: '{serial}'") \ No newline at end of file diff --git a/test/functional/tests/volumes/test_many_lvms_on_many_cores_by_serial.py b/test/functional/tests/volumes/test_many_lvms_on_many_cores_by_serial.py new file mode 100644 index 000000000..6b1502e38 --- /dev/null +++ b/test/functional/tests/volumes/test_many_lvms_on_many_cores_by_serial.py @@ -0,0 +1,87 @@ +# +# Copyright(c) 2024 Huawei Technologies Co., Ltd. +# SPDX-License-Identifier: BSD-3-Clause +# + +import datetime +import pytest + +from storage_devices.lvm import Lvm, LvmConfiguration +from api.cas import casadm +from core.test_run import TestRun +from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan +from test_tools.fio.fio import Fio +from test_tools.fio.fio_param import ReadWrite, IoEngine, VerifyMethod +from test_utils.size import Size, Unit +from tests.volumes.common import get_test_configuration, lvm_filters, validate_configuration + + +@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand])) +@pytest.mark.require_disk("core", DiskTypeLowerThan("cache")) +def test_many_lvms_on_many_cores_by_serial(): + """ + title: Test for LVM creation on CAS devices using their serial - many lvms on many cores. + description: | + Validate if LVMs based on CAS devices combined into one volume group are created + successfully using CAS devices serial after system reboot. + pass_criteria: + - CAS devices created successfully + - LVMs created successfully + - FIO with verification ran successfully + - Configuration after reboot match configuration before + """ + with TestRun.step(f"Create CAS device."): + cache_dev = TestRun.disks["cache"] + core_dev = TestRun.disks["core"] + cache_dev.create_partitions([Size(2, Unit.GibiByte)]) + core_dev.create_partitions([Size(2, Unit.GibiByte)] * 4) + + cache = casadm.start_cache(cache_dev.partitions[0], force=True) + cores = [cache.add_core(core_part) for core_part in core_dev.partitions] + + with TestRun.step("Configure LVM to use devices file."): + LvmConfiguration.set_use_devices_file(True) + + with TestRun.step("Add CAS device type to the LVM config file."): + LvmConfiguration.add_block_device_to_lvm_config("cas") + + with TestRun.step("Create LVMs on CAS device."): + config = LvmConfiguration(lvm_filters, + pv_num=4, + vg_num=1, + lv_num=16,) + + lvms = Lvm.create_specific_lvm_configuration(cores, config) + + with TestRun.step("Run FIO with verification on LVM."): + fio_run = (Fio().create_command() + .read_write(ReadWrite.randrw) + .io_engine(IoEngine.sync) + .io_depth(1) + .time_based() + .run_time(datetime.timedelta(seconds=30)) + .do_verify() + .verify(VerifyMethod.md5) + .block_size(Size(1, Unit.Blocks4096))) + for lvm in lvms: + fio_run.add_job().target(lvm).size(lvm.size) + fio_run.run() + + with TestRun.step("Flush buffers"): + for lvm in lvms: + TestRun.executor.run_expect_success(f"hdparm -f {lvm.path}") + + with TestRun.step("Create init config from running configuration"): + config_before_reboot, devices_before = get_test_configuration() + + with TestRun.step("Reboot system."): + TestRun.executor.reboot() + + with TestRun.step("Validate running configuration"): + validate_configuration(config_before_reboot, devices_before) + + with TestRun.step("Run FIO with verification on LVM."): + fio_run.run() + + with TestRun.step("Remove LVMs."): + Lvm.remove_all() \ No newline at end of file