tests: refactor test_clean_reboot

Signed-off-by: Kamil Gierszewski <kamil.gierszewski@huawei.com>
This commit is contained in:
Kamil Gierszewski 2024-09-25 20:16:00 +02:00
parent 61ff8f60c5
commit b3cb1251cc
No known key found for this signature in database

View File

@ -4,7 +4,7 @@
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
# #
import os import posixpath
import pytest import pytest
from api.cas import casadm from api.cas import casadm
@ -18,9 +18,6 @@ from test_utils.os_utils import drop_caches, DropCachesMode, sync
from test_utils.size import Size, Unit from test_utils.size import Size, Unit
mount_point = "/mnt/test"
@pytest.mark.os_dependent @pytest.mark.os_dependent
@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand])) @pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
@pytest.mark.require_disk("core", DiskTypeLowerThan("cache")) @pytest.mark.require_disk("core", DiskTypeLowerThan("cache"))
@ -31,48 +28,65 @@ mount_point = "/mnt/test"
def test_load_after_clean_shutdown(reboot_type, cache_mode, filesystem): def test_load_after_clean_shutdown(reboot_type, cache_mode, filesystem):
""" """
title: Planned system shutdown test. title: Planned system shutdown test.
description: Test for data consistency after clean system shutdown. description: |
Test for data consistency after clean system shutdown.
pass_criteria: pass_criteria:
- DUT should reboot successfully. - DUT reboot successful.
- Checksum of file on core device should be the same before and after reboot. - Checksum of file on core device should be the same before and after reboot.
""" """
with TestRun.step("Prepare CAS device."): mount_point = "/mnt/test"
with TestRun.step("Prepare cache and core devices"):
cache_disk = TestRun.disks["cache"] cache_disk = TestRun.disks["cache"]
cache_disk.create_partitions([Size(1, Unit.GibiByte)])
cache_dev = cache_disk.partitions[0]
core_dev = TestRun.disks["core"] core_dev = TestRun.disks["core"]
cache_disk.create_partitions([Size(1, Unit.GibiByte)])
cache_dev = cache_disk.partitions[0]
with TestRun.step("Start cache and add core"):
cache = casadm.start_cache(cache_dev, cache_mode, force=True) cache = casadm.start_cache(cache_dev, cache_mode, force=True)
core = cache.add_core(core_dev) core = cache.add_core(core_dev)
with TestRun.step("Create filesystem on the core device and mount it"):
core.create_filesystem(filesystem, blocksize=int(Size(1, Unit.Blocks4096))) core.create_filesystem(filesystem, blocksize=int(Size(1, Unit.Blocks4096)))
core.mount(mount_point) core.mount(mount_point)
with TestRun.step("Create file on cache and count its checksum."): with TestRun.step("Create file on exported object"):
test_file = File(os.path.join(mount_point, "test_file")) test_file = File(posixpath.join(mount_point, "test_file"))
Dd().input("/dev/zero").output(test_file.full_path).block_size(
Size(1, Unit.KibiByte) dd = (
).count(1024).run() Dd()
.input("/dev/zero")
.output(test_file.full_path)
.block_size(Size(1, Unit.KibiByte))
.count(1024)
)
dd.run()
with TestRun.step("Calculate test file md5sums before reboot"):
test_file.refresh_item() test_file.refresh_item()
test_file_md5 = test_file.md5sum() test_file_md5 = test_file.md5sum()
sync() sync()
drop_caches(DropCachesMode.ALL) drop_caches(DropCachesMode.ALL)
with TestRun.step("Reset platform."): with TestRun.step("Reset platform"):
if reboot_type == "soft": if reboot_type == "soft":
TestRun.executor.reboot() TestRun.executor.reboot()
else: else:
power_control = TestRun.plugin_manager.get_plugin("power_control") power_control = TestRun.plugin_manager.get_plugin("power_control")
power_control.power_cycle() power_control.power_cycle()
with TestRun.step("Load cache."): with TestRun.step("Load cache and mount core"):
casadm.load_cache(cache_dev) casadm.load_cache(cache_dev)
core.mount(mount_point) core.mount(mount_point)
with TestRun.step("Check file md5sum."): with TestRun.step("Compare test file md5sums"):
test_file.refresh_item() test_file.refresh_item()
if test_file_md5 != test_file.md5sum(): if test_file_md5 != test_file.md5sum():
TestRun.LOGGER.error("Checksums does not match - file is corrupted.") TestRun.LOGGER.error("Checksums does not match - file is corrupted.")
else: else:
TestRun.LOGGER.info("File checksum is correct.") TestRun.LOGGER.info("File checksum is correct.")
with TestRun.step("Remove test file."): with TestRun.step("Remove test file"):
test_file.remove() test_file.remove()