Skip to content

Commit

Permalink
tests: refactor inactive core stats test
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 51be6fe commit 1412619
Showing 1 changed file with 147 additions and 136 deletions.
283 changes: 147 additions & 136 deletions test/functional/tests/incremental_load/test_inactive_cores.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#
# Copyright(c) 2019-2021 Intel Corporation
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#


import pytest

from api.cas import casadm
Expand All @@ -16,152 +16,163 @@

@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
@pytest.mark.require_disk("core", DiskTypeLowerThan("cache"))
def test_core_inactive():
def test_core_inactive_stats_conf():
"""
1. Start cache with 3 cores.
2. Stop cache.
3. Remove one of core devices.
4. Load cache.
5. Check if cache has appropriate number of valid and inactive core devices.
title: Test for inactive core configuration statistics.
description: |
Test the cache inactive core configuration statistics after removing one of core devices
and loading
cache.
pass_criteria:
- Cache can be loaded with inactive core device.
- CAS correctly reports inactive core statistics in cache configuration statistics after
loading cache.
"""
cache, core_device = prepare()
core_numbers = 3

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

cache_device.create_partitions([Size(500, Unit.MebiByte)])
core_device.create_partitions([Size(1, Unit.GibiByte)] * core_numbers)

cache_device = cache_device.partitions[0]
core_device_partitions = core_device.partitions

with TestRun.step("Staring cache"):
cache = casadm.start_cache(cache_device, force=True)
cache_device = cache.cache_device

cache_device = cache.cache_device
stats = cache.get_statistics()
with TestRun.step("Add cores devices to the cache"):
for core_device_part in core_device_partitions:
cache.add_core(core_dev=core_device_part)

assert stats.config_stats.core_dev == 3
assert stats.config_stats.inactive_core_devices == 0
with TestRun.step("Check if there is correct number of inactive cores in cache statistics"):
stats = cache.get_statistics()
if stats.config_stats.inactive_core_devices != 0:
TestRun.fail("There is inactive core after starting cache")

TestRun.LOGGER.info("Stopping cache")
cache.stop()
with TestRun.step("Stop cache"):
cache.stop()

TestRun.LOGGER.info("Removing one of core devices")
core_device.remove_partitions()
core_device.create_partitions([Size(1, Unit.GibiByte), Size(1, Unit.GibiByte)])
with TestRun.step("Remove last core device"):
core_device.remove_partition(part=core_device_partitions[-1])

TestRun.LOGGER.info("Loading cache with missing core device")
cache = casadm.start_cache(cache_device, load=True)
stats = cache.get_statistics()
with TestRun.step("Load cache with missing core device"):
cache = casadm.start_cache(cache_device, load=True)

assert stats.config_stats.core_dev == 3
assert stats.config_stats.inactive_core_devices == 1
with TestRun.step(
"Check if there is the correct number of cores and inactive cores in cache " "statistics"
):
stats = cache.get_statistics()
if stats.config_stats.core_dev != 3:
TestRun.fail("There is the wrong number of cores after loading the cache")
if stats.config_stats.inactive_core_devices != 1:
TestRun.fail("There is the wrong number of inactive core after loading the cache")


@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
@pytest.mark.require_disk("core", DiskTypeLowerThan("cache"))
def test_core_inactive_stats():
def test_core_inactive_stats_usage():
"""
1. Start cache with 3 cores.
2. Switch cache into WB mode.
3. Issue IO to each core.
4. Stop cache without flush.
5. Remove two core devices.
6. Load cache.
7. Check if cache stats are equal to sum of valid and inactive cores stats.
8. Check if percentage values are calculated properly.
title: Test for inactive core usage statistics.
description: |
Test the cache inactive core usage statistics after removing one of core devices and loading
cache.
pass_criteria:
- Cache can be loaded with inactive core device.
- CAS correctly reports inactive core statistics in cache usage statistics after loading
cache.
"""
cache, core_device = prepare()

cache_device = cache.cache_device

TestRun.LOGGER.info("Switching cache mode to WB")
cache.set_cache_mode(cache_mode=CacheMode.WB)
cores = cache.get_core_devices()
TestRun.LOGGER.info("Issue IO to each core")
for core in cores:
dd = (
Dd()
.input("/dev/zero")
.output(core.path)
.count(1000)
.block_size(Size(4, Unit.KibiByte))
).run()

TestRun.LOGGER.info("Stopping cache with dirty data")
cores[2].flush_core()
cache.stop(no_data_flush=True)

TestRun.LOGGER.info("Removing two of core devices")
core_device.remove_partitions()
core_device.create_partitions([Size(1, Unit.GibiByte)])

TestRun.LOGGER.info("Loading cache with missing core device")
cache = casadm.start_cache(cache_device, load=True)

# Accumulate valid cores stats
cores_occupancy = 0
cores_clean = 0
cores_dirty = 0
cores = cache.get_core_devices()
for core in cores:
core_stats = core.get_statistics()
cores_occupancy += core_stats.usage_stats.occupancy.value
cores_clean += core_stats.usage_stats.clean.value
cores_dirty += core_stats.usage_stats.dirty.value

cache_stats = cache.get_statistics()
# Add inactive core stats
cores_occupancy += cache_stats.usage_stats.inactive_occupancy.value
cores_clean += cache_stats.usage_stats.inactive_clean.value
cores_dirty += cache_stats.usage_stats.inactive_dirty.value

assert cache_stats.usage_stats.occupancy.value == cores_occupancy
assert cache_stats.usage_stats.dirty.value == cores_dirty
assert cache_stats.usage_stats.clean.value == cores_clean

cache_stats_percentage = cache.get_statistics(percentage_val=True)
# Calculate expected percentage value of inactive core stats
inactive_occupancy_perc = (
cache_stats.usage_stats.inactive_occupancy.value
/ cache_stats.config_stats.cache_size.value
)
inactive_clean_perc = (
cache_stats.usage_stats.inactive_clean.value
/ cache_stats.usage_stats.occupancy.value
)
inactive_dirty_perc = (
cache_stats.usage_stats.inactive_dirty.value
/ cache_stats.usage_stats.occupancy.value
)

inactive_occupancy_perc = round(100 * inactive_occupancy_perc, 1)
inactive_clean_perc = round(100 * inactive_clean_perc, 1)
inactive_dirty_perc = round(100 * inactive_dirty_perc, 1)

TestRun.LOGGER.info(str(cache_stats_percentage))
assert (
inactive_occupancy_perc
== cache_stats_percentage.usage_stats.inactive_occupancy
)
assert (
inactive_clean_perc
== cache_stats_percentage.usage_stats.inactive_clean
)
assert (
inactive_dirty_perc
== cache_stats_percentage.usage_stats.inactive_dirty
)


def prepare():
cache_device = TestRun.disks["cache"]
core_device = TestRun.disks["core"]

cache_device.create_partitions([Size(500, Unit.MebiByte)])
core_device.create_partitions(
[Size(1, Unit.GibiByte), Size(1, Unit.GibiByte), Size(1, Unit.GibiByte)]
)

cache_device = cache_device.partitions[0]
core_device_1 = core_device.partitions[0]
core_device_2 = core_device.partitions[1]
core_device_3 = core_device.partitions[2]

TestRun.LOGGER.info("Staring cache")
cache = casadm.start_cache(cache_device, force=True)
TestRun.LOGGER.info("Adding core device")
core_1 = cache.add_core(core_dev=core_device_1)
core_2 = cache.add_core(core_dev=core_device_2)
core_3 = cache.add_core(core_dev=core_device_3)

return cache, core_device
core_numbers = 3

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

cache_device.create_partitions([Size(500, Unit.MebiByte)])
core_device.create_partitions([Size(1, Unit.GibiByte)] * core_numbers)

cache_device = cache_device.partitions[0]
core_device_partitions = core_device.partitions

with TestRun.step("Staring cache"):
cache = casadm.start_cache(cache_device, force=True, cache_mode=CacheMode.WB)
cache_device = cache.cache_device

with TestRun.step("Add cores devices to the cache"):
core_list = [
cache.add_core(core_dev=core_device_part) for core_device_part in core_device_partitions
]

with TestRun.step("Run I/O to each core"):
for core in core_list:
dd = (
Dd()
.input("/dev/zero")
.output(core.path)
.count(1000)
.block_size(Size(4, Unit.KibiByte))
)
dd.run()

with TestRun.step("Flush last core"):
core_list[-1].flush_core()

with TestRun.step("Stopp cache with dirty data"):
cache.stop(no_data_flush=True)

with TestRun.step("Removing two of core devices"):
core_device.remove_partition(part=core_device_partitions[0])
core_device.remove_partition(part=core_device_partitions[1])

with TestRun.step("Loading cache with missing core device"):
cache = casadm.start_cache(cache_device, load=True)

with TestRun.step("Check cores statistics"):
cores_occupancy = 0
cores_clean = 0
cores_dirty = 0

active_cores = cache.get_core_devices()
for core in active_cores:
core_stats = core.get_statistics()
cores_occupancy += core_stats.usage_stats.occupancy.value
cores_clean += core_stats.usage_stats.clean.value
cores_dirty += core_stats.usage_stats.dirty.value

cache_stats = cache.get_statistics()
cache_usage_stats = cache_stats.usage_stats

# Add inactive core stats
cores_occupancy += cache_usage_stats.inactive_occupancy.value
cores_clean += cache_usage_stats.inactive_clean.value
cores_dirty += cache_usage_stats.inactive_dirty.value

if cache_usage_stats.occupancy.value != cores_occupancy:
TestRun.LOGGER.error("Wrong number of occupancy blocks in cache usage stats")
if cache_usage_stats.dirty.value != cores_dirty:
TestRun.LOGGER.error("Wrong number of dirty blocks in cache usage stats")
if cache_usage_stats.clean.value != cores_clean:
TestRun.LOGGER.error("Wrong number of clean blocks in cache usage stats")

cache_usage_stats_percentage = cache.get_statistics(percentage_val=True).usage_stats

# Calculate expected percentage value of inactive core stats
inactive_occupancy_perc = round(
100 * (cache_usage_stats.inactive_occupancy / cache_stats.config_stats.cache_size), 1
)
inactive_dirty_perc = round(
100 * (cache_usage_stats.inactive_dirty / cache_stats.usage_stats.occupancy), 1
)
inactive_clean_perc = round(
100 * (cache_usage_stats.inactive_clean / cache_stats.usage_stats.occupancy), 1
)

if inactive_occupancy_perc != cache_usage_stats_percentage.inactive_occupancy:
TestRun.LOGGER.error("Wrong number of occupancy blocks in usage stats")
if inactive_dirty_perc != cache_usage_stats_percentage.inactive_dirty:
TestRun.LOGGER.error("Wrong number of dirty blocks in usage stats")
if inactive_clean_perc != cache_usage_stats_percentage.inactive_clean:
TestRun.LOGGER.error("Wrong number of clean blocks in usage stats")

0 comments on commit 1412619

Please sign in to comment.