diff --git a/openstack_auth/tests/tests.py b/openstack_auth/tests/tests.py index 11d5511e..bdb50aa2 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): @@ -819,36 +790,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 6f3e8d9f..59f58ab3 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(): @@ -317,7 +282,6 @@ def get_token_auth_plugin(auth_url, token, project_id=None, domain_name=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 65feccba..73c60776 100644 --- a/openstack_auth/views.py +++ b/openstack_auth/views.py @@ -183,8 +183,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)