From 9739a442b6f17383e11d135fe37a75e9a498e11d Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Mon, 30 May 2022 13:41:07 +0200 Subject: [PATCH] [pyocf] properly resolve volume type OCF volume type is different for each context in which given type (Volume subclass) is registered. So OCF volume type should not be a Volume subclass member. Adding map in Context class to store OCF volume type for each registered volume type. Signed-off-by: Adam Rutkowski --- tests/functional/pyocf/types/cache.py | 15 +++++++-------- tests/functional/pyocf/types/ctx.py | 4 +++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/functional/pyocf/types/cache.py b/tests/functional/pyocf/types/cache.py index 7592c29..307c68d 100644 --- a/tests/functional/pyocf/types/cache.py +++ b/tests/functional/pyocf/types/cache.py @@ -256,7 +256,7 @@ class Cache: raise OcfError("Failed to detach failover cache device", c.results["error"]) def standby_activate(self, device, open_cores=True): - device_cfg = Cache.generate_device_config(device) + device_cfg = self.generate_device_config(device) activate_cfg = CacheStandbyActivateConfig(_device=device_cfg, _open_cores=open_cores,) @@ -456,8 +456,7 @@ class Cache: if status: raise OcfError("Error adding partition to cache", status) - @staticmethod - def generate_device_config(device, perform_test=True): + def generate_device_config(self, device, perform_test=True): uuid = Uuid( _data=cast(create_string_buffer(device.uuid.encode("ascii")), c_char_p), _size=len(device.uuid) + 1, @@ -467,7 +466,7 @@ class Cache: lib = OcfLib.getInstance() result = lib.ocf_volume_create( byref(volume), - device.type, + self.owner.ocf_volume_type[type(device)], byref(uuid) ) if result != 0: @@ -487,7 +486,7 @@ class Cache: self.device = device self.device_name = device.uuid - device_config = Cache.generate_device_config(device, perform_test=perform_test) + device_config = self.generate_device_config(device, perform_test=perform_test) attach_cfg = CacheAttachConfig( _device=device_config, @@ -515,7 +514,7 @@ class Cache: self.device = device self.device_name = device.uuid - device_config = Cache.generate_device_config(device, perform_test=False) + device_config = self.generate_device_config(device, perform_test=False) attach_cfg = CacheAttachConfig( _device=device_config, @@ -543,7 +542,7 @@ class Cache: self.device = device self.device_name = device.uuid - device_config = Cache.generate_device_config(device, perform_test=perform_test) + device_config = self.generate_device_config(device, perform_test=perform_test) attach_cfg = CacheAttachConfig( _device=device_config, @@ -580,7 +579,7 @@ class Cache: self.device = device self.device_name = device.uuid - device_config = Cache.generate_device_config(device) + device_config = self.generate_device_config(device) attach_cfg = CacheAttachConfig( _device=device_config, diff --git a/tests/functional/pyocf/types/ctx.py b/tests/functional/pyocf/types/ctx.py index b9b4fda..dc3934f 100644 --- a/tests/functional/pyocf/types/ctx.py +++ b/tests/functional/pyocf/types/ctx.py @@ -37,6 +37,7 @@ class OcfCtx: self.lib = lib self.volume_types_count = 1 self.volume_types = {} + self.ocf_volume_type = {} self.caches = [] self.cfg = OcfCtxCfg( @@ -77,7 +78,7 @@ class OcfCtx: if result != 0: raise OcfError("Volume type registration failed", result) - volume_type.type = self.lib.ocf_ctx_get_volume_type( + self.ocf_volume_type[volume_type] = self.lib.ocf_ctx_get_volume_type( self.ctx_handle, volume_type.type_id ) @@ -91,6 +92,7 @@ class OcfCtx: self.lib.ocf_ctx_unregister_volume_type(self.ctx_handle, vol_type.type_id) del self.volume_types[vol_type.type_id] + del self.ocf_volume_type[vol_type] def cleanup_volume_types(self): for k, vol_type in list(self.volume_types.items()):