From ae240f5aa8bff873b89819f483af5d0ae5a6be26 Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Thu, 23 Dec 2021 14:36:48 +0100 Subject: [PATCH] pyocf: test update to handle zeroed metadata in attach With atomic superblock commit during cache attach, it is possible that power failure interrupts attach operation at a point where neither new or old superblock is present - right after the superblock is cleared. Signed-off-by: Adam Rutkowski --- .../test_management_surprise_shutdown.py | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/functional/tests/surprise_shutdown/test_management_surprise_shutdown.py b/tests/functional/tests/surprise_shutdown/test_management_surprise_shutdown.py index a1be98a..19bb053 100644 --- a/tests/functional/tests/surprise_shutdown/test_management_surprise_shutdown.py +++ b/tests/functional/tests/surprise_shutdown/test_management_surprise_shutdown.py @@ -427,14 +427,23 @@ def test_surprise_shutdown_cache_reinit(pyocf_ctx): device.disarm() - cache = Cache.load_from_device(device) + cache = None + status = OcfErrorCode.OCF_OK + try: + cache = Cache.load_from_device(device) + except OcfError as ex: + status = ex.error_code - stats = cache.get_stats() - if stats["conf"]["core_count"] == 0: - cache.add_core(core) - assert ocf_read(cache, core, io_offset) == Volume.VOLUME_POISON + if not cache: + assert status == OcfErrorCode.OCF_ERR_NO_METADATA + else: + stats = cache.get_stats() + if stats["conf"]["core_count"] == 0: + assert stats["usage"]["occupancy"]["value"] == 0 + cache.add_core(core) + assert ocf_read(cache, core, io_offset) == Volume.VOLUME_POISON - cache.stop() + cache.stop() error_io[IoDir.WRITE] += 1