Merge pull request #157 from KamilLepek/management

Added a few management tests (changing configuration)
This commit is contained in:
Michał Mielewczyk 2019-05-22 16:20:16 +02:00 committed by GitHub
commit 16a01d7698
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 173 additions and 38 deletions

View File

@ -549,6 +549,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:
for cp_to 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
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:
for seq_to 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
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:
for seq_to 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
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

View File

@ -10,17 +10,39 @@ from random import randrange
import pytest
from pyocf.ocf import OcfLib
from pyocf.types.cache import Cache, CacheMode, MetadataLayout, EvictionPolicy
from pyocf.types.cache import Cache, CacheMode, MetadataLayout, EvictionPolicy, CleaningPolicy
from pyocf.types.core import Core
from pyocf.types.data import Data
from pyocf.types.io import IoDir
from pyocf.types.shared import OcfError, OcfCompletion, CacheLineSize
from pyocf.types.shared import OcfError, OcfCompletion, CacheLineSize, SeqCutOffPolicy
from pyocf.types.volume import Volume
from pyocf.utils import Size
logger = logging.getLogger(__name__)
def test_start_check_default(pyocf_ctx):
"""Test if default values are correct after start.
"""
cache_device = Volume(Size.from_MiB(40))
core_device = Volume(Size.from_MiB(10))
cache = Cache.start_on_device(cache_device)
core = Core.using_device(core_device)
cache.add_core(core)
# Check if values are default
stats = cache.get_stats()
assert stats["conf"]["cleaning_policy"] == CleaningPolicy.DEFAULT
assert stats["conf"]["cache_mode"] == CacheMode.DEFAULT
assert stats["conf"]["cache_line_size"] == CacheLineSize.DEFAULT
assert stats["conf"]["eviction_policy"] == EvictionPolicy.DEFAULT
core_stats = core.get_stats()
assert core_stats["seq_cutoff_policy"] == SeqCutOffPolicy.DEFAULT
@pytest.mark.parametrize("cls", CacheLineSize)
@pytest.mark.parametrize("mode", CacheMode)
def test_start_write_first_and_check_mode(pyocf_ctx, mode: CacheMode, cls: CacheLineSize):