Uses explicit imports for _

Previously `_` was monkeypatched in tests/core.py and bin/keystone-*.
This meant that if a developer was not running the tests exactly as
the documentation described they would not work. Even importing
certain modules in a interactive Python interpreter would fail unless
keystone.tests was imported first. Monkeypatching was removed and
explicit import for `_` was added.

Co-Authored-By: David Stanek <dstanek@dstanek.com>
Change-Id: I8b25b5b6d83fb873e25a8fab7686babf1d2261fa
Closes-Bug: #1255518
changes/66/58766/31
Ilya Pekelny 9 years ago committed by Morgan Fainberg
parent d906f57748
commit 5f3fcf1123
  1. 10
      bin/keystone-all
  2. 9
      bin/keystone-manage
  3. 7
      httpd/keystone.py
  4. 13
      keystone/assignment/backends/kvs.py
  5. 3
      keystone/assignment/backends/ldap.py
  6. 1
      keystone/assignment/backends/sql.py
  7. 1
      keystone/assignment/controllers.py
  8. 1
      keystone/assignment/core.py
  9. 1
      keystone/auth/controllers.py
  10. 1
      keystone/auth/plugins/external.py
  11. 1
      keystone/auth/plugins/oauth1.py
  12. 1
      keystone/auth/plugins/password.py
  13. 1
      keystone/catalog/backends/templated.py
  14. 1
      keystone/catalog/controllers.py
  15. 1
      keystone/catalog/core.py
  16. 1
      keystone/clean.py
  17. 1
      keystone/common/authorization.py
  18. 2
      keystone/common/base64utils.py
  19. 1
      keystone/common/cache/backends/mongo.py
  20. 1
      keystone/common/cache/core.py
  21. 1
      keystone/common/controller.py
  22. 1
      keystone/common/environment/__init__.py
  23. 1
      keystone/common/environment/eventlet_server.py
  24. 1
      keystone/common/kvs/backends/memcached.py
  25. 1
      keystone/common/ldap/core.py
  26. 4
      keystone/common/pemutils.py
  27. 2
      keystone/common/serializer.py
  28. 1
      keystone/common/sql/core.py
  29. 1
      keystone/common/sql/migrate_repo/versions/033_migrate_ec2credentials_table_credentials.py
  30. 1
      keystone/common/sql/migration_helpers.py
  31. 1
      keystone/common/utils.py
  32. 1
      keystone/common/wsgi.py
  33. 4
      keystone/contrib/ec2/controllers.py
  34. 1
      keystone/contrib/endpoint_filter/backends/sql.py
  35. 1
      keystone/contrib/example/core.py
  36. 1
      keystone/contrib/federation/utils.py
  37. 1
      keystone/contrib/oauth1/backends/sql.py
  38. 1
      keystone/contrib/oauth1/controllers.py
  39. 1
      keystone/contrib/revoke/controllers.py
  40. 1
      keystone/contrib/revoke/core.py
  41. 1
      keystone/credential/controllers.py
  42. 1
      keystone/credential/core.py
  43. 1
      keystone/identity/backends/kvs.py
  44. 1
      keystone/identity/backends/ldap.py
  45. 1
      keystone/identity/backends/sql.py
  46. 1
      keystone/identity/controllers.py
  47. 1
      keystone/identity/core.py
  48. 1
      keystone/middleware/core.py
  49. 1
      keystone/notifications.py
  50. 1
      keystone/policy/backends/rules.py
  51. 10
      keystone/tests/core.py
  52. 1
      keystone/tests/fakeldap.py
  53. 2
      keystone/tests/test_kvs.py
  54. 1
      keystone/tests/test_wsgi.py
  55. 1
      keystone/token/backends/kvs.py
  56. 1
      keystone/token/controllers.py
  57. 1
      keystone/token/core.py
  58. 1
      keystone/token/provider.py
  59. 1
      keystone/token/providers/common.py
  60. 1
      keystone/token/providers/pki.py
  61. 1
      keystone/trust/controllers.py
  62. 1
      keystone/trust/core.py
  63. 3
      tox.ini

@ -35,11 +35,11 @@ from paste import deploy
import pbr.version
from keystone.openstack.common import gettextutils
# NOTE(blk-u):
# gettextutils.install() must run to set _ before importing any modules that
# contain static translated strings.
gettextutils.install('keystone', lazy=True)
# NOTE(dstanek): gettextutils.enable_lazy() must be called before
# gettextutils._() is called to ensure it has the desired lazy lookup
# behavior. This includes cases, like keystone.exceptions, where
# gettextutils._() is called at import time.
gettextutils.enable_lazy()
from keystone.common import dependency
from keystone.common import environment

@ -28,10 +28,11 @@ if os.path.exists(os.path.join(possible_topdir,
sys.path.insert(0, possible_topdir)
from keystone.openstack.common import gettextutils
# NOTE(blk-u): gettextutils.install() must run to set _ before importing any
# modules that contain static translated strings.
gettextutils.install('keystone', lazy=True)
# NOTE(dstanek): gettextutils.enable_lazy() must be called before
# gettextutils._() is called to ensure it has the desired lazy lookup
# behavior. This includes cases, like keystone.exceptions, where
# gettextutils._() is called at import time.
gettextutils.enable_lazy()
from keystone import cli
from keystone.common import environment

@ -17,13 +17,6 @@ import os
from paste import deploy
from keystone.openstack.common import gettextutils
# NOTE(blk-u):
# gettextutils.install() must run to set _ before importing any modules that
# contain static translated strings.
gettextutils.install('keystone', lazy=True)
from keystone.common import dependency
from keystone.common import environment
from keystone.common import sql

@ -16,6 +16,7 @@ from keystone import assignment
from keystone import clean
from keystone.common import kvs
from keystone import exception
from keystone.openstack.common.gettextutils import _
class Assignment(kvs.Base, assignment.Driver):
@ -85,7 +86,7 @@ class Assignment(kvs.Base, assignment.Driver):
metadata_keys = filter(lambda x: x.startswith("metadata_user-"),
self.db.keys())
for key in metadata_keys:
_, meta_project_or_domain_id, meta_user_id = key.split('-')
i, meta_project_or_domain_id, meta_user_id = key.split('-')
if meta_project_or_domain_id != tenant_id:
# target is not the project, so on to next metadata.
@ -138,7 +139,7 @@ class Assignment(kvs.Base, assignment.Driver):
metadata_keys = filter(lambda x: x.startswith('metadata_user-'),
self.db.keys())
for key in metadata_keys:
_, meta_project_or_domain_id, meta_user_id = key.split('-')
i, meta_project_or_domain_id, meta_user_id = key.split('-')
if meta_user_id != user_id:
# Not the user, so on to next metadata.
@ -219,7 +220,7 @@ class Assignment(kvs.Base, assignment.Driver):
self.db.keys())
for key in metadata_keys:
template = {}
_, meta_project_or_domain_id, template['user_id'] = key.split('-')
i, meta_project_or_domain_id, template['user_id'] = key.split('-')
try:
self.get_project(meta_project_or_domain_id)
template['project_id'] = meta_project_or_domain_id
@ -238,7 +239,7 @@ class Assignment(kvs.Base, assignment.Driver):
self.db.keys())
for key in metadata_keys:
template = {}
_, meta_project_or_domain_id, template['group_id'] = key.split('-')
i, meta_project_or_domain_id, template['group_id'] = key.split('-')
try:
self.get_project(meta_project_or_domain_id)
template['project_id'] = meta_project_or_domain_id
@ -374,7 +375,7 @@ class Assignment(kvs.Base, assignment.Driver):
metadata_keys = filter(lambda x: x.startswith('metadata_user-'),
self.db.keys())
for key in metadata_keys:
_, meta_project_or_domain_id, meta_user_id = key.split('-')
i, meta_project_or_domain_id, meta_user_id = key.split('-')
try:
self.delete_grant(role_id,
project_id=meta_project_or_domain_id,
@ -390,7 +391,7 @@ class Assignment(kvs.Base, assignment.Driver):
metadata_keys = filter(lambda x: x.startswith('metadata_group-'),
self.db.keys())
for key in metadata_keys:
_, meta_project_or_domain_id, meta_group_id = key.split('-')
i, meta_project_or_domain_id, meta_group_id = key.split('-')
try:
self.delete_grant(role_id,
project_id=meta_project_or_domain_id,

@ -25,6 +25,7 @@ from keystone.common import models
from keystone import config
from keystone import exception
from keystone.identity.backends import ldap as ldap_identity
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log
@ -293,7 +294,7 @@ class Assignment(assignment.Driver):
conn = self.group.get_connection()
roles = conn.search_s(dn, ldap.SCOPE_ONELEVEL,
query, ['%s' % '1.1'])
for role_dn, _ in roles:
for role_dn, i in roles:
conn.delete_s(role_dn)
except ldap.NO_SUCH_OBJECT:
pass

@ -21,6 +21,7 @@ from keystone.common.sql import migration_helpers
from keystone import config
from keystone import exception
from keystone.openstack.common.db.sqlalchemy import migration
from keystone.openstack.common.gettextutils import _
CONF = config.CONF

@ -27,6 +27,7 @@ from keystone.common import controller
from keystone.common import dependency
from keystone import config
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log

@ -26,6 +26,7 @@ from keystone.common import manager
from keystone import config
from keystone import exception
from keystone import notifications
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log

@ -23,6 +23,7 @@ from keystone.common import wsgi
from keystone import config
from keystone.contrib import federation
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import importutils
from keystone.openstack.common import log
from keystone.openstack.common import timeutils

@ -22,6 +22,7 @@ from keystone import auth
from keystone.common import config
from keystone.common import dependency
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import versionutils

@ -17,6 +17,7 @@ from keystone.common import dependency
from keystone.contrib.oauth1 import core as oauth
from keystone.contrib.oauth1 import validator
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log
from keystone.openstack.common import timeutils

@ -15,6 +15,7 @@
from keystone import auth
from keystone.common import dependency
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log
METHOD_NAME = 'password'

@ -20,6 +20,7 @@ from keystone.catalog.backends import kvs
from keystone.catalog import core
from keystone import config
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log
from keystone.openstack.common import versionutils

@ -21,6 +21,7 @@ from keystone.common import controller
from keystone.common import dependency
from keystone.common import wsgi
from keystone import exception
from keystone.openstack.common.gettextutils import _
INTERFACES = ['public', 'internal', 'admin']

@ -24,6 +24,7 @@ from keystone.common import driver_hints
from keystone.common import manager
from keystone import config
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log

@ -15,6 +15,7 @@
import six
from keystone import exception
from keystone.openstack.common.gettextutils import _
def check_length(property_name, value, min_length=1, max_length=64):

@ -19,6 +19,7 @@
import collections
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log

@ -43,6 +43,8 @@ import string
import six
from six.moves import urllib
from keystone.openstack.common.gettextutils import _
class InvalidBase64Error(ValueError):
pass

@ -20,6 +20,7 @@ from dogpile.cache import util as dp_util
import six
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import importutils
from keystone.openstack.common import log
from keystone.openstack.common import timeutils

@ -20,6 +20,7 @@ from dogpile.cache import util
from keystone import config
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import importutils
from keystone.openstack.common import log

@ -22,6 +22,7 @@ from keystone.common import utils
from keystone.common import wsgi
from keystone import config
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log
from keystone.openstack.common import versionutils

@ -16,6 +16,7 @@ import functools
import os
from keystone.common import config
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log
CONF = config.CONF

@ -24,6 +24,7 @@ import eventlet
import eventlet.wsgi
import greenlet
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log

@ -27,6 +27,7 @@ from dogpile.cache.backends import memcached
from keystone.common import manager
from keystone import config
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log

@ -19,6 +19,7 @@ import ldap.filter
import six
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log
LOG = log.getLogger(__name__)

@ -93,11 +93,13 @@ and consumption of PEM formatted data including:
"""
import base64
from keystone.common import base64utils
import re
import six
from keystone.common import base64utils
from keystone.openstack.common.gettextutils import _
PEM_TYPE_TO_HEADER = {
u'cms': u'CMS',

@ -25,6 +25,8 @@ import re
import six
from keystone.openstack.common.gettextutils import _
DOCTYPE = '<?xml version="1.0" encoding="UTF-8"?>'
XMLNS = 'http://docs.openstack.org/identity/api/v2.0'

@ -34,6 +34,7 @@ from keystone.openstack.common.db import exception as db_exception
from keystone.openstack.common.db import options as db_options
from keystone.openstack.common.db.sqlalchemy import models
from keystone.openstack.common.db.sqlalchemy import session as db_session
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import jsonutils

@ -16,6 +16,7 @@ import sqlalchemy as sql
from keystone.common import utils
from keystone import exception
from keystone.openstack.common.gettextutils import _
def upgrade(migrate_engine):

@ -25,6 +25,7 @@ from keystone.common import sql
from keystone import contrib
from keystone import exception
from keystone.openstack.common.db.sqlalchemy import migration
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import importutils

@ -29,6 +29,7 @@ import six
from keystone.common import config
from keystone.common import environment
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log
from keystone.openstack.common import strutils
from six import moves

@ -28,6 +28,7 @@ from keystone.common import dependency
from keystone.common import utils
from keystone import exception
from keystone.openstack.common import gettextutils
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import importutils
from keystone.openstack.common import jsonutils
from keystone.openstack.common import log

@ -44,9 +44,9 @@ from keystone.common import dependency
from keystone.common import utils
from keystone.common import wsgi
from keystone import exception
from keystone import token
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import jsonutils
from keystone import token
@dependency.requires('assignment_api', 'catalog_api', 'credential_api',

@ -17,6 +17,7 @@ from keystone.common.sql import migration_helpers
from keystone.contrib import endpoint_filter
from keystone import exception
from keystone.openstack.common.db.sqlalchemy import migration
from keystone.openstack.common.gettextutils import _
class ProjectEndpoint(sql.ModelBase, sql.DictBase):

@ -17,6 +17,7 @@ from keystone.common import dependency
from keystone.common import manager
from keystone import config
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log

@ -18,6 +18,7 @@ import jsonschema
import six
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log

@ -24,6 +24,7 @@ from keystone.contrib import oauth1
from keystone.contrib.oauth1 import core
from keystone import exception
from keystone.openstack.common.db.sqlalchemy import migration
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import jsonutils
from keystone.openstack.common import timeutils

@ -21,6 +21,7 @@ from keystone import config
from keystone.contrib.oauth1 import core as oauth1
from keystone.contrib.oauth1 import validator
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import jsonutils
from keystone.openstack.common import timeutils

@ -13,6 +13,7 @@
from keystone.common import controller
from keystone.common import dependency
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import timeutils

@ -23,6 +23,7 @@ from keystone import config
from keystone.contrib.revoke import model
from keystone import exception
from keystone import notifications
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log
from keystone.openstack.common import timeutils

@ -19,6 +19,7 @@ from keystone.common import controller
from keystone.common import dependency
from keystone.common import driver_hints
from keystone import exception
from keystone.openstack.common.gettextutils import _
@dependency.requires('credential_api')

@ -22,6 +22,7 @@ from keystone.common import dependency
from keystone.common import manager
from keystone import config
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log

@ -16,6 +16,7 @@ from keystone.common import kvs
from keystone.common import utils
from keystone import exception
from keystone import identity
from keystone.openstack.common.gettextutils import _
class _UserIdToDomainId(object):

@ -25,6 +25,7 @@ from keystone.common import utils
from keystone import config
from keystone import exception
from keystone import identity
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log

@ -19,6 +19,7 @@ from keystone.common import utils
from keystone import exception
from keystone import identity
from keystone.openstack.common.db.sqlalchemy import migration
from keystone.openstack.common.gettextutils import _
# Import assignment sql to ensure that the models defined in there are
# available for the reference from User and Group to Domain.id.

@ -24,6 +24,7 @@ from keystone.common import controller
from keystone.common import dependency
from keystone import config
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log
from keystone.openstack.common import versionutils

@ -28,6 +28,7 @@ from keystone.common import manager
from keystone import config
from keystone import exception
from keystone import notifications
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import importutils
from keystone.openstack.common import log
from keystone.openstack.common import versionutils

@ -21,6 +21,7 @@ from keystone.common import serializer
from keystone.common import utils
from keystone.common import wsgi
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import jsonutils
from keystone.openstack.common import log
from keystone.openstack.common import versionutils

@ -25,6 +25,7 @@ from pycadf import cadftype
from pycadf import eventfactory
from pycadf import resource
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log
notifier_opts = [

@ -20,6 +20,7 @@ import os.path
from keystone.common import utils
from keystone import config
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log
from keystone.openstack.common import policy as common_policy
from keystone import policy

@ -35,15 +35,6 @@ import webob
from keystone.openstack.common.fixture import mockpatch
from keystone.openstack.common import gettextutils
# NOTE(blk-u):
# gettextutils.install() must run to set _ before importing any modules that
# contain static translated strings.
#
# Configure gettextutils for deferred translation of messages
# so that error messages in responses can be translated according to the
# Accept-Language in the request rather than the Keystone server locale.
gettextutils.install('keystone', lazy=True)
# NOTE(ayoung)
# environment.use_eventlet must run before any of the code that will
# call the eventlet monkeypatching.
@ -63,6 +54,7 @@ from keystone import notifications
from keystone.openstack.common.db import options as db_options
from keystone.openstack.common.db.sqlalchemy import migration
from keystone.openstack.common.fixture import config as config_fixture
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log
from keystone import service
from keystone.tests import fixtures as ksfixtures

@ -30,6 +30,7 @@ import six
from six import moves
from keystone.common import utils
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log

@ -571,7 +571,7 @@ class KVSTest(tests.TestCase):
class TestMemcachedBackend(tests.TestCase):
@mock.patch('__builtin__._', six.text_type)
@mock.patch('keystone.common.kvs.backends.memcached._', six.text_type)
def test_invalid_backend_fails_initialization(self):
raises_valueerror = matchers.Raises(matchers.MatchesException(
ValueError, r'.*FakeBackend.*'))

@ -23,6 +23,7 @@ from keystone.common import wsgi
from keystone import exception
from keystone.openstack.common.fixture import moxstubout
from keystone.openstack.common import gettextutils
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import jsonutils
from keystone import tests

@ -23,6 +23,7 @@ import six
from keystone.common import kvs
from keystone import config
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log
from keystone.openstack.common import timeutils
from keystone import token

@ -23,6 +23,7 @@ from keystone.common import dependency
from keystone.common import wsgi
from keystone import config
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log
from keystone.openstack.common import timeutils
from keystone.token import core

@ -26,6 +26,7 @@ from keystone.common import dependency
from keystone.common import manager
from keystone import config
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log
from keystone.openstack.common import timeutils
from keystone.openstack.common import versionutils

@ -24,6 +24,7 @@ from keystone.common import manager
from keystone import config
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log
from keystone.openstack.common import timeutils

@ -22,6 +22,7 @@ from keystone.common import dependency
from keystone import config
from keystone.contrib import federation
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone import token
from keystone.token import provider
from keystone import trust

@ -21,6 +21,7 @@ from keystoneclient.common import cms
from keystone.common import environment
from keystone import config
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log
from keystone.token.providers import common

@ -21,6 +21,7 @@ from keystone.common import controller
from keystone.common import dependency
from keystone import config
from keystone import exception
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log
from keystone.openstack.common import timeutils

@ -23,6 +23,7 @@ from keystone.common import manager
from keystone import config
from keystone import exception
from keystone import notifications
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log

@ -49,3 +49,6 @@ commands=
[testenv:sample_config]
envdir = {toxworkdir}/venv
commands = {toxinidir}/tools/config/generate_sample.sh
[hacking]
import_exceptions = keystone.openstack.common.gettextutils._

Loading…
Cancel
Save