Added cache mode change in pyocf and basic test

This commit is contained in:
Kamil Lepek 2019-04-09 15:43:57 +02:00
parent f9c22262fb
commit 5ceb69e9c8
2 changed files with 34 additions and 0 deletions

View File

@ -160,6 +160,11 @@ class Cache:
if status: if status:
raise OcfError("Error setting management queue", status) raise OcfError("Error setting management queue", status)
def change_cache_mode(self, cache_mode: CacheMode):
self.get_and_write_lock()
self.owner.lib.ocf_mngt_cache_set_mode(self.cache_handle, cache_mode)
self.put_and_write_unlock()
def configure_device( def configure_device(
self, device, force=False, perform_test=False, cache_line_size=None self, device, force=False, perform_test=False, cache_line_size=None
): ):

View File

@ -0,0 +1,29 @@
#
# Copyright(c) 2019 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause-Clear
#
import pytest
from pyocf.types.cache import Cache, CacheMode
from pyocf.types.volume import Volume
from pyocf.utils import Size as S
from pyocf.types.shared import CacheLineSize
@pytest.mark.parametrize("from_cm", CacheMode)
@pytest.mark.parametrize("to_cm", CacheMode)
@pytest.mark.parametrize("cls", CacheLineSize)
def test_change_cache_mode(pyocf_ctx, from_cm, to_cm, cls):
# Start cache device
cache_device = Volume(S.from_MiB(100))
cache = Cache.start_on_device(cache_device, cache_mode=from_cm, cache_line_size=cls)
# Check if started with correct cache mode
stats = cache.get_stats()
assert stats["conf"]["cache_mode"] == from_cm
# Change cache mode and check if stats are as expected
cache.change_cache_mode(to_cm)
stats_after = cache.get_stats()
assert stats_after["conf"]["cache_mode"] == to_cm