Merge pull request #736 from pdebski21/tests_disable_cleaner2
Tests disable cleaner
This commit is contained in:
commit
9a22ef0917
@ -248,7 +248,10 @@ class Cache:
|
|||||||
self.cores = []
|
self.cores = []
|
||||||
|
|
||||||
def start_cache(
|
def start_cache(
|
||||||
self, init_mngmt_queue=True, init_default_io_queue=True, locked: bool = False,
|
self,
|
||||||
|
init_mngmt_queue=True,
|
||||||
|
init_default_io_queue=True,
|
||||||
|
locked: bool = False,
|
||||||
):
|
):
|
||||||
cfg = CacheConfig(
|
cfg = CacheConfig(
|
||||||
_name=self.name.encode("ascii"),
|
_name=self.name.encode("ascii"),
|
||||||
@ -257,7 +260,8 @@ class Cache:
|
|||||||
_cache_line_size=self.cache_line_size,
|
_cache_line_size=self.cache_line_size,
|
||||||
_metadata_volatile=self.metadata_volatile,
|
_metadata_volatile=self.metadata_volatile,
|
||||||
_backfill=Backfill(
|
_backfill=Backfill(
|
||||||
_max_queue_size=self.max_queue_size, _queue_unblock_size=self.queue_unblock_size,
|
_max_queue_size=self.max_queue_size,
|
||||||
|
_queue_unblock_size=self.queue_unblock_size,
|
||||||
),
|
),
|
||||||
_locked=locked,
|
_locked=locked,
|
||||||
_pt_unaligned_io=self.pt_unaligned_io,
|
_pt_unaligned_io=self.pt_unaligned_io,
|
||||||
@ -301,7 +305,10 @@ class Cache:
|
|||||||
def standby_activate(self, device, open_cores=True):
|
def standby_activate(self, device, open_cores=True):
|
||||||
device_cfg = self.alloc_device_config(device)
|
device_cfg = self.alloc_device_config(device)
|
||||||
|
|
||||||
activate_cfg = CacheStandbyActivateConfig(_device=device_cfg, _open_cores=open_cores,)
|
activate_cfg = CacheStandbyActivateConfig(
|
||||||
|
_device=device_cfg,
|
||||||
|
_open_cores=open_cores,
|
||||||
|
)
|
||||||
|
|
||||||
self.write_lock()
|
self.write_lock()
|
||||||
c = OcfCompletion([("cache", c_void_p), ("priv", c_void_p), ("error", c_int)])
|
c = OcfCompletion([("cache", c_void_p), ("priv", c_void_p), ("error", c_int)])
|
||||||
@ -446,7 +453,13 @@ class Cache:
|
|||||||
}
|
}
|
||||||
|
|
||||||
def add_partition(
|
def add_partition(
|
||||||
self, part_id: int, name: str, min_size: int, max_size: int, priority: int, valid: bool,
|
self,
|
||||||
|
part_id: int,
|
||||||
|
name: str,
|
||||||
|
min_size: int,
|
||||||
|
max_size: int,
|
||||||
|
priority: int,
|
||||||
|
valid: bool,
|
||||||
):
|
):
|
||||||
self.write_lock()
|
self.write_lock()
|
||||||
|
|
||||||
@ -462,7 +475,12 @@ class Cache:
|
|||||||
raise OcfError("Error adding partition to cache", status)
|
raise OcfError("Error adding partition to cache", status)
|
||||||
|
|
||||||
def configure_partition(
|
def configure_partition(
|
||||||
self, part_id: int, name: str, max_size: int, priority: int, cache_mode=CACHE_MODE_NONE,
|
self,
|
||||||
|
part_id: int,
|
||||||
|
name: str,
|
||||||
|
max_size: int,
|
||||||
|
priority: int,
|
||||||
|
cache_mode=CACHE_MODE_NONE,
|
||||||
):
|
):
|
||||||
ioclasses_info = IoClassesInfo()
|
ioclasses_info = IoClassesInfo()
|
||||||
|
|
||||||
@ -511,9 +529,7 @@ class Cache:
|
|||||||
|
|
||||||
lib = OcfLib.getInstance()
|
lib = OcfLib.getInstance()
|
||||||
result = lib.ocf_volume_create(
|
result = lib.ocf_volume_create(
|
||||||
byref(volume),
|
byref(volume), self.owner.ocf_volume_type[type(device)], byref(uuid)
|
||||||
self.owner.ocf_volume_type[type(device)],
|
|
||||||
byref(uuid)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if result != 0:
|
if result != 0:
|
||||||
@ -533,7 +549,13 @@ class Cache:
|
|||||||
lib = OcfLib.getInstance().ocf_volume_destroy(cfg._volume)
|
lib = OcfLib.getInstance().ocf_volume_destroy(cfg._volume)
|
||||||
|
|
||||||
def attach_device(
|
def attach_device(
|
||||||
self, device, force=False, perform_test=False, cache_line_size=None, open_cores=False,
|
self,
|
||||||
|
device,
|
||||||
|
force=False,
|
||||||
|
perform_test=False,
|
||||||
|
cache_line_size=None,
|
||||||
|
open_cores=False,
|
||||||
|
disable_cleaner=False,
|
||||||
):
|
):
|
||||||
self.device = device
|
self.device = device
|
||||||
self.device_name = device.uuid
|
self.device_name = device.uuid
|
||||||
@ -546,6 +568,7 @@ class Cache:
|
|||||||
_open_cores=open_cores,
|
_open_cores=open_cores,
|
||||||
_force=force,
|
_force=force,
|
||||||
_discard_on_start=False,
|
_discard_on_start=False,
|
||||||
|
_disable_cleaner=disable_cleaner,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.write_lock()
|
self.write_lock()
|
||||||
@ -561,10 +584,11 @@ class Cache:
|
|||||||
|
|
||||||
if c.results["error"]:
|
if c.results["error"]:
|
||||||
raise OcfError(
|
raise OcfError(
|
||||||
f"Attaching cache device failed", c.results["error"],
|
f"Attaching cache device failed",
|
||||||
|
c.results["error"],
|
||||||
)
|
)
|
||||||
|
|
||||||
def standby_attach(self, device, force=False):
|
def standby_attach(self, device, force=False, disable_cleaner=False):
|
||||||
self.device = device
|
self.device = device
|
||||||
self.device_name = device.uuid
|
self.device_name = device.uuid
|
||||||
|
|
||||||
@ -576,6 +600,7 @@ class Cache:
|
|||||||
_open_cores=False,
|
_open_cores=False,
|
||||||
_force=force,
|
_force=force,
|
||||||
_discard_on_start=False,
|
_discard_on_start=False,
|
||||||
|
_disable_cleaner=disable_cleaner,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.write_lock()
|
self.write_lock()
|
||||||
@ -591,10 +616,11 @@ class Cache:
|
|||||||
|
|
||||||
if c.results["error"]:
|
if c.results["error"]:
|
||||||
raise OcfError(
|
raise OcfError(
|
||||||
f"Attaching to standby cache failed", c.results["error"],
|
f"Attaching to standby cache failed",
|
||||||
|
c.results["error"],
|
||||||
)
|
)
|
||||||
|
|
||||||
def standby_load(self, device, perform_test=True):
|
def standby_load(self, device, perform_test=True, disable_cleaner=False):
|
||||||
self.device = device
|
self.device = device
|
||||||
self.device_name = device.uuid
|
self.device_name = device.uuid
|
||||||
|
|
||||||
@ -606,6 +632,7 @@ class Cache:
|
|||||||
_open_cores=False,
|
_open_cores=False,
|
||||||
_force=False,
|
_force=False,
|
||||||
_discard_on_start=False,
|
_discard_on_start=False,
|
||||||
|
_disable_cleaner=disable_cleaner,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.write_lock()
|
self.write_lock()
|
||||||
@ -633,7 +660,7 @@ class Cache:
|
|||||||
if c.results["error"]:
|
if c.results["error"]:
|
||||||
raise OcfError("Attaching cache device failed", c.results["error"])
|
raise OcfError("Attaching cache device failed", c.results["error"])
|
||||||
|
|
||||||
def load_cache(self, device, open_cores=True):
|
def load_cache(self, device, open_cores=True, disable_cleaner=False):
|
||||||
self.device = device
|
self.device = device
|
||||||
self.device_name = device.uuid
|
self.device_name = device.uuid
|
||||||
|
|
||||||
@ -645,6 +672,7 @@ class Cache:
|
|||||||
_open_cores=open_cores,
|
_open_cores=open_cores,
|
||||||
_force=False,
|
_force=False,
|
||||||
_discard_on_start=False,
|
_discard_on_start=False,
|
||||||
|
_disable_cleaner=disable_cleaner,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.write_lock()
|
self.write_lock()
|
||||||
@ -659,7 +687,9 @@ class Cache:
|
|||||||
raise OcfError("Loading cache device failed", c.results["error"])
|
raise OcfError("Loading cache device failed", c.results["error"])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load_from_device(cls, device, owner=None, name="cache", open_cores=True):
|
def load_from_device(
|
||||||
|
cls, device, owner=None, name="cache", open_cores=True, disable_cleaner=False
|
||||||
|
):
|
||||||
if owner is None:
|
if owner is None:
|
||||||
owner = OcfCtx.get_default()
|
owner = OcfCtx.get_default()
|
||||||
|
|
||||||
@ -667,7 +697,7 @@ class Cache:
|
|||||||
|
|
||||||
c.start_cache()
|
c.start_cache()
|
||||||
try:
|
try:
|
||||||
c.load_cache(device, open_cores=open_cores)
|
c.load_cache(device, open_cores=open_cores, disable_cleaner=disable_cleaner)
|
||||||
except: # noqa E722
|
except: # noqa E722
|
||||||
c.stop()
|
c.stop()
|
||||||
raise
|
raise
|
||||||
@ -675,7 +705,7 @@ class Cache:
|
|||||||
return c
|
return c
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def start_on_device(cls, device, owner=None, **kwargs):
|
def start_on_device(cls, device, owner=None, disable_cleaner=False, **kwargs):
|
||||||
if owner is None:
|
if owner is None:
|
||||||
owner = OcfCtx.get_default()
|
owner = OcfCtx.get_default()
|
||||||
|
|
||||||
@ -683,7 +713,7 @@ class Cache:
|
|||||||
|
|
||||||
c.start_cache()
|
c.start_cache()
|
||||||
try:
|
try:
|
||||||
c.attach_device(device, force=True)
|
c.attach_device(device, force=True, disable_cleaner=disable_cleaner)
|
||||||
except: # noqa E722
|
except: # noqa E722
|
||||||
c.stop()
|
c.stop()
|
||||||
raise
|
raise
|
||||||
@ -722,7 +752,10 @@ class Cache:
|
|||||||
core_handle = c_void_p()
|
core_handle = c_void_p()
|
||||||
|
|
||||||
result = self.owner.lib.ocf_core_get_by_name(
|
result = self.owner.lib.ocf_core_get_by_name(
|
||||||
self.cache_handle, name.encode("ascii"), len(name), byref(core_handle),
|
self.cache_handle,
|
||||||
|
name.encode("ascii"),
|
||||||
|
len(name),
|
||||||
|
byref(core_handle),
|
||||||
)
|
)
|
||||||
if result != 0:
|
if result != 0:
|
||||||
raise OcfError("Failed getting core by name", result)
|
raise OcfError("Failed getting core by name", result)
|
||||||
@ -744,7 +777,12 @@ class Cache:
|
|||||||
self.write_lock()
|
self.write_lock()
|
||||||
|
|
||||||
c = OcfCompletion(
|
c = OcfCompletion(
|
||||||
[("cache", c_void_p), ("core", c_void_p), ("priv", c_void_p), ("error", c_int),]
|
[
|
||||||
|
("cache", c_void_p),
|
||||||
|
("core", c_void_p),
|
||||||
|
("priv", c_void_p),
|
||||||
|
("error", c_int),
|
||||||
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
self.owner.lib.ocf_mngt_cache_add_core(self.cache_handle, byref(cfg), c, None)
|
self.owner.lib.ocf_mngt_cache_add_core(self.cache_handle, byref(cfg), c, None)
|
||||||
@ -939,6 +977,17 @@ class Cache:
|
|||||||
def settle(self):
|
def settle(self):
|
||||||
Queue.settle_many(self.io_queues + [self.mngt_queue])
|
Queue.settle_many(self.io_queues + [self.mngt_queue])
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_by_name(cache_name, owner=None):
|
||||||
|
if owner is None:
|
||||||
|
owner = OcfCtx.get_default()
|
||||||
|
cache_pointer = c_void_p()
|
||||||
|
return OcfLib.getInstance().ocf_mngt_cache_get_by_name(
|
||||||
|
owner.ctx_handle, cache_name, byref(cache_pointer)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
lib = OcfLib.getInstance()
|
lib = OcfLib.getInstance()
|
||||||
lib.ocf_mngt_cache_remove_core.argtypes = [c_void_p, c_void_p, c_void_p]
|
lib.ocf_mngt_cache_remove_core.argtypes = [c_void_p, c_void_p, c_void_p]
|
||||||
|
@ -4,9 +4,14 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from pyocf.types.volume import RamVolume
|
||||||
|
from pyocf.types.cache import Cache, CacheMetadataSegment
|
||||||
|
from pyocf.types.core import Core
|
||||||
|
from pyocf.types.shared import OcfError, OcfCompletion
|
||||||
|
from pyocf.utils import Size as S
|
||||||
|
from pyocf.helpers import get_metadata_segment_size
|
||||||
|
from ctypes import c_int
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip(reason="not implemented")
|
|
||||||
def test_attach_cleaner_disabled(pyocf_ctx):
|
def test_attach_cleaner_disabled(pyocf_ctx):
|
||||||
"""
|
"""
|
||||||
title: Attach cache with cleaner_disabled option set.
|
title: Attach cache with cleaner_disabled option set.
|
||||||
@ -29,10 +34,24 @@ def test_attach_cleaner_disabled(pyocf_ctx):
|
|||||||
- disable_cleaner::set_cleaner_disabled
|
- disable_cleaner::set_cleaner_disabled
|
||||||
- disable_cleaner::cleaning_section_alocation
|
- disable_cleaner::cleaning_section_alocation
|
||||||
"""
|
"""
|
||||||
pass
|
cache_device = RamVolume(S.from_MiB(50))
|
||||||
|
core_device = RamVolume(S.from_MiB(10))
|
||||||
|
|
||||||
|
cache = Cache.start_on_device(cache_device, disable_cleaner=True)
|
||||||
|
core = Core.using_device(core_device)
|
||||||
|
|
||||||
|
stats = cache.get_stats()
|
||||||
|
assert stats["conf"]["attached"] is True, "checking whether cache is attached properly"
|
||||||
|
|
||||||
|
cleaning_size = get_metadata_segment_size(cache, CacheMetadataSegment.CLEANING)
|
||||||
|
assert (
|
||||||
|
cleaning_size == 0
|
||||||
|
), f'Metadata cleaning segment size expected: "0", got: "{cleaning_size}"'
|
||||||
|
|
||||||
|
cache.stop()
|
||||||
|
assert Cache.get_by_name("cache1", pyocf_ctx) != 0, "Try getting cache after stopping it"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip(reason="not implemented")
|
|
||||||
def test_load_cleaner_disabled(pyocf_ctx):
|
def test_load_cleaner_disabled(pyocf_ctx):
|
||||||
"""
|
"""
|
||||||
title: Load cache in cleaner_disabled mode.
|
title: Load cache in cleaner_disabled mode.
|
||||||
@ -57,7 +76,31 @@ def test_load_cleaner_disabled(pyocf_ctx):
|
|||||||
- disable_cleaner::load_cleaner_disabled
|
- disable_cleaner::load_cleaner_disabled
|
||||||
- disable_cleaner::cleaning_section_alocation
|
- disable_cleaner::cleaning_section_alocation
|
||||||
"""
|
"""
|
||||||
pass
|
cache_device = RamVolume(S.from_MiB(50))
|
||||||
|
core_device = RamVolume(S.from_MiB(10))
|
||||||
|
|
||||||
|
cache = Cache.start_on_device(cache_device, disable_cleaner=True)
|
||||||
|
core = Core.using_device(core_device)
|
||||||
|
|
||||||
|
cache.add_core(core)
|
||||||
|
|
||||||
|
cache.stop()
|
||||||
|
|
||||||
|
cache = Cache.load_from_device(cache_device, open_cores=False, disable_cleaner=True)
|
||||||
|
|
||||||
|
cache.add_core(core, try_add=True)
|
||||||
|
|
||||||
|
stats = cache.get_stats()
|
||||||
|
assert stats["conf"]["attached"] is True, "checking whether cache is attached properly"
|
||||||
|
|
||||||
|
cleaning_size = get_metadata_segment_size(cache, CacheMetadataSegment.CLEANING)
|
||||||
|
assert (
|
||||||
|
cleaning_size == 0
|
||||||
|
), f'Metadata cleaning segment size expected: "0", got: "{cleaning_size}"'
|
||||||
|
|
||||||
|
cache.stop()
|
||||||
|
assert Cache.get_by_name("cache1", pyocf_ctx) != 0, "Try getting cache after stopping it"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip(reason="not implemented")
|
@pytest.mark.skip(reason="not implemented")
|
||||||
|
@ -265,7 +265,7 @@ def test_start_stop_multiple(pyocf_ctx):
|
|||||||
stats = cache.get_stats()
|
stats = cache.get_stats()
|
||||||
cache_name = stats["conf"]["cache_name"]
|
cache_name = stats["conf"]["cache_name"]
|
||||||
cache.stop()
|
cache.stop()
|
||||||
assert get_cache_by_name(pyocf_ctx, cache_name) != 0, "Try getting cache after stopping it"
|
assert Cache.get_by_name(cache_name, pyocf_ctx) != 0, "Try getting cache after stopping it"
|
||||||
|
|
||||||
|
|
||||||
def test_100_start_stop(pyocf_ctx):
|
def test_100_start_stop(pyocf_ctx):
|
||||||
@ -288,7 +288,7 @@ def test_100_start_stop(pyocf_ctx):
|
|||||||
assert stats["conf"]["cache_line_size"] == cache_line_size, "Cache line size"
|
assert stats["conf"]["cache_line_size"] == cache_line_size, "Cache line size"
|
||||||
assert stats["conf"]["cache_name"] == cache_name, "Cache name"
|
assert stats["conf"]["cache_name"] == cache_name, "Cache name"
|
||||||
cache.stop()
|
cache.stop()
|
||||||
assert get_cache_by_name(pyocf_ctx, "cache1") != 0, "Try getting cache after stopping it"
|
assert Cache.get_by_name("cache1", pyocf_ctx) != 0, "Try getting cache after stopping it"
|
||||||
|
|
||||||
|
|
||||||
def test_start_stop_incrementally(pyocf_ctx):
|
def test_start_stop_incrementally(pyocf_ctx):
|
||||||
@ -337,7 +337,7 @@ def test_start_stop_incrementally(pyocf_ctx):
|
|||||||
cache_name = stats["conf"]["cache_name"]
|
cache_name = stats["conf"]["cache_name"]
|
||||||
cache.stop()
|
cache.stop()
|
||||||
assert (
|
assert (
|
||||||
get_cache_by_name(pyocf_ctx, cache_name) != 0
|
Cache.get_by_name(cache_name, pyocf_ctx) != 0
|
||||||
), "Try getting cache after stopping it"
|
), "Try getting cache after stopping it"
|
||||||
add = not add
|
add = not add
|
||||||
|
|
||||||
@ -648,9 +648,3 @@ def check_md5_sums(core: Core, mode: CacheMode):
|
|||||||
core.device.md5() == core.get_front_volume().md5()
|
core.device.md5() == core.get_front_volume().md5()
|
||||||
), "MD5 check: core device vs exported object"
|
), "MD5 check: core device vs exported object"
|
||||||
|
|
||||||
|
|
||||||
def get_cache_by_name(ctx, cache_name):
|
|
||||||
cache_pointer = c_void_p()
|
|
||||||
return OcfLib.getInstance().ocf_mngt_cache_get_by_name(
|
|
||||||
ctx.ctx_handle, cache_name, byref(cache_pointer)
|
|
||||||
)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user