From 2f289bd873a32263c0a02dc3f69737180c90e308 Mon Sep 17 00:00:00 2001 From: Jan Musial Date: Tue, 21 Jun 2022 15:32:31 +0200 Subject: [PATCH 1/4] pyocf: update OcfErrorCode with new code Signed-off-by: Jan Musial --- tests/functional/pyocf/types/shared.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/functional/pyocf/types/shared.py b/tests/functional/pyocf/types/shared.py index a401793..4499eb0 100644 --- a/tests/functional/pyocf/types/shared.py +++ b/tests/functional/pyocf/types/shared.py @@ -1,5 +1,5 @@ # -# Copyright(c) 2019-2021 Intel Corporation +# Copyright(c) 2019-2022 Intel Corporation # SPDX-License-Identifier: BSD-3-Clause # @@ -59,6 +59,7 @@ class OcfErrorCode(IntEnum): OCF_ERR_STANDBY_ATTACHED = auto() OCF_ERR_CORE_NOT_REMOVED = auto() OCF_ERR_CACHE_NOT_STANDBY = auto() + OCF_ERR_CLEANER_DISABLED = auto() class OcfCompletion: From fb83a182ee029baa7d6499558591a8f07f1f814c Mon Sep 17 00:00:00 2001 From: Jan Musial Date: Tue, 21 Jun 2022 15:33:04 +0200 Subject: [PATCH 2/4] pyocf: API for getting cleaning policy from cache Signed-off-by: Jan Musial --- tests/functional/pyocf/types/cache.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/functional/pyocf/types/cache.py b/tests/functional/pyocf/types/cache.py index a4d3aff..c4510c5 100644 --- a/tests/functional/pyocf/types/cache.py +++ b/tests/functional/pyocf/types/cache.py @@ -17,6 +17,7 @@ from ctypes import ( byref, cast, create_string_buffer, + POINTER, ) from enum import IntEnum, auto from datetime import timedelta @@ -346,6 +347,22 @@ class Cache: if 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): 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_volume.argtypes = [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 = [ c_void_p, c_uint32, From b898f5c336401f78019bf8f03705661db9ae9341 Mon Sep 17 00:00:00 2001 From: Jan Musial Date: Wed, 22 Jun 2022 12:02:54 +0200 Subject: [PATCH 3/4] pyocf: implement test_cleaner_disabled_nop Signed-off-by: Jan Musial --- .../tests/management/test_disable_cleaner.py | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/tests/functional/tests/management/test_disable_cleaner.py b/tests/functional/tests/management/test_disable_cleaner.py index 98f4aad..ae9a884 100644 --- a/tests/functional/tests/management/test_disable_cleaner.py +++ b/tests/functional/tests/management/test_disable_cleaner.py @@ -5,7 +5,7 @@ import pytest 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.shared import OcfError, OcfCompletion 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): """ title: NOP enfocement in cleaner_disabled mode.. @@ -126,7 +125,29 @@ def test_cleaner_disabled_nop(pyocf_ctx): - disable_cleaner::starting_with_nop_policy - 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") From b39161f1aa23f0d735206c78909a362574227587 Mon Sep 17 00:00:00 2001 From: Jan Musial Date: Wed, 22 Jun 2022 09:55:29 +0200 Subject: [PATCH 4/4] pyocf: implement test_attach_cleaner_disabled_non_default Signed-off-by: Jan Musial --- .../tests/management/test_disable_cleaner.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/functional/tests/management/test_disable_cleaner.py b/tests/functional/tests/management/test_disable_cleaner.py index ae9a884..5077397 100644 --- a/tests/functional/tests/management/test_disable_cleaner.py +++ b/tests/functional/tests/management/test_disable_cleaner.py @@ -150,7 +150,6 @@ def test_cleaner_disabled_nop(pyocf_ctx): cache.set_cleaning_policy(CleaningPolicy.NOP) -@pytest.mark.skip(reason="not implemented") def test_attach_cleaner_disabled_non_default(pyocf_ctx): """ title: Attach cache with default config does not set clener_disabled. @@ -169,4 +168,11 @@ def test_attach_cleaner_disabled_non_default(pyocf_ctx): requirements: - 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}"'