Merge pull request #302 from Deixx/empty-cache-name

Recognize empty string as an incorrect cache name
This commit is contained in:
Michał Mielewczyk 2019-10-01 13:19:20 +02:00 committed by GitHub
commit e02821d399
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,14 +3,15 @@
# SPDX-License-Identifier: BSD-3-Clause-Clear # SPDX-License-Identifier: BSD-3-Clause-Clear
# #
import pytest
import logging import logging
from tests.utils.random import RandomGenerator, DefaultRanges
import pytest
from pyocf.types.cache import Cache, CacheMode, EvictionPolicy, MetadataLayout, PromotionPolicy from pyocf.types.cache import Cache, CacheMode, EvictionPolicy, MetadataLayout, PromotionPolicy
from pyocf.types.shared import OcfError, CacheLineSize
from pyocf.types.volume import Volume from pyocf.types.volume import Volume
from pyocf.utils import Size from pyocf.utils import Size
from pyocf.types.shared import OcfError, CacheLineSize from tests.utils.random import RandomGenerator, DefaultRanges
from ctypes import c_uint32
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -66,11 +67,17 @@ def test_fuzzy_start_name(pyocf_ctx, string_randomize, cm, cls):
:param cls: cache line size value to start cache with :param cls: cache line size value to start cache with
""" """
cache_device = Volume(Size.from_MiB(30)) cache_device = Volume(Size.from_MiB(30))
incorrect_values = ['']
try: try:
cache = Cache.start_on_device(cache_device, name=string_randomize, cache_mode=cm, cache = Cache.start_on_device(cache_device, name=string_randomize, cache_mode=cm,
cache_line_size=cls) cache_line_size=cls)
except OcfError: except OcfError:
logger.error(f"Cache did not start properly with correct name value: {string_randomize}") if string_randomize not in incorrect_values:
logger.error(
f"Cache did not start properly with correct name value: '{string_randomize}'")
return
if string_randomize in incorrect_values:
logger.error(f"Cache started with incorrect name value: '{string_randomize}'")
cache.stop() cache.stop()