Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix isEnabledFor for compatibility with logging
After refactoring Keystone to use the unified logging implementation
from Oslo-incubator there were some issues using isEnabledFor with the
ContextAdapter provided in keystone/openstack/common/log.py. This
removes those calls and adds a check in keystone/common/wsgi.py to
handle the case where Keystone is running Python 2.6, in which
ContextAdapter doesn't have 'isEnabledFor'.

fixes bug 1213284

Change-Id: I8c64b12dcd9d955c96dc5a48348555ff37b15116
  • Loading branch information
Lance Bragstad committed Aug 20, 2013
1 parent 0b2a160 commit cfebb34
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
39 changes: 18 additions & 21 deletions keystone/common/ldap/core.py
Expand Up @@ -514,24 +514,22 @@ def simple_bind_s(self, user, password):
def add_s(self, dn, attrs):
ldap_attrs = [(kind, [py2ldap(x) for x in safe_iter(values)])
for kind, values in attrs]
if LOG.isEnabledFor(LOG.debug):
sane_attrs = [(kind, values
if kind != 'userPassword'
else ['****'])
for kind, values in ldap_attrs]
LOG.debug(_('LDAP add: dn=%(dn)s, attrs=%(attrs)s') % {
'dn': dn, 'attrs': sane_attrs})
sane_attrs = [(kind, values
if kind != 'userPassword'
else ['****'])
for kind, values in ldap_attrs]
LOG.debug(_('LDAP add: dn=%(dn)s, attrs=%(attrs)s') % {
'dn': dn, 'attrs': sane_attrs})
return self.conn.add_s(dn, ldap_attrs)

def search_s(self, dn, scope, query, attrlist=None):
if LOG.isEnabledFor(LOG.debug):
LOG.debug(_(
'LDAP search: dn=%(dn)s, scope=%(scope)s, query=%(query)s, '
'attrs=%(attrlist)s') % {
'dn': dn,
'scope': scope,
'query': query,
'attrlist': attrlist})
LOG.debug(_(
'LDAP search: dn=%(dn)s, scope=%(scope)s, query=%(query)s, '
'attrs=%(attrlist)s') % {
'dn': dn,
'scope': scope,
'query': query,
'attrlist': attrlist})
if self.page_size:
res = self.paged_search_s(dn, scope, query, attrlist)
else:
Expand Down Expand Up @@ -591,12 +589,11 @@ def modify_s(self, dn, modlist):
else [py2ldap(x) for x in safe_iter(values)]))
for op, kind, values in modlist]

if LOG.isEnabledFor(LOG.debug):
sane_modlist = [(op, kind, (values if kind != 'userPassword'
else ['****']))
for op, kind, values in ldap_modlist]
LOG.debug(_('LDAP modify: dn=%(dn)s, modlist=%(modlist)s') % {
'dn': dn, 'modlist': sane_modlist})
sane_modlist = [(op, kind, (values if kind != 'userPassword'
else ['****']))
for op, kind, values in ldap_modlist]
LOG.debug(_('LDAP modify: dn=%(dn)s, modlist=%(modlist)s') % {
'dn': dn, 'modlist': sane_modlist})

return self.conn.modify_s(dn, ldap_modlist)

Expand Down
4 changes: 2 additions & 2 deletions keystone/common/wsgi.py
Expand Up @@ -396,7 +396,7 @@ class Debug(Middleware):

@webob.dec.wsgify(RequestClass=Request)
def __call__(self, req):
if LOG.isEnabledFor(LOG.debug):
if not hasattr(LOG, 'isEnabledFor') or LOG.isEnabledFor(LOG.debug):
LOG.debug('%s %s %s', ('*' * 20), 'REQUEST ENVIRON', ('*' * 20))
for key, value in req.environ.items():
LOG.debug('%s = %s', key, mask_password(value,
Expand All @@ -408,7 +408,7 @@ def __call__(self, req):
LOG.debug('')

resp = req.get_response(self.application)
if LOG.isEnabledFor(LOG.debug):
if not hasattr(LOG, 'isEnabledFor') or LOG.isEnabledFor(LOG.debug):
LOG.debug('%s %s %s', ('*' * 20), 'RESPONSE HEADERS', ('*' * 20))
for (key, value) in resp.headers.iteritems():
LOG.debug('%s = %s', key, value)
Expand Down

0 comments on commit cfebb34

Please sign in to comment.