From af0fca6ad31d9dfb14ce2174718d765fba10de3a Mon Sep 17 00:00:00 2001 From: caoyue Date: Thu, 7 Jan 2016 13:20:05 +0800 Subject: [PATCH] Use oslo.utils.reflection 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: I8e9bb4a8e517111eee80a60c518f29c8d87490e9 --- neutron/common/utils.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/neutron/common/utils.py b/neutron/common/utils.py index 7237fd9d8..66e675bd1 100644 --- a/neutron/common/utils.py +++ b/neutron/common/utils.py @@ -41,6 +41,7 @@ from oslo_config import cfg from oslo_log import log as logging from oslo_utils import excutils from oslo_utils import importutils +from oslo_utils import reflection import six from stevedore import driver @@ -64,9 +65,11 @@ class cache_method_results(object): self._not_cached = object() def _get_from_cache(self, target_self, *args, **kwargs): + target_self_cls_name = reflection.get_class_name(target_self, + fully_qualified=False) func_name = "%(module)s.%(class)s.%(func_name)s" % { 'module': target_self.__module__, - 'class': target_self.__class__.__name__, + 'class': target_self_cls_name, 'func_name': self.func.__name__, } key = (func_name,) + args @@ -90,19 +93,21 @@ class cache_method_results(object): return item def __call__(self, target_self, *args, **kwargs): + target_self_cls_name = reflection.get_class_name(target_self, + fully_qualified=False) if not hasattr(target_self, '_cache'): raise NotImplementedError( "Instance of class %(module)s.%(class)s must contain _cache " "attribute" % { 'module': target_self.__module__, - 'class': target_self.__class__.__name__}) + 'class': target_self_cls_name}) if not target_self._cache: if self._first_call: LOG.debug("Instance of class %(module)s.%(class)s doesn't " "contain attribute _cache therefore results " "cannot be cached for %(func_name)s.", {'module': target_self.__module__, - 'class': target_self.__class__.__name__, + 'class': target_self_cls_name, 'func_name': self.func.__name__}) self._first_call = False return self.func(target_self, *args, **kwargs) -- 2.45.2