From 973a474b37c6c810cad4bc78e42b53596f0543e4 Mon Sep 17 00:00:00 2001 From: Jan Musial Date: Tue, 22 Feb 2022 11:31:13 +0100 Subject: [PATCH] Make open_cores load viable by adding getter for cores Signed-off-by: Jan Musial --- tests/functional/pyocf/types/cache.py | 27 +++++++++++++++++++++++++++ tests/functional/pyocf/types/core.py | 6 ++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/tests/functional/pyocf/types/cache.py b/tests/functional/pyocf/types/cache.py index 0b28af3..a90598f 100644 --- a/tests/functional/pyocf/types/cache.py +++ b/tests/functional/pyocf/types/cache.py @@ -38,6 +38,7 @@ from .stats.cache import CacheInfo from .ioclass import IoClassesInfo, IoClassInfo from .stats.shared import UsageStats, RequestsStats, BlocksStats, ErrorsStats from .ctx import OcfCtx +from .volume import Volume class Backfill(Structure): @@ -593,6 +594,27 @@ class Cache: def write_unlock(self): self.owner.lib.ocf_mngt_cache_unlock(self.cache_handle) + def get_core_by_name(self, name: str): + core_handle = c_void_p() + + result = self.owner.lib.ocf_core_get_by_name( + self.cache_handle, + name.encode("ascii"), + len(name), + byref(core_handle), + ) + if result != 0: + raise OcfError("Failed getting core by name", result) + + uuid = self.owner.lib.ocf_core_get_uuid_wrapper(core_handle) + device = Volume.get_by_uuid(uuid.contents._data.decode("ascii")) + core = Core(device) + core.cache = self + core.handle = core_handle + self.cores.append(core) + + return core + def add_core(self, core: Core, try_add=False): cfg = core.get_config() @@ -741,6 +763,11 @@ class Cache: self.mngt_queue.put() del self.io_queues[:] + self.started = False + for core in self.cores: + core.cache = None + core.handle = None + self.write_unlock() self.device = None self.started = False diff --git a/tests/functional/pyocf/types/core.py b/tests/functional/pyocf/types/core.py index b83d32a..201706a 100644 --- a/tests/functional/pyocf/types/core.py +++ b/tests/functional/pyocf/types/core.py @@ -19,6 +19,7 @@ from ctypes import ( cast, byref, create_string_buffer, + POINTER, ) from datetime import timedelta @@ -58,7 +59,6 @@ class Core: def __init__( self, device: Volume, - try_add: bool, name: str = "core", seq_cutoff_threshold: int = DEFAULT_SEQ_CUTOFF_THRESHOLD, seq_cutoff_promotion_count: int = DEFAULT_SEQ_CUTOFF_PROMOTION_COUNT, @@ -73,7 +73,7 @@ class Core: @classmethod def using_device(cls, device, **kwargs): - c = cls(device=device, try_add=False, **kwargs) + c = cls(device=device, **kwargs) return c @@ -222,6 +222,8 @@ class Core: lib = OcfLib.getInstance() +lib.ocf_core_get_uuid_wrapper.restype = POINTER(Uuid) +lib.ocf_core_get_uuid_wrapper.argtypes = [c_void_p] lib.ocf_core_get_volume.restype = c_void_p lib.ocf_volume_new_io.argtypes = [ c_void_p,