From 01166ba55ea0d29011acb06158e0fa15e07c9e95 Mon Sep 17 00:00:00 2001 From: Jan Musial Date: Tue, 29 Mar 2022 09:05:27 +0200 Subject: [PATCH] Security test for cache exported object Signed-off-by: Jan Musial --- .../tests/security/test_failover_security.py | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 tests/functional/tests/security/test_failover_security.py diff --git a/tests/functional/tests/security/test_failover_security.py b/tests/functional/tests/security/test_failover_security.py new file mode 100644 index 0000000..12722a8 --- /dev/null +++ b/tests/functional/tests/security/test_failover_security.py @@ -0,0 +1,80 @@ +# +# Copyright(c) 2022 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause +# + +import pytest +import logging +from datetime import datetime + +from pyocf.types.volume_cache import CacheVolume +from pyocf.types.volume import RamVolume +from pyocf.types.cache import Cache, CacheMetadataSegment, CacheMode +from pyocf.utils import Size +from pyocf.types.shared import CacheLineSize, OcfError, OcfErrorCode +from pyocf.types.ctx import OcfCtx +from pyocf.rio import Rio, ReadWrite +from pyocf.helpers import get_metadata_segment_size, get_metadata_segment_page_location +from tests.utils.random import RandomGenerator + +logger = logging.getLogger(__name__) + + +@pytest.mark.security +@pytest.mark.parametrize("cache_line_size", CacheLineSize) +@pytest.mark.parametrize( + "bs", + [ + Size.from_B(512), + Size.from_KiB(1), + Size.from_KiB(18), + Size.from_KiB(128), + ], +) +@pytest.mark.parametrize( + "io_size", + [ + Size.from_B(512), + Size.from_KiB(10), + Size.from_MiB(1), + Size.from_MiB(10), + Size.from_GiB(1), + ], +) +@pytest.mark.parametrize("section", CacheMetadataSegment) +def test_garbage_on_cache_exported_object(pyocf_ctx, cache_line_size, bs, io_size, section): + num_jobs = 1 + qd = 64 + + vol_size = Size.from_MiB(100) + cache_vol = RamVolume(vol_size) + secondary_cache_volume = RamVolume(vol_size) + + cache = Cache(owner=OcfCtx.get_default(), cache_line_size=cache_line_size) + + cache.start_cache(init_default_io_queue=False) + + for i in range(num_jobs): + cache.add_io_queue(f"io-queue-{i}") + + cache.standby_attach(cache_vol) + + cache_exp_vol = CacheVolume(cache) + + seed = next(RandomGenerator()) + r = ( + Rio() + .target(cache_exp_vol) + .njobs(num_jobs) + .readwrite(ReadWrite.RANDWRITE) + .io_size(io_size) + .randseed(seed) + .bs(bs) + .qd(qd) + .norandommap() + .run(cache.io_queues) + ) + + cache.standby_detach() + with pytest.raises(OcfError): + cache.standby_activate(secondary_cache_volume, open_cores=False)