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 <katarzyna.treder@h-partners.com>
  • Loading branch information
Katarzyna Treder committed Nov 25, 2024
1 parent ef8843b commit dbf8e08
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 2 deletions.
69 changes: 69 additions & 0 deletions test/functional/tests/misc/test_exported_object_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_exported_object_serial():
"""
title: Cached volume serial creation.
description: Validate if each exported object is created with proper serial.
pass_criteria:
- Each exported object has proper serial in following format:
opencas-casX-Y where X is cache ID and Y is core ID
- 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 cached volume has proper serial"):
check_serial(cores)

with TestRun.step("Create init config from running configuration"):
InitConfig.create_init_config_from_running_configuration()

with TestRun.step("Reboot platform"):
TestRun.executor.reboot()

with TestRun.step("Check if cached volumes 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"Cached volume {core.path} has wrong serial: '{serial}'")
5 changes: 3 additions & 2 deletions test/functional/tests/volumes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ 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()

if config_after_reboot == config_before_reboot:
TestRun.LOGGER.info(f"Configuration is as expected")
else:
TestRun.LOGGER.info(f"config before reboot: {config_before_reboot}")
TestRun.LOGGER.info(f"config after reboot: {config_after_reboot}")
TestRun.LOGGER.info(f"Config before reboot: {config_before_reboot}")
TestRun.LOGGER.info(f"Config after reboot: {config_after_reboot}")
TestRun.LOGGER.error(f"Configuration changed after reboot")

if devices_after == devices_before:
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 cached volumes using their serial - many lvms on many cores.
description: |
Validate if LVMs based on exported objects combined into one volume group are created
successfully using cached volume's serial after system reboot.
pass_criteria:
- exported objects created successfully
- LVMs created successfully
- FIO with verification ran successfully
- Configuration after reboot match configuration before
"""
with TestRun.step("Prepare devices."):
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 cached volumes."):
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 dbf8e08

Please sign in to comment.