pyocf: Make cache lookup by name a common utility

Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
Robert Baldyga 2022-06-20 17:01:43 +02:00 committed by Piotr Debski
parent 5441cdb50a
commit ef4bfc9ac3
2 changed files with 13 additions and 9 deletions

View File

@ -977,6 +977,16 @@ 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()

View File

@ -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)
)