Merge pull request #742 from jfckm/cleaner-disabled-cp-setting

Tests for disabled_cleaner setting
This commit is contained in:
Robert Baldyga 2022-06-24 14:01:38 +02:00 committed by GitHub
commit b43ff83e33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 6 deletions

View File

@ -17,6 +17,7 @@ from ctypes import (
byref, byref,
cast, cast,
create_string_buffer, create_string_buffer,
POINTER,
) )
from enum import IntEnum, auto from enum import IntEnum, auto
from datetime import timedelta from datetime import timedelta
@ -346,6 +347,22 @@ class Cache:
if c.results["error"]: if c.results["error"]:
raise OcfError("Error changing cleaning policy", c.results["error"]) raise OcfError("Error changing cleaning policy", c.results["error"])
def get_cleaning_policy(self):
cleaning_policy = c_int()
self.read_lock()
status = self.owner.lib.ocf_mngt_cache_cleaning_get_policy(
self.cache_handle, byref(cleaning_policy)
)
self.read_unlock()
if status != OcfErrorCode.OCF_OK:
raise OcfError("Failed to get cleaning policy", ret)
return CleaningPolicy(cleaning_policy.value)
def set_cleaning_policy_param(self, cleaning_policy: CleaningPolicy, param_id, param_value): def set_cleaning_policy_param(self, cleaning_policy: CleaningPolicy, param_id, param_value):
self.write_lock() self.write_lock()
@ -998,6 +1015,8 @@ lib.ocf_cache_get_front_volume.argtypes = [c_void_p]
lib.ocf_cache_get_front_volume.restype = c_void_p lib.ocf_cache_get_front_volume.restype = c_void_p
lib.ocf_cache_get_volume.argtypes = [c_void_p] lib.ocf_cache_get_volume.argtypes = [c_void_p]
lib.ocf_cache_get_volume.restype = c_void_p lib.ocf_cache_get_volume.restype = c_void_p
lib.ocf_mngt_cache_cleaning_get_policy.argypes = [c_void_p, POINTER(c_int)]
lib.ocf_mngt_cache_cleaning_get_policy.restype = OcfErrorCode
lib.ocf_mngt_cache_cleaning_set_policy.argtypes = [ lib.ocf_mngt_cache_cleaning_set_policy.argtypes = [
c_void_p, c_void_p,
c_uint32, c_uint32,

View File

@ -1,5 +1,5 @@
# #
# Copyright(c) 2019-2021 Intel Corporation # Copyright(c) 2019-2022 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
# #
@ -59,6 +59,7 @@ class OcfErrorCode(IntEnum):
OCF_ERR_STANDBY_ATTACHED = auto() OCF_ERR_STANDBY_ATTACHED = auto()
OCF_ERR_CORE_NOT_REMOVED = auto() OCF_ERR_CORE_NOT_REMOVED = auto()
OCF_ERR_CACHE_NOT_STANDBY = auto() OCF_ERR_CACHE_NOT_STANDBY = auto()
OCF_ERR_CLEANER_DISABLED = auto()
class OcfCompletion: class OcfCompletion:

View File

@ -5,7 +5,7 @@
import pytest import pytest
from pyocf.types.volume import RamVolume from pyocf.types.volume import RamVolume
from pyocf.types.cache import Cache, CacheMetadataSegment from pyocf.types.cache import Cache, CacheMetadataSegment, CleaningPolicy
from pyocf.types.core import Core from pyocf.types.core import Core
from pyocf.types.shared import OcfError, OcfCompletion from pyocf.types.shared import OcfError, OcfCompletion
from pyocf.utils import Size as S from pyocf.utils import Size as S
@ -103,7 +103,6 @@ def test_load_cleaner_disabled(pyocf_ctx):
@pytest.mark.skip(reason="not implemented")
def test_cleaner_disabled_nop(pyocf_ctx): def test_cleaner_disabled_nop(pyocf_ctx):
""" """
title: NOP enfocement in cleaner_disabled mode.. title: NOP enfocement in cleaner_disabled mode..
@ -126,10 +125,31 @@ def test_cleaner_disabled_nop(pyocf_ctx):
- disable_cleaner::starting_with_nop_policy - disable_cleaner::starting_with_nop_policy
- disable_cleaner::nop_enforcement - disable_cleaner::nop_enforcement
""" """
pass cache_device = RamVolume(S.from_MiB(50))
cache = Cache.start_on_device(cache_device, disable_cleaner=True)
assert cache.get_cleaning_policy() == CleaningPolicy.NOP, (
"Cleaning policy should be NOP after starting cache with disabled cleaner"
)
with pytest.raises(OcfError):
cache.set_cleaning_policy(CleaningPolicy.ALRU)
assert cache.get_cleaning_policy() == CleaningPolicy.NOP, (
"It shouldn't be possible to switch cleaning policy to ALRU when cleaner is disabled"
)
with pytest.raises(OcfError):
cache.set_cleaning_policy(CleaningPolicy.ACP)
assert cache.get_cleaning_policy() == CleaningPolicy.NOP, (
"It shouldn't be possible to switch cleaning policy to ACP when cleaner is disabled"
)
cache.set_cleaning_policy(CleaningPolicy.NOP)
@pytest.mark.skip(reason="not implemented")
def test_attach_cleaner_disabled_non_default(pyocf_ctx): def test_attach_cleaner_disabled_non_default(pyocf_ctx):
""" """
title: Attach cache with default config does not set clener_disabled. title: Attach cache with default config does not set clener_disabled.
@ -148,4 +168,11 @@ def test_attach_cleaner_disabled_non_default(pyocf_ctx):
requirements: requirements:
- disable_cleaner::default_setting - disable_cleaner::default_setting
""" """
pass cache_device = RamVolume(S.from_MiB(50))
cache = Cache.start_on_device(cache_device)
cleaning_size = get_metadata_segment_size(cache, CacheMetadataSegment.CLEANING)
assert (
cleaning_size > 0
), f'Metadata cleaning segment size expected: "> 0", got: "{cleaning_size}"'