From 1fa52e84a8485eb0f2f2763faaff2223999d8447 Mon Sep 17 00:00:00 2001 From: Daniel Madej Date: Thu, 4 Apr 2019 10:45:25 +0200 Subject: [PATCH] Extract cache.flush() method from cache.stop() Signed-off-by: Daniel Madej --- tests/functional/pyocf/types/cache.py | 28 +++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/tests/functional/pyocf/types/cache.py b/tests/functional/pyocf/types/cache.py index c9ee5e8..b52f801 100644 --- a/tests/functional/pyocf/types/cache.py +++ b/tests/functional/pyocf/types/cache.py @@ -386,17 +386,10 @@ class Cache: return self.io_queues[0] def stop(self, flush: bool = True): - self.get_and_write_lock() - if flush: - c = OcfCompletion( - [("cache", c_void_p), ("priv", c_void_p), ("error", c_int)] - ) - self.owner.lib.ocf_mngt_cache_flush(self.cache_handle, False, c, None) - c.wait() - if c.results["error"]: - self.put_and_write_unlock() - raise OcfError("Couldn't flush cache", c.results["error"]) + self.flush() + + self.get_and_write_lock() c = OcfCompletion( [("cache", c_void_p), ("priv", c_void_p), ("error", c_int)] @@ -412,6 +405,21 @@ class Cache: self.put_and_write_unlock() self.owner.caches.remove(self) + def flush(self): + self.get_and_write_lock() + + c = OcfCompletion( + [("cache", c_void_p), ("priv", c_void_p), ("error", c_int)] + ) + self.owner.lib.ocf_mngt_cache_flush(self.cache_handle, False, c, None) + c.wait() + if c.results["error"]: + self.put_and_write_unlock() + raise OcfError("Couldn't flush cache", c.results["error"]) + + self.put_and_write_unlock() + + lib = OcfLib.getInstance() lib.ocf_mngt_cache_remove_core.argtypes = [c_void_p, c_void_p, c_void_p] lib.ocf_mngt_cache_add_core.argtypes = [c_void_p, c_void_p, c_void_p, c_void_p]