Skip to content

Commit

Permalink
tests: update tests: fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamil Gierszewski committed Aug 30, 2024
1 parent 1b2d893 commit 70c892e
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_support_different_io_size(cache_mode):
- No IO errors
"""

with TestRun.step("Prepare cache and core"):
with TestRun.step("Prepare cache and core devices"):
cache_disk = TestRun.disks["cache"]
core_disk = TestRun.disks["core"]
cache_disk.create_partitions([Size(1, Unit.GibiByte)])
Expand Down
18 changes: 9 additions & 9 deletions test/functional/tests/basic/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,12 @@ def test_cas_version():

with TestRun.step(f"Read cas version from {version_file_path} location"):
file_read = fs_utils.read_file(version_file_path).split("\n")
file_version, *_ = [line for line in file_read if "CAS_VERSION=" in line]
file_cas_version_list = file_version.split("=")[1]
file_cas_version = next(
(line.split("=")[1] for line in file_read if "CAS_VERSION=" in line)
)

with TestRun.step("Compare cmd and file versions"):
if not all(
file_cas_version_list == file_cas_version for file_cas_version in cmd_cas_versions
):
if not all(file_cas_version == cmd_cas_version for cmd_cas_version in cmd_cas_versions):
TestRun.LOGGER.error(f"Cmd and file versions doesn`t match")


Expand All @@ -69,9 +68,11 @@ def test_negative_start_cache():
- Fails to start cache on another partition with the same id
"""

with TestRun.step("Partition cache devices"):
with TestRun.step("Prepare cache and core devices"):
cache_dev = TestRun.disks["cache"]

cache_dev.create_partitions([Size(2, Unit.GibiByte)] * 2)

cache_dev_1 = cache_dev.partitions[0]
cache_dev_2 = cache_dev.partitions[1]

Expand Down Expand Up @@ -102,7 +103,6 @@ def test_negative_start_cache():
)
)
TestRun.fail("Two caches started with same ID")

except CmdException:
if not check_stderr_msg(output, start_cache_with_existing_id):
TestRun.fail(f"Received unexpected error message: {output.stderr}")
Expand All @@ -125,7 +125,7 @@ def test_data_integrity(filesystem, cache_mode, cache_line_size):
- Data consistency is preserved.
"""

with TestRun.step("Partition cache and core devices"):
with TestRun.step("Prepare cache and core devices"):
cache_device = TestRun.disks["cache"]
core_device = TestRun.disks["core"]

Expand All @@ -140,7 +140,7 @@ def test_data_integrity(filesystem, cache_mode, cache_line_size):
cache_dev=cache_part, cache_mode=cache_mode, cache_line_size=cache_line_size, force=True
)
core = cache.add_core(core_dev=core_part)

with TestRun.step("Create filesystem on CAS device and mount it"):
core.create_filesystem(filesystem)
core.mount(mountpoint)
Expand Down
3 changes: 2 additions & 1 deletion test/functional/tests/basic/test_start_cas.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ def test_start_cache_add_core():
"""
with TestRun.step("Prepare cache and core devices"):
cache_dev = TestRun.disks["cache"]
cache_dev.create_partitions([Size(500, Unit.MebiByte)])
core_dev = TestRun.disks["core"]

cache_dev.create_partitions([Size(500, Unit.MebiByte)])
core_dev.create_partitions([Size(2, Unit.GibiByte)])

with TestRun.step("Start cache"):
Expand Down
28 changes: 15 additions & 13 deletions test/functional/tests/cache_ops/test_cleaning_policy_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
@pytest.mark.parametrize("cleaning_policy", CleaningPolicy)
@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
@pytest.mark.require_disk("core", DiskTypeLowerThan("cache"))
def test_cleaning_policies_in_write_back(cleaning_policy):
def test_cleaning_policies_in_write_back(cleaning_policy: CleaningPolicy):
"""
title: Test for cleaning policy operation in Write-Back cache mode.
description: |
Expand All @@ -50,10 +50,11 @@ def test_cleaning_policies_in_write_back(cleaning_policy):
- Dirty data is flushed or not according to the policy used.
"""

with TestRun.step("Partition cache and core devices"):
with TestRun.step("Prepare cache and core devices"):
cache_dev = TestRun.disks["cache"]
cache_dev.create_partitions([Size(1, Unit.GibiByte)])
core_dev = TestRun.disks["core"]

cache_dev.create_partitions([Size(1, Unit.GibiByte)])
core_dev.create_partitions([Size(2, Unit.GibiByte)] * cores_count)

with TestRun.step("Disable udev"):
Expand All @@ -62,7 +63,7 @@ def test_cleaning_policies_in_write_back(cleaning_policy):
with TestRun.step(f"Start cache in Write-Back mode with {cleaning_policy} cleaning policy"):
cache = casadm.start_cache(cache_dev.partitions[0], CacheMode.WB, force=True)
cache.set_cleaning_policy(cleaning_policy=cleaning_policy)
set_params(cache, cleaning_policy)
set_cleaning_policy_params(cache, cleaning_policy)

with TestRun.step("Check for running CAS cleaner"):
output = TestRun.executor.run(f"pgrep {cas_cleaner_process_name}")
Expand All @@ -88,13 +89,13 @@ def test_cleaning_policies_in_write_back(cleaning_policy):
fio.run()
time.sleep(3)

core_writes_before_wait_for_cleaning = cache.get_statistics().block_stats_cache.core.writes
core_writes_before_wait_for_cleaning = cache.get_statistics().block_stats.core.writes

with TestRun.step(f"Wait {time_to_wait} seconds"):
time.sleep(time_to_wait)

with TestRun.step("Check write statistics for core device"):
core_writes_after_wait_for_cleaning = cache.get_statistics().block_stats_cache.core.writes
core_writes_after_wait_for_cleaning = cache.get_statistics().block_stats.core.writes
check_cleaning_policy_operation(
cleaning_policy,
core_writes_before_wait_for_cleaning,
Expand All @@ -117,18 +118,19 @@ def test_cleaning_policies_in_write_through(cleaning_policy):
- Dirty data is flushed or not according to the policy used.
"""

with TestRun.step("Partition cache and core devices"):
with TestRun.step("Prepare cache and core devices"):
cache_dev = TestRun.disks["cache"]
cache_dev.create_partitions([Size(1, Unit.GibiByte)])
core_dev = TestRun.disks["core"]

cache_dev.create_partitions([Size(1, Unit.GibiByte)])
core_dev.create_partitions([Size(2, Unit.GibiByte)] * cores_count)

with TestRun.step("Disable udev"):
Udev.disable()

with TestRun.step(f"Start cache in Write-Through mode with {cleaning_policy} cleaning policy"):
cache = casadm.start_cache(cache_dev.partitions[0], CacheMode.WT, force=True)
set_params(cache, cleaning_policy)
set_cleaning_policy_params(cache, cleaning_policy)

with TestRun.step("Check for running CAS cleaner"):
output = TestRun.executor.run(f"pgrep {cas_cleaner_process_name}")
Expand Down Expand Up @@ -157,25 +159,25 @@ def test_cleaning_policies_in_write_through(cleaning_policy):

with TestRun.step("Change cache mode back to Write-Through"):
cache.set_cache_mode(CacheMode.WT, flush=False)
core_writes_before_wait_for_cleaning = cache.get_statistics().block_stats_cache.core.writes
core_writes_before_wait_for_cleaning = cache.get_statistics().block_stats.core.writes

with TestRun.step(f"Wait {time_to_wait} seconds"):
time.sleep(time_to_wait)

with TestRun.step("Check write statistics for core device"):
core_writes_after_wait_for_cleaning = cache.get_statistics().block_stats_cache.core.writes
core_writes_after_wait_for_cleaning = cache.get_statistics().block_stats.core.writes
check_cleaning_policy_operation(
cleaning_policy,
core_writes_before_wait_for_cleaning,
core_writes_after_wait_for_cleaning,
)


def set_params(cache, cleaning_policy):
def set_cleaning_policy_params(cache, cleaning_policy):
current_cleaning_policy = cache.get_cleaning_policy()
if current_cleaning_policy != cleaning_policy:
TestRun.LOGGER.error(
f"Cleaning policy is {current_cleaning_policy}, " f"should be {cleaning_policy}"
f"Cleaning policy is {current_cleaning_policy}, should be {cleaning_policy}"
)

match cleaning_policy:
Expand Down
32 changes: 19 additions & 13 deletions test/functional/tests/cache_ops/test_concurrent_flushes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@pytest.mark.parametrize("cache_mode", CacheMode.with_traits(CacheModeTrait.LazyWrites))
@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
@pytest.mark.require_disk("core", DiskTypeSet([DiskType.hdd, DiskType.hdd4k]))
def test_concurrent_cores_flush(cache_mode):
def test_concurrent_cores_flush(cache_mode: CacheMode):
"""
title: Fail to flush two cores simultaneously.
description: |
Expand All @@ -34,12 +34,14 @@ def test_concurrent_cores_flush(cache_mode):
the same cache simultaneously.
"""

with TestRun.step("Prepare cache and core"):
with TestRun.step("Prepare cache and core devices"):
cache_dev = TestRun.disks["cache"]
cache_dev.create_partitions([Size(2, Unit.GibiByte)])
cache_part = cache_dev.partitions[0]
core_dev = TestRun.disks["core"]

cache_dev.create_partitions([Size(2, Unit.GibiByte)])
core_dev.create_partitions([Size(5, Unit.GibiByte)] * 2)

cache_part = cache_dev.partitions[0]
core_part1 = core_dev.partitions[0]
core_part2 = core_dev.partitions[1]

Expand All @@ -64,7 +66,7 @@ def test_concurrent_cores_flush(cache_mode):
.target(core.path)
.size(core.size)
.block_size(Size(4, Unit.MebiByte))
.read_write(ReadWrite.randwrite)
.read_write(ReadWrite.write)
.direct(1)
)
fio_pid = fio.run_in_background()
Expand Down Expand Up @@ -147,7 +149,7 @@ def test_concurrent_cores_flush(cache_mode):
@pytest.mark.parametrize("cache_mode", CacheMode.with_traits(CacheModeTrait.LazyWrites))
@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
@pytest.mark.require_disk("core", DiskTypeLowerThan("cache"))
def test_concurrent_caches_flush(cache_mode):
def test_concurrent_caches_flush(cache_mode: CacheMode):
"""
title: Success to flush two caches simultaneously.
description: |
Expand All @@ -156,16 +158,20 @@ def test_concurrent_caches_flush(cache_mode):
- No system crash.
- Flush for each cache should finish successfully.
"""
caches_number = 3

with TestRun.step("Prepare caches and cores"):
with TestRun.step("Prepare cache and core devices"):
cache_dev = TestRun.disks["cache"]
cache_dev.create_partitions([Size(2, Unit.GibiByte)] * 3)
core_dev = TestRun.disks["core"]
core_dev.create_partitions([Size(2, Unit.GibiByte) * 2] * 3)

with TestRun.step(f"Start 3 caches"):
caches = [casadm.start_cache(cache_dev=part, cache_mode=cache_mode, force=True) for part in
cache_dev.partitions]
cache_dev.create_partitions([Size(2, Unit.GibiByte)] * caches_number)
core_dev.create_partitions([Size(2, Unit.GibiByte) * 2] * caches_number)

with TestRun.step(f"Start {caches_number} caches"):
caches = [
casadm.start_cache(cache_dev=part, cache_mode=cache_mode, force=True)
for part in cache_dev.partitions
]

with TestRun.step("Disable cleaning and sequential cutoff"):
for cache in caches:
Expand All @@ -192,7 +198,7 @@ def test_concurrent_caches_flush(cache_mode):

with TestRun.step("Check if each cache is full of dirty blocks"):
for cache in caches:
if not cache.get_dirty_blocks() != core.size.set_unit(Unit.Blocks4096):
if not cache.get_dirty_blocks() != core.size:
TestRun.fail(f"The cache {cache.cache_id} does not contain dirty blocks")

with TestRun.step("Start flush operation on all caches simultaneously"):
Expand Down
25 changes: 13 additions & 12 deletions test/functional/tests/cache_ops/test_core_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
from test_utils.size import Size, Unit

mount_point = "/mnt/cas"
cores_amount = 3


@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
@pytest.mark.require_disk("core", DiskTypeLowerThan("cache"))
def test_remove_core_when_other_mounted_auto_numeration():
"""
title: Test for removing one core from the cache when the other core is mounted.
Cores are numerated automatically.
title: Remove one core when other are mounted - auto-numerated.
description: |
Test of the ability to remove the unmounted core from the cache when the other core
is mounted and its ID starts with a different digit.
Expand All @@ -32,16 +32,17 @@ def test_remove_core_when_other_mounted_auto_numeration():
- Removing unmounted core finished with success.
"""

with TestRun.step("Prepare cache and core"):
with TestRun.step("Prepare cache and core devices"):
cache_device = TestRun.disks["cache"]
cache_device.create_partitions([Size(50, Unit.MebiByte)])
core_device = TestRun.disks["core"]
core_device.create_partitions([Size(200, Unit.MebiByte)] * 3)

cache_device.create_partitions([Size(50, Unit.MebiByte)])
core_device.create_partitions([Size(200, Unit.MebiByte)] * cores_amount)

with TestRun.step("Start cache"):
cache = casadm.start_cache(cache_device.partitions[0], force=True)

with TestRun.step("Add cores to cache and mount them except the first one"):
with TestRun.step(f"Add {cores_amount} cores to cache and mount them except the first one"):
free_core = cache.add_core(core_device.partitions[0])
mounted_cores = []
for i, part in enumerate(core_device.partitions[1:]):
Expand All @@ -62,8 +63,7 @@ def test_remove_core_when_other_mounted_auto_numeration():
@pytest.mark.require_disk("core", DiskTypeLowerThan("cache"))
def test_remove_core_when_other_mounted_custom_numeration():
"""
title: Test for removing one core from the cache when the other core is mounted.
Cores have custom numeration, starting with the same digit.
title: Remove one core when other are mounted - custom numeration.
description: |
Test of the ability to remove the unmounted core from the cache when the other core
is mounted and its ID starts with the same digit.
Expand All @@ -72,16 +72,17 @@ def test_remove_core_when_other_mounted_custom_numeration():
- Removing unmounted core finished with success.
"""

with TestRun.step("Prepare devices"):
with TestRun.step("Prepare cache and core devices"):
cache_device = TestRun.disks["cache"]
cache_device.create_partitions([Size(50, Unit.MebiByte)])
core_device = TestRun.disks["core"]

cache_device.create_partitions([Size(50, Unit.MebiByte)])
core_device.create_partitions([Size(200, Unit.MebiByte)] * 3)

with TestRun.step("Start cache"):
cache = casadm.start_cache(cache_device.partitions[0], force=True)

with TestRun.step("Add cores to cache and mount them except the first one"):
with TestRun.step(f"Add {cores_amount} cores to cache and mount them except the first one"):
random_prefix = random.randint(1, 9)
random_interfix = random.randint(1, 9)

Expand All @@ -91,7 +92,7 @@ def test_remove_core_when_other_mounted_custom_numeration():
for i, part in enumerate(core_device.partitions[1:]):
part.create_filesystem(Filesystem.xfs)
mounted_cores.append(
cache.add_core(core_dev=part, core_id=f"{random_prefix}{random_interfix}{i}")
cache.add_core(core_dev=part, core_id=int(f"{random_prefix}{random_interfix}{i}"))
)
mounted_cores[i].mount(
mount_point=f"{mount_point}{cache.cache_id}-{mounted_cores[i].core_id}"
Expand Down
Loading

0 comments on commit 70c892e

Please sign in to comment.