From 5e7b4809aa81fc8c7d381a6ac95730b0f10edc1e Mon Sep 17 00:00:00 2001 From: Brant Knudson Date: Thu, 2 Jan 2014 18:42:42 -0600 Subject: [PATCH] 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 --- keystone/assignment/core.py | 13 ++++++++----- keystone/service.py | 8 ++++---- keystone/token/core.py | 8 ++++++-- keystone/token/provider.py | 8 +++++--- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/keystone/assignment/core.py b/keystone/assignment/core.py index b3351b84e6..5bb679086a 100644 --- a/keystone/assignment/core.py +++ b/keystone/assignment/core.py @@ -34,6 +34,9 @@ CONF = config.CONF LOG = log.getLogger(__name__) 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(): return {'description': @@ -275,12 +278,12 @@ class Manager(manager.Manager): return self.driver.list_projects_for_user(user_id, group_ids) @cache.on_arguments(should_cache_fn=SHOULD_CACHE, - expiration_time=CONF.assignment.cache_time) + expiration_time=EXPIRATION_TIME) def get_domain(self, domain_id): return self.driver.get_domain(domain_id) @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): return self.driver.get_domain_by_name(domain_name) @@ -385,17 +388,17 @@ class Manager(manager.Manager): 'domainid': domain_id}) @cache.on_arguments(should_cache_fn=SHOULD_CACHE, - expiration_time=CONF.assignment.cache_time) + expiration_time=EXPIRATION_TIME) def get_project(self, project_id): return self.driver.get_project(project_id) @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): return self.driver.get_project_by_name(tenant_name, domain_id) @cache.on_arguments(should_cache_fn=SHOULD_CACHE, - expiration_time=CONF.assignment.cache_time) + expiration_time=EXPIRATION_TIME) def get_role(self, role_id): return self.driver.get_role(role_id) diff --git a/keystone/service.py b/keystone/service.py index 90984b4fba..400e8c9f33 100644 --- a/keystone/service.py +++ b/keystone/service.py @@ -38,11 +38,11 @@ CONF = config.CONF 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(): + + # Configure and build the cache + cache.configure_cache_region(cache.REGION) + # Ensure that the identity driver is created before the assignment manager. # The default assignment driver is determined by the identity driver, so # the identity driver must be available to the assignment manager. diff --git a/keystone/token/core.py b/keystone/token/core.py index 2c0aec1fba..829c697258 100644 --- a/keystone/token/core.py +++ b/keystone/token/core.py @@ -37,6 +37,10 @@ CONF = config.CONF LOG = log.getLogger(__name__) 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(): """Determine when a fresh token should expire. @@ -144,7 +148,7 @@ class Manager(manager.Manager): return token_ref @cache.on_arguments(should_cache_fn=SHOULD_CACHE, - expiration_time=CONF.token.cache_time) + expiration_time=EXPIRATION_TIME) def _get_token(self, token_id): # Only ever use the "unique" id in the cache key. return self.driver.get_token(token_id) @@ -178,7 +182,7 @@ class Manager(manager.Manager): self.invalidate_revocation_list() @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): return self.driver.list_revoked_tokens() diff --git a/keystone/token/provider.py b/keystone/token/provider.py index b7371bbf7a..d6c797ca43 100644 --- a/keystone/token/provider.py +++ b/keystone/token/provider.py @@ -33,6 +33,8 @@ CONF = config.CONF LOG = log.getLogger(__name__) 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 V2 = 'v2.0' @@ -158,17 +160,17 @@ class Manager(manager.Manager): self.validate_v3_token(unique_id) @cache.on_arguments(should_cache_fn=SHOULD_CACHE, - expiration_time=CONF.token.cache_time) + expiration_time=EXPIRATION_TIME) def _validate_token(self, token_id): return self.driver.validate_token(token_id) @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): return self.driver.validate_v2_token(token_id) @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): return self.driver.validate_v3_token(token_id)