Refactor IO class tests

Signed-off-by: Klaudia Jablonska <klaudia.jablonska@intel.com>
This commit is contained in:
Klaudia Jablonska
2022-08-29 16:04:22 +02:00
parent 2da9753a10
commit 1cf2af7ed4
17 changed files with 1100 additions and 883 deletions

View File

@@ -1,5 +1,5 @@
#
# Copyright(c) 2019-2021 Intel Corporation
# Copyright(c) 2019-2022 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -22,11 +22,11 @@ from tests.io_class.io_class_common import mountpoint, prepare, ioclass_config_p
@pytest.mark.require_disk("core", DiskTypeLowerThan("cache"))
def test_ioclass_file_extension():
"""
title: Test IO classification by file extension.
description: Test if file extension classification works properly.
pass_criteria:
- No kernel bug.
- IO is classified properly based on IO class rule with file extension.
title: Test IO classification by file extension.
description: Test if file extension classification works properly.
pass_criteria:
- No kernel bug.
- IO is classified properly based on IO class rule with file extension.
"""
iterations = 50
ioclass_id = 1
@@ -35,10 +35,11 @@ def test_ioclass_file_extension():
dd_size = Size(4, Unit.KibiByte)
dd_count = 10
dd = (
Dd().input("/dev/zero")
.output(f"{mountpoint}/test_file.{tested_extension}")
.count(dd_count)
.block_size(dd_size)
Dd()
.input("/dev/zero")
.output(f"{mountpoint}/test_file.{tested_extension}")
.count(dd_count)
.block_size(dd_size)
)
with TestRun.step("Prepare cache and core."):
@@ -74,13 +75,14 @@ def test_ioclass_file_extension():
with TestRun.step(f"Write to file with not cached extension and check if it is not cached."):
for ext in wrong_extensions:
dd = (
Dd().input("/dev/zero")
.output(f"{mountpoint}/test_file.{ext}")
.count(dd_count)
.block_size(dd_size)
(
Dd()
.input("/dev/zero")
.output(f"{mountpoint}/test_file.{ext}")
.count(dd_count)
.block_size(dd_size)
.run()
)
dd.run()
sync()
dirty = cache.get_io_class_statistics(io_class_id=ioclass_id).usage_stats.dirty
if dirty.get_value(Unit.Blocks4096) != 0:
@@ -91,11 +93,11 @@ def test_ioclass_file_extension():
@pytest.mark.require_disk("core", DiskTypeLowerThan("cache"))
def test_ioclass_file_name_prefix():
"""
title: Test IO classification by file name prefix.
description: Test if file name prefix classification works properly.
pass_criteria:
- No kernel bug.
- IO is classified properly based on IO class rule with file name prefix.
title: Test IO classification by file name prefix.
description: Test if file name prefix classification works properly.
pass_criteria:
- No kernel bug.
- IO is classified properly based on IO class rule with file name prefix.
"""
ioclass_id = 1
@@ -107,25 +109,14 @@ def test_ioclass_file_name_prefix():
with TestRun.step("Prepare cache and core."):
cache, core = prepare()
with TestRun.step("Create and load IO class config."):
ioclass_config.remove_ioclass_config()
ioclass_config.create_ioclass_config(False)
# Avoid caching anything else than files with specified prefix
ioclass_config.add_ioclass(
ioclass_id=0,
eviction_priority=255,
allocation="0.00",
rule=f"unclassified",
ioclass_config_path=ioclass_config_path,
)
with TestRun.step("Add io class for specific file name prefix."):
# Enables file with specified prefix to be cached
ioclass_config.add_ioclass(
ioclass_id=ioclass_id,
eviction_priority=1,
allocation="1.00",
rule=f"file_name_prefix:test&done",
ioclass_config_path=ioclass_config_path,
ioclass_config_path=ioclass_config_path
)
casadm.load_io_classes(cache_id=cache.cache_id, file=ioclass_config_path)
@@ -137,66 +128,76 @@ def test_ioclass_file_name_prefix():
current_occupancy = cache.get_occupancy()
if previous_occupancy.get_value() > current_occupancy.get_value():
TestRun.fail(f"Current occupancy ({str(current_occupancy)}) is lower "
f"than before ({str(previous_occupancy)}).")
TestRun.fail(
f"Current occupancy ({str(current_occupancy)}) is lower "
f"than before ({str(previous_occupancy)})."
)
# Filesystem creation caused metadata IO which is not supposed
# to be cached
# Check if files with proper prefix are cached
with TestRun.step(f"Write files which are supposed to be cached and check "
f"if they are cached."):
with TestRun.step(
f"Write files which are supposed to be cached and check " f"if they are cached."
):
for f in cached_files:
dd = (
Dd().input("/dev/zero")
.output(f"{mountpoint}/{f}")
.count(dd_count)
.block_size(dd_size)
(
Dd()
.input("/dev/zero")
.output(f"{mountpoint}/{f}")
.count(dd_count)
.block_size(dd_size)
.run()
)
dd.run()
sync()
current_occupancy = cache.get_occupancy()
expected_occupancy = previous_occupancy + (dd_size * dd_count)
if current_occupancy != expected_occupancy:
TestRun.fail(f"Current occupancy value is not valid. "
f"(Expected: {str(expected_occupancy)}, "
f"actual: {str(current_occupancy)})")
TestRun.fail(
f"Current occupancy value is not valid. "
f"(Expected: {str(expected_occupancy)}, "
f"actual: {str(current_occupancy)})"
)
previous_occupancy = current_occupancy
with TestRun.step("Flush cache."):
cache.flush_cache()
# Check if file with improper extension is not cached
with TestRun.step(f"Write files which are not supposed to be cached and check if "
f"they are not cached."):
with TestRun.step(
f"Write files which are not supposed to be cached and check if " f"they are not cached."
):
for f in not_cached_files:
dd = (
Dd().input("/dev/zero")
.output(f"{mountpoint}/{f}")
.count(dd_count)
.block_size(dd_size)
(
Dd()
.input("/dev/zero")
.output(f"{mountpoint}/{f}")
.count(dd_count)
.block_size(dd_size)
.run()
)
dd.run()
sync()
current_occupancy = cache.get_occupancy()
if current_occupancy != previous_occupancy:
TestRun.fail(f"Current occupancy value is not valid. "
f"(Expected: {str(previous_occupancy)}, "
f"actual: {str(current_occupancy)})")
TestRun.fail(
f"Current occupancy value is not valid. "
f"(Expected: {str(previous_occupancy)}, "
f"actual: {str(current_occupancy)})"
)
@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
@pytest.mark.require_disk("core", DiskTypeLowerThan("cache"))
def test_ioclass_file_extension_preexisting_filesystem():
"""
title: Test IO classification by file extension with preexisting filesystem on core device.
description: |
Test if file extension classification works properly when there is an existing
filesystem on core device.
pass_criteria:
- No kernel bug.
- IO is classified properly based on IO class rule with file extension
after mounting core device.
title: Test IO classification by file extension with preexisting filesystem on core device.
description: |
Test if file extension classification works properly when there is an existing
filesystem on core device.
pass_criteria:
- No kernel bug.
- IO is classified properly based on IO class rule with file extension
after mounting core device.
"""
ioclass_id = 1
extensions = ["tmp", "tm", "out", "txt", "log", "123"]
@@ -212,13 +213,14 @@ def test_ioclass_file_extension_preexisting_filesystem():
core.core_device.mount(mountpoint)
for ext in extensions:
dd = (
Dd().input("/dev/zero")
.output(f"{mountpoint}/test_file.{ext}")
.count(dd_count)
.block_size(dd_size)
(
Dd()
.input("/dev/zero")
.output(f"{mountpoint}/test_file.{ext}")
.count(dd_count)
.block_size(dd_size)
.run()
)
dd.run()
core.core_device.unmount()
with TestRun.step("Create IO class config."):
@@ -243,13 +245,14 @@ def test_ioclass_file_extension_preexisting_filesystem():
with TestRun.step(f"Write to file with cached extension and check if they are cached."):
for ext in extensions:
dd = (
Dd().input("/dev/zero")
.output(f"{mountpoint}/test_file.{ext}")
.count(dd_count)
.block_size(dd_size)
(
Dd()
.input("/dev/zero")
.output(f"{mountpoint}/test_file.{ext}")
.count(dd_count)
.block_size(dd_size)
.run()
)
dd.run()
sync()
dirty = cache.get_io_class_statistics(io_class_id=ioclass_id).usage_stats.dirty
if dirty.get_value(Unit.Blocks4096) != (extensions.index(ext) + 1) * dd_count:
@@ -260,11 +263,11 @@ def test_ioclass_file_extension_preexisting_filesystem():
@pytest.mark.require_disk("core", DiskTypeLowerThan("cache"))
def test_ioclass_file_offset():
"""
title: Test IO classification by file offset.
description: Test if file offset classification works properly.
pass_criteria:
- No kernel bug.
- IO is classified properly based on IO class rule with file offset.
title: Test IO classification by file offset.
description: Test if file offset classification works properly.
pass_criteria:
- No kernel bug.
- IO is classified properly based on IO class rule with file offset.
"""
ioclass_id = 1
iterations = 100
@@ -272,6 +275,7 @@ def test_ioclass_file_offset():
dd_count = 1
min_cached_offset = 16384
max_cached_offset = 65536
blocks4096 = Unit.Blocks4096.get_value()
with TestRun.step("Prepare cache and core."):
cache, core = prepare()
@@ -296,22 +300,21 @@ def test_ioclass_file_offset():
with TestRun.step("Write to file within cached offset range and check if it is cached."):
# Since ioclass rule consists of strict inequalities, 'seek' can't be set to first
# nor last sector
min_seek = int((min_cached_offset + Unit.Blocks4096.value) / Unit.Blocks4096.value)
max_seek = int(
(max_cached_offset - min_cached_offset - Unit.Blocks4096.value)
/ Unit.Blocks4096.value
)
min_seek = int((min_cached_offset + blocks4096) / blocks4096)
max_seek = int((max_cached_offset - min_cached_offset - blocks4096) / blocks4096)
for i in range(iterations):
file_offset = random.choice(range(min_seek, max_seek))
dd = (
Dd().input("/dev/zero")
.output(f"{mountpoint}/tmp_file")
.count(dd_count)
.block_size(dd_size)
.seek(file_offset)
(
Dd()
.input("/dev/zero")
.output(f"{mountpoint}/tmp_file")
.count(dd_count)
.block_size(dd_size)
.seek(file_offset)
.run()
)
dd.run()
sync()
dirty = cache.get_io_class_statistics(io_class_id=ioclass_id).usage_stats.dirty
if dirty.get_value(Unit.Blocks4096) != 1:
@@ -319,20 +322,22 @@ def test_ioclass_file_offset():
cache.flush_cache()
with TestRun.step(
"Write to file outside of cached offset range and check if it is not cached."):
"Write to file outside of cached offset range and check if it is not cached."
):
min_seek = 0
max_seek = int(min_cached_offset / Unit.Blocks4096.value)
max_seek = int(min_cached_offset / blocks4096)
TestRun.LOGGER.info(f"Writing to file outside of cached offset range")
for i in range(iterations):
file_offset = random.choice(range(min_seek, max_seek))
dd = (
Dd().input("/dev/zero")
.output(f"{mountpoint}/tmp_file")
.count(dd_count)
.block_size(dd_size)
.seek(file_offset)
(
Dd()
.input("/dev/zero")
.output(f"{mountpoint}/tmp_file")
.count(dd_count)
.block_size(dd_size)
.seek(file_offset)
.run()
)
dd.run()
sync()
dirty = cache.get_io_class_statistics(io_class_id=ioclass_id).usage_stats.dirty
if dirty.get_value(Unit.Blocks4096) != 0:
@@ -345,11 +350,11 @@ def test_ioclass_file_offset():
@pytest.mark.parametrizex("filesystem", Filesystem)
def test_ioclass_file_size(filesystem):
"""
title: Test IO classification by file size.
description: Test if file size classification works properly.
pass_criteria:
- No kernel bug.
- IO is classified properly based on IO class rule with file size.
title: Test IO classification by file size.
description: Test if file size classification works properly.
pass_criteria:
- No kernel bug.
- IO is classified properly based on IO class rule with file size.
"""
# File size IO class rules are configured in a way that each tested file size is unambiguously
@@ -375,8 +380,9 @@ def test_ioclass_file_size(filesystem):
with TestRun.step("Prepare and load IO class config."):
load_file_size_io_classes(cache, base_size)
with TestRun.step(f"Prepare {filesystem.name} filesystem and mount {core.path} "
f"at {mountpoint}."):
with TestRun.step(
f"Prepare {filesystem.name} filesystem and mount {core.path} " f"at {mountpoint}."
):
core.create_filesystem(filesystem)
core.mount(mountpoint)
sync()
@@ -385,26 +391,28 @@ def test_ioclass_file_size(filesystem):
test_files = []
for size, ioclass_id in size_to_class.items():
occupancy_before = cache.get_io_class_statistics(
io_class_id=ioclass_id).usage_stats.occupancy
io_class_id=ioclass_id
).usage_stats.occupancy
file_path = f"{mountpoint}/test_file_{size.get_value()}"
Dd().input("/dev/zero").output(file_path).oflag("sync").block_size(size).count(1).run()
sync()
drop_caches(DropCachesMode.ALL)
occupancy_after = cache.get_io_class_statistics(
io_class_id=ioclass_id).usage_stats.occupancy
io_class_id=ioclass_id
).usage_stats.occupancy
if occupancy_after != occupancy_before + size:
TestRun.fail("File not cached properly!\n"
f"Expected {occupancy_before + size}\n"
f"Actual {occupancy_after}")
TestRun.fail(
"File not cached properly!\n"
f"Expected {occupancy_before + size}\n"
f"Actual {occupancy_after}"
)
test_files.append(File(file_path).refresh_item())
sync()
drop_caches(DropCachesMode.ALL)
with TestRun.step("Move all files to 'unclassified' IO class."):
ioclass_config.remove_ioclass_config(ioclass_config_path=ioclass_config_path)
ioclass_config.create_ioclass_config(
add_default_rule=False, ioclass_config_path=ioclass_config_path
)
ioclass_config.remove_ioclass_config(ioclass_config_path)
ioclass_config.create_ioclass_config(False, ioclass_config_path)
ioclass_config.add_ioclass(
ioclass_id=0,
eviction_priority=22,
@@ -428,18 +436,18 @@ def test_ioclass_file_size(filesystem):
occupancy_after = cache.get_io_class_statistics(io_class_id=0).usage_stats.occupancy
occupancy_expected = occupancy_before + file.size
if occupancy_after != occupancy_expected:
TestRun.fail("File not reclassified properly!\n"
f"Expected {occupancy_expected}\n"
f"Actual {occupancy_after}")
TestRun.fail(
"File not reclassified properly!\n"
f"Expected {occupancy_expected}\n"
f"Actual {occupancy_after}"
)
occupancy_before = occupancy_after
sync()
drop_caches(DropCachesMode.ALL)
with TestRun.step("Restore IO class configuration."):
ioclass_config.remove_ioclass_config(ioclass_config_path=ioclass_config_path)
ioclass_config.create_ioclass_config(
add_default_rule=False, ioclass_config_path=ioclass_config_path
)
ioclass_config.remove_ioclass_config(ioclass_config_path)
ioclass_config.create_ioclass_config(False, ioclass_config_path)
ioclass_config.add_ioclass(
ioclass_id=0,
eviction_priority=22,
@@ -457,18 +465,22 @@ def test_ioclass_file_size(filesystem):
for file in test_files:
ioclass_id = size_to_class[file.size]
occupancy_before = cache.get_io_class_statistics(
io_class_id=ioclass_id).usage_stats.occupancy
io_class_id=ioclass_id
).usage_stats.occupancy
Dd().input(file.full_path).output("/dev/null").block_size(file.size).run()
sync()
drop_caches(DropCachesMode.ALL)
occupancy_after = cache.get_io_class_statistics(
io_class_id=ioclass_id).usage_stats.occupancy
io_class_id=ioclass_id
).usage_stats.occupancy
actual_blocks = occupancy_after.get_value(Unit.Blocks4096)
expected_blocks = (occupancy_before + file.size).get_value(Unit.Blocks4096)
if actual_blocks != expected_blocks:
TestRun.fail("File not reclassified properly!\n"
f"Expected {occupancy_before + file.size}\n"
f"Actual {occupancy_after}")
TestRun.fail(
"File not reclassified properly!\n"
f"Expected {occupancy_before + file.size}\n"
f"Actual {occupancy_after}"
)
sync()
drop_caches(DropCachesMode.ALL)