Fix reading cache-time before configured

There were several places where the cache time was read at
import-time. This means that the default value is used rather
than the value that the user configured because CONF() had not
been called yet.

This change makes it so the values are read at run-time, after
CONF() has been called.

Change-Id: I835418f249c5217bf79efebad1dee22d25f6774a
Closes-Bug: #1265670
This commit is contained in:
Brant Knudson 2014-01-02 18:42:42 -06:00
parent 627141fe45
commit 5e7b4809aa
4 changed files with 23 additions and 14 deletions

View File

@ -34,6 +34,9 @@ CONF = config.CONF
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
SHOULD_CACHE = cache.should_cache_fn('assignment') SHOULD_CACHE = cache.should_cache_fn('assignment')
# NOTE(blk-u): The config option is not available at import time.
EXPIRATION_TIME = lambda: CONF.assignment.cache_time
def calc_default_domain(): def calc_default_domain():
return {'description': return {'description':
@ -275,12 +278,12 @@ class Manager(manager.Manager):
return self.driver.list_projects_for_user(user_id, group_ids) return self.driver.list_projects_for_user(user_id, group_ids)
@cache.on_arguments(should_cache_fn=SHOULD_CACHE, @cache.on_arguments(should_cache_fn=SHOULD_CACHE,
expiration_time=CONF.assignment.cache_time) expiration_time=EXPIRATION_TIME)
def get_domain(self, domain_id): def get_domain(self, domain_id):
return self.driver.get_domain(domain_id) return self.driver.get_domain(domain_id)
@cache.on_arguments(should_cache_fn=SHOULD_CACHE, @cache.on_arguments(should_cache_fn=SHOULD_CACHE,
expiration_time=CONF.assignment.cache_time) expiration_time=EXPIRATION_TIME)
def get_domain_by_name(self, domain_name): def get_domain_by_name(self, domain_name):
return self.driver.get_domain_by_name(domain_name) return self.driver.get_domain_by_name(domain_name)
@ -385,17 +388,17 @@ class Manager(manager.Manager):
'domainid': domain_id}) 'domainid': domain_id})
@cache.on_arguments(should_cache_fn=SHOULD_CACHE, @cache.on_arguments(should_cache_fn=SHOULD_CACHE,
expiration_time=CONF.assignment.cache_time) expiration_time=EXPIRATION_TIME)
def get_project(self, project_id): def get_project(self, project_id):
return self.driver.get_project(project_id) return self.driver.get_project(project_id)
@cache.on_arguments(should_cache_fn=SHOULD_CACHE, @cache.on_arguments(should_cache_fn=SHOULD_CACHE,
expiration_time=CONF.assignment.cache_time) expiration_time=EXPIRATION_TIME)
def get_project_by_name(self, tenant_name, domain_id): def get_project_by_name(self, tenant_name, domain_id):
return self.driver.get_project_by_name(tenant_name, domain_id) return self.driver.get_project_by_name(tenant_name, domain_id)
@cache.on_arguments(should_cache_fn=SHOULD_CACHE, @cache.on_arguments(should_cache_fn=SHOULD_CACHE,
expiration_time=CONF.assignment.cache_time) expiration_time=EXPIRATION_TIME)
def get_role(self, role_id): def get_role(self, role_id):
return self.driver.get_role(role_id) return self.driver.get_role(role_id)

View File

@ -38,11 +38,11 @@ CONF = config.CONF
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
# Ensure the cache is configured and built before we instantiate the managers
cache.configure_cache_region(cache.REGION)
def load_backends(): def load_backends():
# Configure and build the cache
cache.configure_cache_region(cache.REGION)
# Ensure that the identity driver is created before the assignment manager. # Ensure that the identity driver is created before the assignment manager.
# The default assignment driver is determined by the identity driver, so # The default assignment driver is determined by the identity driver, so
# the identity driver must be available to the assignment manager. # the identity driver must be available to the assignment manager.

View File

@ -37,6 +37,10 @@ CONF = config.CONF
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
SHOULD_CACHE = cache.should_cache_fn('token') SHOULD_CACHE = cache.should_cache_fn('token')
# NOTE(blk-u): The config options are not available at import time.
EXPIRATION_TIME = lambda: CONF.token.cache_time
REVOCATION_CACHE_EXPIRATION_TIME = lambda: CONF.token.revocation_cache_time
def default_expire_time(): def default_expire_time():
"""Determine when a fresh token should expire. """Determine when a fresh token should expire.
@ -144,7 +148,7 @@ class Manager(manager.Manager):
return token_ref return token_ref
@cache.on_arguments(should_cache_fn=SHOULD_CACHE, @cache.on_arguments(should_cache_fn=SHOULD_CACHE,
expiration_time=CONF.token.cache_time) expiration_time=EXPIRATION_TIME)
def _get_token(self, token_id): def _get_token(self, token_id):
# Only ever use the "unique" id in the cache key. # Only ever use the "unique" id in the cache key.
return self.driver.get_token(token_id) return self.driver.get_token(token_id)
@ -178,7 +182,7 @@ class Manager(manager.Manager):
self.invalidate_revocation_list() self.invalidate_revocation_list()
@cache.on_arguments(should_cache_fn=SHOULD_CACHE, @cache.on_arguments(should_cache_fn=SHOULD_CACHE,
expiration_time=CONF.token.revocation_cache_time) expiration_time=REVOCATION_CACHE_EXPIRATION_TIME)
def list_revoked_tokens(self): def list_revoked_tokens(self):
return self.driver.list_revoked_tokens() return self.driver.list_revoked_tokens()

View File

@ -33,6 +33,8 @@ CONF = config.CONF
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
SHOULD_CACHE = cache.should_cache_fn('token') SHOULD_CACHE = cache.should_cache_fn('token')
# NOTE(blk-u): The config options are not available at import time.
EXPIRATION_TIME = lambda: CONF.token.cache_time
# supported token versions # supported token versions
V2 = 'v2.0' V2 = 'v2.0'
@ -158,17 +160,17 @@ class Manager(manager.Manager):
self.validate_v3_token(unique_id) self.validate_v3_token(unique_id)
@cache.on_arguments(should_cache_fn=SHOULD_CACHE, @cache.on_arguments(should_cache_fn=SHOULD_CACHE,
expiration_time=CONF.token.cache_time) expiration_time=EXPIRATION_TIME)
def _validate_token(self, token_id): def _validate_token(self, token_id):
return self.driver.validate_token(token_id) return self.driver.validate_token(token_id)
@cache.on_arguments(should_cache_fn=SHOULD_CACHE, @cache.on_arguments(should_cache_fn=SHOULD_CACHE,
expiration_time=CONF.token.cache_time) expiration_time=EXPIRATION_TIME)
def _validate_v2_token(self, token_id): def _validate_v2_token(self, token_id):
return self.driver.validate_v2_token(token_id) return self.driver.validate_v2_token(token_id)
@cache.on_arguments(should_cache_fn=SHOULD_CACHE, @cache.on_arguments(should_cache_fn=SHOULD_CACHE,
expiration_time=CONF.token.cache_time) expiration_time=EXPIRATION_TIME)
def _validate_v3_token(self, token_id): def _validate_v3_token(self, token_id):
return self.driver.validate_v3_token(token_id) return self.driver.validate_v3_token(token_id)