Skip to content

Commit 0260a84

Browse files
author
Katarzyna Treder
committed
Add tests for CAS device serial
Signed-off-by: Katarzyna Treder <katarzyna.treder@h-partners.com>
1 parent c63c078 commit 0260a84

File tree

6 files changed

+191
-30
lines changed

6 files changed

+191
-30
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#
2+
# Copyright(c) 2024-2025 Huawei Technologies Co., Ltd.
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
#
5+
6+
import itertools
7+
import os
8+
import random
9+
import pytest
10+
11+
from api.cas import casadm
12+
from api.cas.init_config import InitConfig
13+
from core.test_run import TestRun
14+
from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan
15+
from type_def.size import Size, Unit
16+
17+
serial_template = "opencas-"
18+
19+
20+
@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
21+
@pytest.mark.require_disk("core", DiskTypeLowerThan("cache"))
22+
def test_exported_object_serial():
23+
"""
24+
title: Cached volume serial creation.
25+
description: Validate if each exported object is created with proper serial.
26+
pass_criteria:
27+
- Each exported object has proper serial in following format:
28+
opencas-casX-Y where X is cache ID and Y is core ID
29+
- serial is not changed after system reboot
30+
"""
31+
caches_count = 4
32+
cores_count = [random.randint(1, 4) for _ in range(caches_count)]
33+
34+
with TestRun.step("Prepare devices"):
35+
cache_dev = TestRun.disks["cache"]
36+
core_dev = TestRun.disks["core"]
37+
38+
cache_dev.create_partitions([Size(1, Unit.GibiByte)] * caches_count)
39+
core_dev.create_partitions([Size(1, Unit.GibiByte)] * sum(cores_count))
40+
41+
with TestRun.step("Start caches and add cores"):
42+
caches = [
43+
casadm.start_cache(cache_dev.partitions[cache_num], force=True)
44+
for cache_num in range(caches_count)
45+
]
46+
47+
part_num = itertools.count().__next__
48+
cores_per_cache = [
49+
[
50+
caches[cache_num].add_core(core_dev.partitions[part_num()])
51+
for _ in range(cores_count[cache_num])
52+
] for cache_num in range(caches_count)
53+
]
54+
cores = list(itertools.chain(*cores_per_cache))
55+
56+
with TestRun.step("Check if each cached volume has proper serial"):
57+
check_serial(cores)
58+
59+
with TestRun.step("Create init config from running configuration"):
60+
InitConfig.create_init_config_from_running_configuration()
61+
62+
with TestRun.step("Reboot platform"):
63+
TestRun.executor.reboot()
64+
65+
with TestRun.step("Check if cached volumes have proper serial after reboot"):
66+
check_serial(cores)
67+
68+
69+
def check_serial(cores):
70+
for core in cores:
71+
serial = core.get_serial()
72+
if serial != serial_template + os.path.basename(core.path):
73+
TestRun.LOGGER.error(f"Cached volume {core.path} has wrong serial: '{serial}'")

test/functional/tests/volumes/common.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
# Copyright(c) 2022 Intel Corporation
3-
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
3+
# Copyright(c) 2024-2025 Huawei Technologies Co., Ltd.
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
66

@@ -57,14 +57,15 @@ def get_test_configuration():
5757

5858
return config_output.stdout, devices
5959

60+
6061
def validate_configuration(config_before_reboot, devices_before):
6162
config_after_reboot, devices_after = get_test_configuration()
6263

6364
if config_after_reboot == config_before_reboot:
6465
TestRun.LOGGER.info(f"Configuration is as expected")
6566
else:
66-
TestRun.LOGGER.info(f"config before reboot: {config_before_reboot}")
67-
TestRun.LOGGER.info(f"config after reboot: {config_after_reboot}")
67+
TestRun.LOGGER.info(f"Config before reboot: {config_before_reboot}")
68+
TestRun.LOGGER.info(f"Config after reboot: {config_after_reboot}")
6869
TestRun.LOGGER.error(f"Configuration changed after reboot")
6970

7071
if devices_after == devices_before:

test/functional/tests/volumes/test_many_cores_on_many_lvms.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
# Copyright(c) 2022 Intel Corporation
3-
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
3+
# Copyright(c) 2024-2025 Huawei Technologies Co., Ltd.
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
66

@@ -22,14 +22,14 @@
2222
@pytest.mark.require_disk("core", DiskTypeSet([DiskType.optane, DiskType.nand]))
2323
def test_many_cores_on_many_lvms():
2424
"""
25-
title: Test for CAS creation with lvms as cores: 1 cache, 16 lvms, 16 cores.
26-
description: |
27-
Validation of LVM support, CAS with 1 cache and 16 lvms as 16 cores.
28-
pass_criteria:
29-
- LVMs created successfully.
30-
- CAS devices created successfully.
31-
- FIO with verification ran successfully.
32-
- Configuration after reboot match configuration before.
25+
title: Test for CAS creation with lvms as cores: 1 cache, 16 lvms, 16 cores.
26+
description: |
27+
Validation of LVM support, CAS with 1 cache and 16 lvms as 16 cores.
28+
pass_criteria:
29+
- LVMs created successfully.
30+
- CAS devices created successfully.
31+
- FIO with verification ran successfully.
32+
- Configuration after reboot match configuration before.
3333
"""
3434
with TestRun.step(f"Prepare devices."):
3535
cache_device = TestRun.disks['cache']

test/functional/tests/volumes/test_many_lvms_on_many_cores.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
# Copyright(c) 2022 Intel Corporation
3-
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
3+
# Copyright(c) 2024-2025 Huawei Technologies Co., Ltd.
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
66

@@ -23,14 +23,14 @@
2323
@pytest.mark.require_disk("core2", DiskTypeLowerThan("cache"))
2424
def test_many_lvms_on_many_cores():
2525
"""
26-
title: Test for LVM creation on CAS: 1 cache, 4 cores, 4 lvms.
27-
description: |
28-
Validation of LVM support, LVMs created (4) on CAS device (1 cache, 4 cores).
29-
pass_criteria:
30-
- CAS devices created successfully.
31-
- LVMs created successfully.
32-
- FIO with verification ran successfully.
33-
- Configuration after reboot match configuration before.
26+
title: Test for LVM creation on CAS: 1 cache, 4 cores, 4 lvms.
27+
description: |
28+
Validation of LVM support, LVMs created (4) on CAS device (1 cache, 4 cores).
29+
pass_criteria:
30+
- CAS devices created successfully.
31+
- LVMs created successfully.
32+
- FIO with verification ran successfully.
33+
- Configuration after reboot match configuration before.
3434
"""
3535
with TestRun.step(f"Create CAS device."):
3636
cache_device = TestRun.disks['cache']
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#
2+
# Copyright(c) 2024-2025 Huawei Technologies Co., Ltd.
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
#
5+
6+
import datetime
7+
import pytest
8+
9+
from storage_devices.lvm import Lvm, LvmConfiguration
10+
from api.cas import casadm
11+
from core.test_run import TestRun
12+
from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan
13+
from test_tools.fio.fio import Fio
14+
from test_tools.fio.fio_param import ReadWrite, IoEngine, VerifyMethod
15+
from type_def.size import Size, Unit
16+
from tests.volumes.common import get_test_configuration, lvm_filters, validate_configuration
17+
18+
19+
@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
20+
@pytest.mark.require_disk("core", DiskTypeLowerThan("cache"))
21+
def test_many_lvms_on_many_cores_by_serial():
22+
"""
23+
title: Test for LVM creation on cached volumes using their serial - many lvms on many cores.
24+
description: |
25+
Validate if LVMs based on exported objects combined into one volume group are created
26+
successfully using cached volume's serial after system reboot.
27+
pass_criteria:
28+
- exported objects created successfully
29+
- LVMs created successfully
30+
- FIO with verification ran successfully
31+
- Configuration after reboot match configuration before
32+
"""
33+
with TestRun.step("Prepare devices."):
34+
cache_dev = TestRun.disks["cache"]
35+
core_dev = TestRun.disks["core"]
36+
cache_dev.create_partitions([Size(2, Unit.GibiByte)])
37+
core_dev.create_partitions([Size(2, Unit.GibiByte)] * 4)
38+
39+
cache = casadm.start_cache(cache_dev.partitions[0], force=True)
40+
cores = [cache.add_core(core_part) for core_part in core_dev.partitions]
41+
42+
with TestRun.step("Configure LVM to use devices file."):
43+
LvmConfiguration.set_use_devices_file(True)
44+
45+
with TestRun.step("Add CAS device type to the LVM config file."):
46+
LvmConfiguration.add_block_device_to_lvm_config("cas")
47+
48+
with TestRun.step("Create LVMs on cached volumes."):
49+
config = LvmConfiguration(lvm_filters,
50+
pv_num=4,
51+
vg_num=1,
52+
lv_num=16,)
53+
54+
lvms = Lvm.create_specific_lvm_configuration(cores, config)
55+
56+
with TestRun.step("Run FIO with verification on LVM."):
57+
fio_run = (Fio().create_command()
58+
.read_write(ReadWrite.randrw)
59+
.io_engine(IoEngine.sync)
60+
.io_depth(1)
61+
.time_based()
62+
.run_time(datetime.timedelta(seconds=30))
63+
.do_verify()
64+
.verify(VerifyMethod.md5)
65+
.block_size(Size(1, Unit.Blocks4096)))
66+
for lvm in lvms:
67+
fio_run.add_job().target(lvm).size(lvm.size)
68+
fio_run.run()
69+
70+
with TestRun.step("Flush buffers"):
71+
for lvm in lvms:
72+
TestRun.executor.run_expect_success(f"hdparm -f {lvm.path}")
73+
74+
with TestRun.step("Create init config from running configuration"):
75+
config_before_reboot, devices_before = get_test_configuration()
76+
77+
with TestRun.step("Reboot system."):
78+
TestRun.executor.reboot()
79+
80+
with TestRun.step("Validate running configuration"):
81+
validate_configuration(config_before_reboot, devices_before)
82+
83+
with TestRun.step("Run FIO with verification on LVM."):
84+
fio_run.run()
85+
86+
with TestRun.step("Remove LVMs."):
87+
Lvm.remove_all()

test/functional/tests/volumes/test_many_lvms_on_single_core.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
# Copyright(c) 2022 Intel Corporation
3-
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
3+
# Copyright(c) 2024-2025 Huawei Technologies Co., Ltd.
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
66

@@ -22,14 +22,14 @@
2222
@pytest.mark.require_disk("core", DiskTypeLowerThan("cache"))
2323
def test_many_lvms_on_single_core():
2424
"""
25-
title: Test for LVM creation on CAS device - many lvms on single core.
26-
description: |
27-
Validation of LVM support, many LVMs (16) created on CAS device (1 cache, 1 core).
28-
pass_criteria:
29-
- CAS devices created successfully.
30-
- LVMs created successfully.
31-
- FIO with verification ran successfully.
32-
- Configuration after reboot match configuration before.
25+
title: Test for LVM creation on CAS device - many lvms on single core.
26+
description: |
27+
Validation of LVM support, many LVMs (16) created on CAS device (1 cache, 1 core).
28+
pass_criteria:
29+
- CAS devices created successfully.
30+
- LVMs created successfully.
31+
- FIO with verification ran successfully.
32+
- Configuration after reboot match configuration before.
3333
"""
3434
with TestRun.step(f"Create CAS device."):
3535
cache_dev = TestRun.disks['cache']

0 commit comments

Comments
 (0)