summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlin-hua-cheng <os.lcheng@gmail.com>2015-10-15 16:09:05 -0700
committerItxaka <iserrano@redhat.com>2015-12-23 12:21:45 +0100
commit31ab61d3b5a0ae7bd281e975f955136b9adebdb6 (patch)
treeefd6c0adf0819e140a18d200ebf809286617c62c
parent651a22ceaf3feb92ea2e1bab9420d9d97dd5b635 (diff)
downloaddjango_openstack_auth-31ab61d3b5a0ae7bd281e975f955136b9adebdb6.tar.gz
Revert - Cache the User's Project by Token ID
The caching is done only per process, so the cleanup during logout does not really work since the during could be handled by another process. So the cache will just keep on growing. This reverts commit bd9fd598e6c2ff11f8c31098cd25c7a42a97d761. Change-Id: If878d77533ea5fac86fbb73127f26908f1097091 Closes-Bug: #1451943 (cherry picked from commit 91dec7239da7eb7c6dad385b42aa8aa5a7efa422)
-rw-r--r--openstack_auth/tests/tests.py59
-rw-r--r--openstack_auth/utils.py36
-rw-r--r--openstack_auth/views.py2
3 files changed, 0 insertions, 97 deletions
diff --git a/openstack_auth/tests/tests.py b/openstack_auth/tests/tests.py
index 0901429..241fd00 100644
--- a/openstack_auth/tests/tests.py
+++ b/openstack_auth/tests/tests.py
@@ -436,35 +436,6 @@ class OpenStackAuthTestsV2(OpenStackAuthTestsMixin, test.TestCase):
token=unscoped.auth_token)
self.assertEqual(tenant_list, expected_tenants)
- def test_tenant_list_caching(self):
- tenants = [self.data.tenant_two, self.data.tenant_one]
- expected_tenants = [self.data.tenant_one, self.data.tenant_two]
- user = self.data.user
- unscoped = self.data.unscoped_access_info
-
- client = self._mock_unscoped_client_with_token(user, unscoped)
- self._mock_unscoped_list_tenants(client, tenants)
- self.mox.ReplayAll()
-
- tenant_list = utils.get_project_list(
- user_id=user.id,
- auth_url=settings.OPENSTACK_KEYSTONE_URL,
- token=unscoped.auth_token)
- self.assertEqual(tenant_list, expected_tenants)
-
- # Test to validate that requesting the project list again results
- # to using the cache and will not make a Keystone call.
- self.assertEqual(utils._PROJECT_CACHE.get(unscoped.auth_token),
- expected_tenants)
- tenant_list = utils.get_project_list(
- user_id=user.id,
- auth_url=settings.OPENSTACK_KEYSTONE_URL,
- token=unscoped.auth_token)
- self.assertEqual(tenant_list, expected_tenants)
-
- utils.remove_project_cache(unscoped.auth_token)
- self.assertIsNone(utils._PROJECT_CACHE.get(unscoped.auth_token))
-
class OpenStackAuthTestsV3(OpenStackAuthTestsMixin, test.TestCase):
@@ -791,36 +762,6 @@ class OpenStackAuthTestsV3(OpenStackAuthTestsMixin, test.TestCase):
token=unscoped.auth_token)
self.assertEqual(project_list, expected_projects)
- def test_tenant_list_caching(self):
- projects = [self.data.project_two, self.data.project_one]
- expected_projects = [self.data.project_one, self.data.project_two]
- user = self.data.user
- unscoped = self.data.unscoped_access_info
-
- client = self._mock_unscoped_client_with_token(user, unscoped)
- self._mock_unscoped_list_projects(client, user, projects)
-
- self.mox.ReplayAll()
-
- project_list = utils.get_project_list(
- user_id=user.id,
- auth_url=settings.OPENSTACK_KEYSTONE_URL,
- token=unscoped.auth_token)
- self.assertEqual(project_list, expected_projects)
-
- # Test to validate that requesting the project list again results
- # to using the cache and will not make a Keystone call.
- self.assertEqual(utils._PROJECT_CACHE.get(unscoped.auth_token),
- expected_projects)
- project_list = utils.get_project_list(
- user_id=user.id,
- auth_url=settings.OPENSTACK_KEYSTONE_URL,
- token=unscoped.auth_token)
- self.assertEqual(project_list, expected_projects)
-
- utils.remove_project_cache(unscoped.auth_token)
- self.assertIsNone(utils._PROJECT_CACHE.get(unscoped.auth_token))
-
class OpenStackAuthTestsWebSSO(OpenStackAuthTestsMixin, test.TestCase):
diff --git a/openstack_auth/utils.py b/openstack_auth/utils.py
index 1bc212e..9ffb44e 100644
--- a/openstack_auth/utils.py
+++ b/openstack_auth/utils.py
@@ -12,14 +12,12 @@
# limitations under the License.
import datetime
-import functools
import logging
from django.conf import settings
from django.contrib import auth
from django.contrib.auth import middleware
from django.contrib.auth import models
-from django.utils import decorators
from django.utils import timezone
from keystoneclient.auth.identity import v2 as v2_auth
from keystoneclient.auth.identity import v3 as v3_auth
@@ -32,8 +30,6 @@ from six.moves.urllib import parse as urlparse
LOG = logging.getLogger(__name__)
-_PROJECT_CACHE = {}
-
_TOKEN_TIMEOUT_MARGIN = getattr(settings, 'TOKEN_TIMEOUT_MARGIN', 0)
"""
@@ -116,37 +112,6 @@ def is_safe_url(url, host=None):
return not netloc or netloc == host
-def memoize_by_keyword_arg(cache, kw_keys):
- """Memoize a function using the list of keyword argument name as its key.
-
- Wrap a function so that results for any keyword argument tuple are stored
- in 'cache'. Note that the keyword args to the function must be usable as
- dictionary keys.
-
- :param cache: Dictionary object to store the results.
- :param kw_keys: List of keyword arguments names. The values are used
- for generating the key in the cache.
- """
- def _decorator(func):
- @functools.wraps(func, assigned=decorators.available_attrs(func))
- def wrapper(*args, **kwargs):
- mem_args = [kwargs[key] for key in kw_keys if key in kwargs]
- mem_args = '__'.join(str(mem_arg) for mem_arg in mem_args)
- if not mem_args:
- return func(*args, **kwargs)
- if mem_args in cache:
- return cache[mem_args]
- result = func(*args, **kwargs)
- cache[mem_args] = result
- return result
- return wrapper
- return _decorator
-
-
-def remove_project_cache(token):
- _PROJECT_CACHE.pop(token, None)
-
-
# Helper for figuring out keystone version
# Implementation will change when API version discovery is available
def get_keystone_version():
@@ -312,7 +277,6 @@ def get_token_auth_plugin(auth_url, token, project_id=None):
reauthenticate=False)
-@memoize_by_keyword_arg(_PROJECT_CACHE, ('token', ))
def get_project_list(*args, **kwargs):
is_federated = kwargs.get('is_federated', False)
sess = kwargs.get('session') or get_session()
diff --git a/openstack_auth/views.py b/openstack_auth/views.py
index 52f2d48..677986f 100644
--- a/openstack_auth/views.py
+++ b/openstack_auth/views.py
@@ -175,8 +175,6 @@ def logout(request, login_url=None, **kwargs):
def delete_token(endpoint, token_id):
"""Delete a token."""
- utils.remove_project_cache(token_id)
-
try:
endpoint = utils.fix_auth_url_version(endpoint)