Skip to content

Commit

Permalink
tests: refactor test_clean_reboot
Browse files Browse the repository at this point in the history
Signed-off-by: Kamil Gierszewski <kamil.gierszewski@huawei.com>
  • Loading branch information
Kamil Gierszewski committed Sep 25, 2024
1 parent 4aac33f commit 37b9ba1
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions test/functional/tests/initialize/test_clean_reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# SPDX-License-Identifier: BSD-3-Clause
#

import os
import posixpath
import pytest

from api.cas import casadm
Expand All @@ -18,61 +18,75 @@
from test_utils.size import Size, Unit


mount_point = "/mnt/test"


@pytest.mark.os_dependent
@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
@pytest.mark.require_disk("core", DiskTypeLowerThan("cache"))
@pytest.mark.parametrizex("cache_mode", CacheMode)
@pytest.mark.parametrizex("filesystem", Filesystem)
@pytest.mark.parametrizex("reboot_type", ["soft", "hard"])
@pytest.mark.parametrizex("reboot_type", ["soft"])
@pytest.mark.require_plugin("power_control")
def test_load_after_clean_shutdown(reboot_type, cache_mode, filesystem):
"""
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:
- DUT should reboot successfully.
- DUT reboot successfully.
- 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"]
core_dev = TestRun.disks["core"]

cache_disk.create_partitions([Size(1, Unit.GibiByte)])

cache_dev = cache_disk.partitions[0]
core_dev = TestRun.disks["core"]

with TestRun.step("Start cache and add core"):
cache = casadm.start_cache(cache_dev, cache_mode, force=True)
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.mount(mount_point)

with TestRun.step("Create file on cache and count its checksum."):
test_file = File(os.path.join(mount_point, "test_file"))
Dd().input("/dev/zero").output(test_file.full_path).block_size(
Size(1, Unit.KibiByte)
).count(1024).run()
with TestRun.step("Create file on exported object"):
test_file = File(posixpath.join(mount_point, "test_file"))

dd = (
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_md5 = test_file.md5sum()
sync()
drop_caches(DropCachesMode.ALL)

with TestRun.step("Reset platform."):
with TestRun.step("Reset platform"):
if reboot_type == "soft":
TestRun.executor.reboot()
else:
power_control = TestRun.plugin_manager.get_plugin("power_control")
power_control.power_cycle()

with TestRun.step("Load cache."):
with TestRun.step("Load cache and mount core"):
casadm.load_cache(cache_dev)
core.mount(mount_point)

with TestRun.step("Check file md5sum."):
with TestRun.step("Compare test file md5sums"):
test_file.refresh_item()
if test_file_md5 != test_file.md5sum():
TestRun.LOGGER.error("Checksums does not match - file is corrupted.")
else:
TestRun.LOGGER.info("File checksum is correct.")

with TestRun.step("Remove test file."):
with TestRun.step("Remove test file"):
test_file.remove()

0 comments on commit 37b9ba1

Please sign in to comment.