Added a few management tests (changing configuration after start and checking statistics)

Fixed core/cache stats pyocf API

Signed-off-by: Kamil Lepek <kamil.lepek94@gmail.com>
This commit is contained in:
Kamil Lepek 2019-05-16 10:23:17 +02:00
parent a9d07917a1
commit ecd492e562
4 changed files with 149 additions and 36 deletions

View File

@ -531,6 +531,10 @@ lib.ocf_mngt_cache_cleaning_set_policy.argtypes = [c_void_p, c_uint32]
lib.ocf_mngt_cache_cleaning_set_policy.restype = c_int
lib.ocf_mngt_core_set_seq_cutoff_policy_all.argtypes = [c_void_p, c_uint32]
lib.ocf_mngt_core_set_seq_cutoff_policy_all.restype = c_int
lib.ocf_stats_collect_cache.argtypes = [c_void_p, c_void_p, c_void_p, c_void_p, c_void_p]
lib.ocf_stats_collect_cache.restype = c_int
lib.ocf_cache_get_info.argtypes = [c_void_p, c_void_p]
lib.ocf_cache_get_info.restype = c_int
lib.ocf_mngt_cache_cleaning_set_param.argtypes = [
c_void_p,
c_uint32,

View File

@ -112,26 +112,27 @@ class Core:
blocks = BlocksStats()
errors = ErrorsStats()
self.cache.get_and_lock(True)
self.cache.get_and_read_lock()
status = self.cache.owner.lib.ocf_stats_collect_core(
self.handle, byref(usage), byref(req), byref(blocks), byref(errors)
)
if status:
self.cache.put_and_unlock(True)
self.cache.put_and_read_unlock()
raise OcfError("Failed collecting core stats", status)
status = self.cache.owner.lib.ocf_core_get_stats(
self.handle, byref(core_stats)
)
if status:
self.cache.put_and_unlock(True)
self.cache.put_and_read_unlock()
raise OcfError("Failed getting core stats", status)
self.cache.put_and_unlock(True)
self.cache.put_and_read_unlock()
return {
"size": Size(core_stats.core_size_bytes),
"dirty_for": timedelta(seconds=core_stats.dirty_for),
"seq_cutoff_policy": SeqCutOffPolicy(core_stats.seq_cutoff_policy),
"seq_cutoff_threshold": core_stats.seq_cutoff_threshold,
"usage": struct_to_dict(usage),
"req": struct_to_dict(req),
"blocks": struct_to_dict(blocks),
@ -182,3 +183,7 @@ lib.ocf_core_get_volume.argtypes = [c_void_p]
lib.ocf_core_get_volume.restype = c_void_p
lib.ocf_mngt_core_set_seq_cutoff_policy.argtypes = [c_void_p, c_uint32]
lib.ocf_mngt_core_set_seq_cutoff_policy.restype = c_int
lib.ocf_stats_collect_core.argtypes = [c_void_p, c_void_p, c_void_p, c_void_p, c_void_p]
lib.ocf_stats_collect_core.restype = c_int
lib.ocf_core_get_stats.argtypes = [c_void_p, c_void_p]
lib.ocf_core_get_stats.restype = c_int

View File

@ -1,31 +0,0 @@
#
# Copyright(c) 2019 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause-Clear
#
import pytest
from pyocf.types.cache import Cache, CacheMode
from pyocf.types.volume import Volume
from pyocf.utils import Size as S
from pyocf.types.shared import CacheLineSize
@pytest.mark.parametrize("from_cm", CacheMode)
@pytest.mark.parametrize("to_cm", CacheMode)
@pytest.mark.parametrize("cls", CacheLineSize)
def test_change_cache_mode(pyocf_ctx, from_cm, to_cm, cls):
# Start cache device
cache_device = Volume(S.from_MiB(30))
cache = Cache.start_on_device(
cache_device, cache_mode=from_cm, cache_line_size=cls
)
# Check if started with correct cache mode
stats = cache.get_stats()
assert stats["conf"]["cache_mode"] == from_cm
# Change cache mode and check if stats are as expected
cache.change_cache_mode(to_cm)
stats_after = cache.get_stats()
assert stats_after["conf"]["cache_mode"] == to_cm

View File

@ -0,0 +1,135 @@
#
# Copyright(c) 2019 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause-Clear
#
import pytest
from pyocf.types.cache import Cache, CacheMode, CleaningPolicy, SeqCutOffPolicy
from pyocf.types.core import Core
from pyocf.types.volume import Volume
from pyocf.utils import Size as S
from pyocf.types.shared import CacheLineSize
@pytest.mark.parametrize("from_cm", CacheMode)
@pytest.mark.parametrize("to_cm", CacheMode)
@pytest.mark.parametrize("cls", CacheLineSize)
def test_change_cache_mode(pyocf_ctx, from_cm, to_cm, cls):
# Start cache device
cache_device = Volume(S.from_MiB(30))
cache = Cache.start_on_device(
cache_device, cache_mode=from_cm, cache_line_size=cls
)
# Change cache mode and check if stats are as expected
cache.change_cache_mode(to_cm)
stats_after = cache.get_stats()
assert stats_after["conf"]["cache_mode"] == to_cm
@pytest.mark.parametrize("cm", CacheMode)
@pytest.mark.parametrize("cls", CacheLineSize)
def test_change_cleaning_policy(pyocf_ctx, cm, cls):
# Start cache device
cache_device = Volume(S.from_MiB(30))
cache = Cache.start_on_device(
cache_device, cache_mode=cm, cache_line_size=cls
)
# Check all possible cleaning policy switches
for cp_from in CleaningPolicy:
cache.set_cleaning_policy(cp_from.value)
# Check if cleaning policy is correct
stats = cache.get_stats()
assert stats["conf"]["cleaning_policy"] == cp_from.value
for cp_to in CleaningPolicy:
cache.set_cleaning_policy(cp_to.value)
# Check if cleaning policy is correct
stats = cache.get_stats()
assert stats["conf"]["cleaning_policy"] == cp_to.value
@pytest.mark.parametrize("cm", CacheMode)
@pytest.mark.parametrize("cls", CacheLineSize)
def test_cache_change_seq_cut_off_policy(pyocf_ctx, cm, cls):
# Start cache device
cache_device = Volume(S.from_MiB(30))
cache = Cache.start_on_device(
cache_device, cache_mode=cm, cache_line_size=cls
)
# Create 2 core devices
core_device1 = Volume(S.from_MiB(10))
core1 = Core.using_device(core_device1)
core_device2 = Volume(S.from_MiB(10))
core2 = Core.using_device(core_device2)
# Add cores
cache.add_core(core1)
cache.add_core(core2)
# Check all possible seq cut off policy switches
for seq_from in SeqCutOffPolicy:
cache.set_seq_cut_off_policy(seq_from.value)
# Check if seq cut off policy is correct
stats = core1.get_stats()
assert stats["seq_cutoff_policy"] == seq_from.value
stats = core2.get_stats()
assert stats["seq_cutoff_policy"] == seq_from.value
for seq_to in SeqCutOffPolicy:
cache.set_seq_cut_off_policy(seq_to.value)
# Check if seq cut off policy is correct
stats = core1.get_stats()
assert stats["seq_cutoff_policy"] == seq_to.value
stats = core2.get_stats()
assert stats["seq_cutoff_policy"] == seq_to.value
@pytest.mark.parametrize("cm", CacheMode)
@pytest.mark.parametrize("cls", CacheLineSize)
def test_core_change_seq_cut_off_policy(pyocf_ctx, cm, cls):
# Start cache device
cache_device = Volume(S.from_MiB(30))
cache = Cache.start_on_device(
cache_device, cache_mode=cm, cache_line_size=cls
)
# Create 2 core devices
core_device1 = Volume(S.from_MiB(10))
core1 = Core.using_device(core_device1)
core_device2 = Volume(S.from_MiB(10))
core2 = Core.using_device(core_device2)
# Add cores
cache.add_core(core1)
cache.add_core(core2)
# Check all possible seq cut off policy switches for first core
for seq_from in SeqCutOffPolicy:
core1.set_seq_cut_off_policy(seq_from.value)
# Check if seq cut off policy of the first core is correct
stats = core1.get_stats()
assert stats["seq_cutoff_policy"] == seq_from.value
# Check if seq cut off policy of the second core did not change
stats = core2.get_stats()
assert stats["seq_cutoff_policy"] == SeqCutOffPolicy.DEFAULT
for seq_to in SeqCutOffPolicy:
core1.set_seq_cut_off_policy(seq_to.value)
# Check if seq cut off policy of the first core is correct
stats = core1.get_stats()
assert stats["seq_cutoff_policy"] == seq_to.value
# Check if seq cut off policy of the second core did not change
stats = core2.get_stats()
assert stats["seq_cutoff_policy"] == SeqCutOffPolicy.DEFAULT