Skip to content

Commit

Permalink
Add tests for CAS device serial
Browse files Browse the repository at this point in the history
Signed-off-by: Katarzyna Treder <[email protected]>
  • Loading branch information
Katarzyna Treder committed Nov 13, 2024
1 parent ef8843b commit 1a7c13d
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 1 deletion.
7 changes: 6 additions & 1 deletion test/functional/api/cas/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
69 changes: 69 additions & 0 deletions test/functional/tests/cache_ops/test_cas_device_serial.py
Original file line number Diff line number Diff line change
@@ -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}'")
1 change: 1 addition & 0 deletions test/functional/tests/volumes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def get_test_configuration():

return config_output.stdout, devices


def validate_configuration(config_before_reboot, devices_before):
config_after_reboot, devices_after = get_test_configuration()

Expand Down
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 1a7c13d

Please sign in to comment.