]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Use oslo.utils.reflection extract the class name
authorcaoyue <yue.cao@easystack.cn>
Thu, 7 Jan 2016 05:20:05 +0000 (13:20 +0800)
committercaoyue <yue.cao@easystack.cn>
Thu, 7 Jan 2016 11:44:59 +0000 (19:44 +0800)
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

index 7237fd9d85a689ec67e30b03f0c0c2ab664b7b73..66e675bd174e6d20331b3f6a15c7f32b183f5a22 100644 (file)
@@ -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)