Enable all commented out tests

The first attempt at getting all the tests to work missed out the
config_overrides in the base test class and the 'role' and
'assignment' groups.

Also, sha1_mangle_key was added to encode the key before calling
dogpile's sha1_mangle_key to support all the python34 tests.

Removed the skipIf's added for py34 as the tests are now working.
Also removed the testtools from requirements as we don't need it
anymore.

Change-Id: I0e09429e6739dc946f6e15398ccb264b4d62bb42
This commit is contained in:
Davanum Srinivas 2015-06-23 21:50:54 -04:00
parent 25eace34c9
commit 3411d7200f
4 changed files with 119 additions and 90 deletions

View File

@ -92,6 +92,29 @@ FILE_OPTIONS = {
help='Number of seconds that an operation will wait to get ' help='Number of seconds that an operation will wait to get '
'a memcache client connection.'), 'a memcache client connection.'),
], ],
'role': [
# The role driver has no default for backward compatibility reasons.
# If role driver is not specified, the assignment driver chooses
# the backend
cfg.StrOpt('driver',
help='Role backend driver.'),
cfg.BoolOpt('caching', default=True,
help='Toggle for role caching. This has no effect '
'unless global caching is enabled.'),
cfg.IntOpt('cache_time',
help='TTL (in seconds) to cache role data. This has '
'no effect unless global caching is enabled.'),
cfg.IntOpt('list_limit',
help='Maximum number of entities that will be returned '
'in a role collection.'),
],
'assignment': [
# assignment has no default for backward compatibility reasons.
# If assignment driver is not specified, the identity driver chooses
# the backend
cfg.StrOpt('driver',
help='Assignment backend driver.'),
],
} }

View File

@ -23,6 +23,7 @@ from oslo_utils import importutils
from oslo_cache import exception from oslo_cache import exception
from oslo_cache._i18n import _, _LE from oslo_cache._i18n import _, _LE
from oslo_cache import _opts
CONF = cfg.CONF CONF = cfg.CONF
@ -119,6 +120,10 @@ def build_cache_config():
return conf_dict return conf_dict
def sha1_mangle_key(key):
return util.sha1_mangle_key(key.encode('UTF-8'))
def configure_cache_region(region): def configure_cache_region(region):
"""Configure a cache region. """Configure a cache region.
@ -149,7 +154,7 @@ def configure_cache_region(region):
# mangler provided by dogpile.cache. This ensures we always use a fixed # mangler provided by dogpile.cache. This ensures we always use a fixed
# size cache-key. # size cache-key.
if region.key_mangler is None: if region.key_mangler is None:
region.key_mangler = util.sha1_mangle_key region.key_mangler = sha1_mangle_key
for class_path in CONF.cache.proxies: for class_path in CONF.cache.proxies:
# NOTE(morganfainberg): if we have any proxy wrappers, we should # NOTE(morganfainberg): if we have any proxy wrappers, we should
@ -306,3 +311,7 @@ def get_memoization_decorator(section, expiration_section=None):
memoize.get_expiration_time = expiration_time memoize.get_expiration_time = expiration_time
return memoize return memoize
def configure(conf):
_opts.configure(conf)

View File

@ -21,8 +21,6 @@ from dogpile.cache import proxy
import mock import mock
from oslo_config import cfg from oslo_config import cfg
from oslotest import base from oslotest import base
import six
import testtools
from oslo_cache import core as cache from oslo_cache import core as cache
from oslo_cache import exception from oslo_cache import exception
@ -42,6 +40,17 @@ class BaseTestCase(base.BaseTestCase):
self.config_fixture = self.useFixture(config_fixture.Config(CONF)) self.config_fixture = self.useFixture(config_fixture.Config(CONF))
self.addCleanup(delattr, self, 'config_fixture') self.addCleanup(delattr, self, 'config_fixture')
self.config_overrides()
def config_overrides(self):
self.config_fixture.config(
# TODO(morganfainberg): Make Cache Testing a separate test case
# in tempest, and move it out of the base unit tests.
group='cache',
backend='dogpile.cache.memory',
enabled=True,
proxies=['oslo_cache.tests.test_cache.CacheIsolatingProxy'])
def _copy_value(value): def _copy_value(value):
if value is not NO_VALUE: if value is not NO_VALUE:
@ -111,13 +120,12 @@ class CacheRegionTest(BaseTestCase):
return cacheable_function return cacheable_function
# FIXME(dims) : Need to resurrect this test ported from keystone def test_region_built_with_proxy_direct_cache_test(self):
# def test_region_built_with_proxy_direct_cache_test(self): # Verify cache regions are properly built with proxies.
# # Verify cache regions are properly built with proxies. test_value = TestProxyValue('Direct Cache Test')
# test_value = TestProxyValue('Direct Cache Test') self.region.set('cache_test', test_value)
# self.region.set('cache_test', test_value) cached_value = self.region.get('cache_test')
# cached_value = self.region.get('cache_test') self.assertTrue(cached_value.cached)
# self.assertTrue(cached_value.cached)
def test_cache_region_no_error_multiple_config(self): def test_cache_region_no_error_multiple_config(self):
# Verify configuring the CacheRegion again doesn't error. # Verify configuring the CacheRegion again doesn't error.
@ -167,48 +175,44 @@ class CacheRegionTest(BaseTestCase):
return _do_test return _do_test
# FIXME(dims) : Need to resurrect this test ported from keystone def test_cache_no_fallthrough_expiration_time_fn(self):
# def test_cache_no_fallthrough_expiration_time_fn(self): # Since we do not re-configure the cache region, for ease of testing
# # Since we do not re-configure the cache region, for ease of testing # this value is set the same as the expiration_time default in the
# # this value is set the same as the expiration_time default in the # [cache] section
# # [cache] section cache_time = 600
# cache_time = 600 expiration_time = cache.get_expiration_time_fn('role')
# expiration_time = cache.get_expiration_time_fn('role') do_test = self._get_cache_fallthrough_fn(cache_time)
# do_test = self._get_cache_fallthrough_fn(cache_time) # Run the test with the assignment cache_time value
# # Run the test with the assignment cache_time value self.config_fixture.config(cache_time=cache_time,
# self.config_fixture.config(cache_time=cache_time, group='role')
# group='role') test_value = TestProxyValue(uuid.uuid4().hex)
# test_value = TestProxyValue(uuid.uuid4().hex) self.assertEqual(cache_time, expiration_time())
# self.assertEqual(cache_time, expiration_time()) do_test(value=test_value)
# do_test(value=test_value)
# FIXME(dims) : Need to resurrect this test ported from keystone def test_cache_fallthrough_expiration_time_fn(self):
# def test_cache_fallthrough_expiration_time_fn(self): # Since we do not re-configure the cache region, for ease of testing
# # Since we do not re-configure the cache region, for ease of testing # this value is set the same as the expiration_time default in the
# # this value is set the same as the expiration_time default in the # [cache] section
# # [cache] section cache_time = 599
# cache_time = 599 expiration_time = cache.get_expiration_time_fn('role')
# expiration_time = cache.get_expiration_time_fn('role') do_test = self._get_cache_fallthrough_fn(cache_time)
# do_test = self._get_cache_fallthrough_fn(cache_time) # Run the test with the assignment cache_time value set to None and
# # Run the test with the assignment cache_time value set to None and # the global value set.
# # the global value set. self.config_fixture.config(cache_time=None, group='role')
# self.config_fixture.config(cache_time=None, group='role') test_value = TestProxyValue(uuid.uuid4().hex)
# test_value = TestProxyValue(uuid.uuid4().hex) self.assertIsNone(expiration_time())
# self.assertIsNone(expiration_time()) do_test(value=test_value)
# do_test(value=test_value)
# FIXME(dims) : Need to resurrect this test ported from keystone def test_should_cache_fn_global_cache_enabled(self):
# def test_should_cache_fn_global_cache_enabled(self): # Verify should_cache_fn generates a sane function for subsystem and
# # Verify should_cache_fn generates a sane function for subsystem and # functions as expected with caching globally enabled.
# # functions as expected with caching globally enabled. cacheable_function = self._get_cacheable_function()
# cacheable_function = self._get_cacheable_function()
# self.config_fixture.config(group='cache', enabled=True)
# self.config_fixture.config(group='cache', enabled=True) cacheable_function(self.test_value)
# cacheable_function(self.test_value) cached_value = cacheable_function(self.test_value)
# cached_value = cacheable_function(self.test_value) self.assertTrue(cached_value.cached)
# self.assertTrue(cached_value.cached)
@testtools.skipIf(six.PY3, 'FIXME: this test does not work python 3.x')
def test_should_cache_fn_global_cache_disabled(self): def test_should_cache_fn_global_cache_disabled(self):
# Verify should_cache_fn generates a sane function for subsystem and # Verify should_cache_fn generates a sane function for subsystem and
# functions as expected with caching globally disabled. # functions as expected with caching globally disabled.
@ -219,7 +223,6 @@ class CacheRegionTest(BaseTestCase):
cached_value = cacheable_function(self.test_value) cached_value = cacheable_function(self.test_value)
self.assertFalse(cached_value.cached) self.assertFalse(cached_value.cached)
@testtools.skipIf(six.PY3, 'FIXME: this test does not work python 3.x')
def test_should_cache_fn_global_cache_disabled_section_cache_enabled(self): def test_should_cache_fn_global_cache_disabled_section_cache_enabled(self):
# Verify should_cache_fn generates a sane function for subsystem and # Verify should_cache_fn generates a sane function for subsystem and
# functions as expected with caching globally disabled and the specific # functions as expected with caching globally disabled and the specific
@ -234,7 +237,6 @@ class CacheRegionTest(BaseTestCase):
cached_value = cacheable_function(self.test_value) cached_value = cacheable_function(self.test_value)
self.assertFalse(cached_value.cached) self.assertFalse(cached_value.cached)
@testtools.skipIf(six.PY3, 'FIXME: this test does not work python 3.x')
def test_should_cache_fn_global_cache_enabled_section_cache_disabled(self): def test_should_cache_fn_global_cache_enabled_section_cache_disabled(self):
# Verify should_cache_fn generates a sane function for subsystem and # Verify should_cache_fn generates a sane function for subsystem and
# functions as expected with caching globally enabled and the specific # functions as expected with caching globally enabled and the specific
@ -249,21 +251,19 @@ class CacheRegionTest(BaseTestCase):
cached_value = cacheable_function(self.test_value) cached_value = cacheable_function(self.test_value)
self.assertFalse(cached_value.cached) self.assertFalse(cached_value.cached)
# FIXME(dims) : Need to resurrect this test ported from keystone def test_should_cache_fn_global_cache_enabled_section_cache_enabled(self):
# def test_should_cache_fn_global_cache_enabled_section_cache_enabled( # Verify should_cache_fn generates a sane function for subsystem and
# self): # functions as expected with caching globally enabled and the specific
# #Verify should_cache_fn generates a sane function for subsystem and # section caching enabled.
# #functions as expected with caching globally enabled and the specific cacheable_function = self._get_cacheable_function()
# #section caching enabled.
# cacheable_function = self._get_cacheable_function() self._add_test_caching_option()
# self.config_fixture.config(group='cache', enabled=True)
# self._add_test_caching_option() self.config_fixture.config(group='cache', caching=True)
# self.config_fixture.config(group='cache', enabled=True)
# self.config_fixture.config(group='cache', caching=True) cacheable_function(self.test_value)
# cached_value = cacheable_function(self.test_value)
# cacheable_function(self.test_value) self.assertTrue(cached_value.cached)
# cached_value = cacheable_function(self.test_value)
# self.assertTrue(cached_value.cached)
def test_cache_dictionary_config_builder(self): def test_cache_dictionary_config_builder(self):
"""Validate we build a sane dogpile.cache dictionary config.""" """Validate we build a sane dogpile.cache dictionary config."""
@ -286,27 +286,26 @@ class CacheRegionTest(BaseTestCase):
config_dict['test_prefix.arguments.arg2']) config_dict['test_prefix.arguments.arg2'])
self.assertNotIn('test_prefix.arguments.arg3', config_dict) self.assertNotIn('test_prefix.arguments.arg3', config_dict)
# FIXME(dims) : Need to resurrect this test ported from keystone def test_cache_debug_proxy(self):
# def test_cache_debug_proxy(self): single_value = 'Test Value'
# single_value = 'Test Value' single_key = 'testkey'
# single_key = 'testkey' multi_values = {'key1': 1, 'key2': 2, 'key3': 3}
# multi_values = {'key1': 1, 'key2': 2, 'key3': 3}
# self.region.set(single_key, single_value)
# self.region.set(single_key, single_value) self.assertEqual(single_value, self.region.get(single_key))
# self.assertEqual(single_value, self.region.get(single_key))
# self.region.delete(single_key)
# self.region.delete(single_key) self.assertEqual(NO_VALUE, self.region.get(single_key))
# self.assertEqual(NO_VALUE, self.region.get(single_key))
# self.region.set_multi(multi_values)
# self.region.set_multi(multi_values) cached_values = self.region.get_multi(multi_values.keys())
# cached_values = self.region.get_multi(multi_values.keys()) for value in multi_values.values():
# for value in multi_values.values(): self.assertIn(value, cached_values)
# self.assertIn(value, cached_values) self.assertEqual(len(multi_values.values()), len(cached_values))
# self.assertEqual(len(multi_values.values()), len(cached_values))
# self.region.delete_multi(multi_values.keys())
# self.region.delete_multi(multi_values.keys()) for value in self.region.get_multi(multi_values.keys()):
# for value in self.region.get_multi(multi_values.keys()): self.assertEqual(NO_VALUE, value)
# self.assertEqual(NO_VALUE, value)
def test_configure_non_region_object_raises_error(self): def test_configure_non_region_object_raises_error(self):
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
@ -324,9 +323,8 @@ class CacheNoopBackendTest(BaseTestCase):
def config_overrides(self): def config_overrides(self):
super(CacheNoopBackendTest, self).config_overrides() super(CacheNoopBackendTest, self).config_overrides()
self.config_fixture.config(group='cache', self.config_fixture.config(group='cache',
backend='oslo_cache.cache.noop') backend='oslo_cache.noop')
@testtools.skipIf(six.PY3, 'FIXME: this test does not work python 3.x')
def test_noop_backend(self): def test_noop_backend(self):
single_value = 'Test Value' single_value = 'Test Value'
single_key = 'testkey' single_key = 'testkey'

View File

@ -5,7 +5,6 @@ hacking<0.11,>=0.10.0
oslotest>=1.5.1 # Apache-2.0 oslotest>=1.5.1 # Apache-2.0
oslosphinx>=2.5.0 # Apache-2.0 oslosphinx>=2.5.0 # Apache-2.0
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2 sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2
testtools>=1.4.0
# Optional dogpile backend: MongoDB # Optional dogpile backend: MongoDB
pymongo>=3.0.2 pymongo>=3.0.2