Use the oslo.utils.reflection to extract the class name

The oslo.utils reflection module/code handles more variations
of where a class name may come from (on python 2 and python 3)
so its usage allows getting more accurate class names so we might
as well use it.

Change-Id: I94a1f522755ec76b9b48b881c42b65a7c4c3860f
This commit is contained in:
ChangBo Guo(gcb) 2015-11-04 14:59:23 +08:00
parent 890b628607
commit f6c56d51a2
6 changed files with 28 additions and 9 deletions

View File

@ -25,6 +25,7 @@ from dogpile.core import nameregistry
from oslo_config import cfg
from oslo_log import log
from oslo_utils import importutils
from oslo_utils import reflection
from keystone import exception
from keystone.i18n import _
@ -147,12 +148,16 @@ class KeyValueStore(object):
if issubclass(pxy, proxy.ProxyBackend):
proxies.append(pxy)
else:
pxy_cls_name = reflection.get_class_name(
pxy, fully_qualified=False)
LOG.warning(_LW('%s is not a dogpile.proxy.ProxyBackend'),
pxy.__name__)
pxy_cls_name)
for proxy_cls in reversed(proxies):
proxy_cls_name = reflection.get_class_name(
proxy_cls, fully_qualified=False)
LOG.info(_LI('Adding proxy \'%(proxy)s\' to KVS %(name)s.'),
{'proxy': proxy_cls.__name__,
{'proxy': proxy_cls_name,
'name': self._region.name})
self._region.wrap(proxy_cls)

View File

@ -24,6 +24,7 @@ import ldap.controls
import ldap.filter
import ldappool
from oslo_log import log
from oslo_utils import reflection
import six
from six.moves import map, zip
@ -71,8 +72,10 @@ def utf8_encode(value):
elif isinstance(value, six.binary_type):
return value
else:
value_cls_name = reflection.get_class_name(
value, fully_qualified=False)
raise TypeError("value must be basestring, "
"not %s" % value.__class__.__name__)
"not %s" % value_cls_name)
_utf8_decoder = codecs.getdecoder('utf-8')

View File

@ -17,6 +17,7 @@ import functools
from oslo_log import log
from oslo_log import versionutils
from oslo_utils import importutils
from oslo_utils import reflection
import stevedore
from keystone.i18n import _
@ -125,14 +126,14 @@ def create_legacy_driver(driver_class):
"""
module_name = driver_class.__module__
class_name = driver_class.__name__
class_name = reflection.get_class_name(driver_class)
class Driver(driver_class):
@versionutils.deprecated(
as_of=versionutils.deprecated.LIBERTY,
what='%s.Driver' % module_name,
in_favor_of='%s.%s' % (module_name, class_name),
in_favor_of=class_name,
remove_in=+2)
def __init__(self, *args, **kwargs):
super(Driver, self).__init__(*args, **kwargs)

View File

@ -27,6 +27,7 @@ import uuid
from oslo_config import cfg
from oslo_log import log
from oslo_serialization import jsonutils
from oslo_utils import reflection
from oslo_utils import strutils
from oslo_utils import timeutils
import passlib.hash
@ -315,8 +316,10 @@ def get_unix_user(user=None):
elif user is None:
user_info = pwd.getpwuid(os.geteuid())
else:
user_cls_name = reflection.get_class_name(user,
fully_qualified=False)
raise TypeError('user must be string, int or None; not %s (%r)' %
(user.__class__.__name__, user))
(user_cls_name, user))
return user_info.pw_uid, user_info.pw_name
@ -373,8 +376,10 @@ def get_unix_group(group=None):
elif group is None:
group_info = grp.getgrgid(os.getegid())
else:
group_cls_name = reflection.get_class_name(group,
fully_qualified=False)
raise TypeError('group must be string, int or None; not %s (%r)' %
(group.__class__.__name__, group))
(group_cls_name, group))
return group_info.gr_gid, group_info.gr_name

View File

@ -14,6 +14,7 @@
from keystoneclient.common import cms
from oslo_config import cfg
from oslo_utils import reflection
from oslo_utils import timeutils
import six
@ -64,7 +65,9 @@ class KeystoneToken(dict):
def __repr__(self):
desc = ('<%(type)s (audit_id=%(audit_id)s, '
'audit_chain_id=%(audit_chain_id)s) at %(loc)s>')
return desc % {'type': self.__class__.__name__,
self_cls_name = reflection.get_class_name(self,
fully_qualified=False)
return desc % {'type': self_cls_name,
'audit_id': self.audit_id,
'audit_chain_id': self.audit_chain_id,
'loc': hex(id(self))}

View File

@ -23,6 +23,7 @@ import socket
from oslo_config import cfg
from oslo_log import log
import oslo_messaging
from oslo_utils import reflection
import pycadf
from pycadf import cadftaxonomy as taxonomy
from pycadf import cadftype
@ -254,7 +255,8 @@ def _get_callback_info(callback):
module_name = getattr(callback, '__module__', None)
func_name = callback.__name__
if inspect.ismethod(callback):
class_name = callback.__self__.__class__.__name__
class_name = reflection.get_class_name(callback.__self__,
fully_qualified=False)
return [module_name, class_name, func_name]
else:
return [module_name, func_name]