tests: Fix d2c test
Cache attach operation is not supposed to complete unless all the d2c requests are completed, thus need to handle it asynchronously. Signed-off-by: Robert Baldyga <robert.baldyga@huawei.com>
This commit is contained in:
@@ -569,7 +569,7 @@ class Cache:
|
||||
def free_device_config(self, cfg):
|
||||
lib = OcfLib.getInstance().ocf_volume_destroy(cfg._volume)
|
||||
|
||||
def attach_device(
|
||||
def attach_device_async(
|
||||
self,
|
||||
device,
|
||||
force=False,
|
||||
@@ -593,15 +593,40 @@ class Cache:
|
||||
|
||||
self.write_lock()
|
||||
|
||||
c = OcfCompletion([("cache", c_void_p), ("priv", c_void_p), ("error", c_int)])
|
||||
def callback(c):
|
||||
self.write_unlock()
|
||||
self.free_device_config(device_config)
|
||||
|
||||
c = OcfCompletion(
|
||||
[("cache", c_void_p), ("priv", c_void_p), ("error", c_int)],
|
||||
callback=callback
|
||||
)
|
||||
|
||||
self.owner.lib.ocf_mngt_cache_attach(self.cache_handle, byref(attach_cfg), c, None)
|
||||
|
||||
return c
|
||||
|
||||
def attach_device(
|
||||
self,
|
||||
device,
|
||||
force=False,
|
||||
perform_test=False,
|
||||
cache_line_size=None,
|
||||
open_cores=False,
|
||||
disable_cleaner=False,
|
||||
):
|
||||
|
||||
c = self.attach_device_async(
|
||||
device,
|
||||
force,
|
||||
perform_test,
|
||||
cache_line_size,
|
||||
open_cores,
|
||||
disable_cleaner
|
||||
)
|
||||
|
||||
c.wait()
|
||||
|
||||
self.write_unlock()
|
||||
|
||||
self.free_device_config(device_config)
|
||||
|
||||
if c.results["error"]:
|
||||
raise OcfError(
|
||||
f"Attaching cache device failed",
|
||||
|
@@ -83,7 +83,7 @@ class OcfCompletion:
|
||||
except KeyError:
|
||||
raise KeyError(f"No completion argument {key} specified")
|
||||
|
||||
def __init__(self, completion_args: list, context=None):
|
||||
def __init__(self, completion_args: list, context=None, callback=None):
|
||||
"""
|
||||
Provide ctypes arg list, and optionally index of status argument in
|
||||
completion function which will be extracted (default - last argument).
|
||||
@@ -95,6 +95,7 @@ class OcfCompletion:
|
||||
self.results = OcfCompletion.CompletionResult(completion_args)
|
||||
self._as_parameter_ = self.callback
|
||||
self.context = context
|
||||
self.user_callback = callback
|
||||
|
||||
@property
|
||||
def callback(self):
|
||||
@@ -102,6 +103,8 @@ class OcfCompletion:
|
||||
def complete(*args):
|
||||
self.results.results = args
|
||||
self.e.set()
|
||||
if self.user_callback:
|
||||
self.user_callback(self)
|
||||
|
||||
return complete
|
||||
|
||||
|
Reference in New Issue
Block a user