Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of tests for exported object serial feature #1584

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}'")
18 changes: 18 additions & 0 deletions test/functional/tests/volumes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,21 @@ def get_test_configuration():
devices = get_block_device_names_list(exclude_list=[7]) # 7 stands for loop device

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.error(f"Configuration changed after reboot")

if devices_after == devices_before:
TestRun.LOGGER.info(f"Device list is as expected")
else:
TestRun.LOGGER.info(f"Devices before: {devices_before}")
TestRun.LOGGER.info(f"Devices after: {devices_after}")
TestRun.LOGGER.error(f"Device list changed after reboot")
18 changes: 2 additions & 16 deletions test/functional/tests/volumes/test_many_cores_on_many_lvms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
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
from tests.volumes.common import get_test_configuration, validate_configuration


@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
Expand Down Expand Up @@ -81,21 +81,7 @@ def test_many_cores_on_many_lvms():
TestRun.executor.reboot()

with TestRun.step("Validate running configuration"):
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.error(f"Configuration changed after reboot")

if devices_after == devices_before:
TestRun.LOGGER.info(f"Device list is as expected")
else:
TestRun.LOGGER.info(f"Devices before: {devices_before}")
TestRun.LOGGER.info(f"Devices after: {devices_after}")
TestRun.LOGGER.error(f"Device list changed after reboot")
validate_configuration(config_before_reboot, devices_before)

with TestRun.step("Run FIO with verification on LVM."):
fio_run.run()
Expand Down
18 changes: 2 additions & 16 deletions test/functional/tests/volumes/test_many_lvms_on_many_cores.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
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
from tests.volumes.common import get_test_configuration, lvm_filters, validate_configuration


@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
Expand Down Expand Up @@ -89,21 +89,7 @@ def test_many_lvms_on_many_cores():
TestRun.executor.reboot()

with TestRun.step("Validate running configuration"):
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.error(f"Configuration changed after reboot")

if devices_after == devices_before:
TestRun.LOGGER.info(f"Device list is as expected")
else:
TestRun.LOGGER.info(f"Devices before: {devices_before}")
TestRun.LOGGER.info(f"Devices after: {devices_after}")
TestRun.LOGGER.error(f"Device list changed after reboot")
validate_configuration(config_before_reboot, devices_before)

with TestRun.step("Run FIO with verification on LVM."):
fio_run.run()
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()
18 changes: 2 additions & 16 deletions test/functional/tests/volumes/test_many_lvms_on_single_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
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
from tests.volumes.common import get_test_configuration, lvm_filters, validate_configuration


@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
Expand Down Expand Up @@ -78,21 +78,7 @@ def test_many_lvms_on_single_core():
TestRun.executor.reboot()

with TestRun.step("Validate running configuration"):
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.error(f"Configuration changed after reboot")

if devices_after == devices_before:
TestRun.LOGGER.info(f"Device list is as expected")
else:
TestRun.LOGGER.info(f"Devices before: {devices_before}")
TestRun.LOGGER.info(f"Devices after: {devices_after}")
TestRun.LOGGER.error(f"Device list changed after reboot")
validate_configuration(config_before_reboot, devices_before)

with TestRun.step("Run FIO with verification on LVM."):
fio_run.run()
Expand Down
Loading