From 236ba5fa6565fe340a1e098bcbe9b216fb5b8931 Mon Sep 17 00:00:00 2001 From: Bo Wang Date: Tue, 16 Feb 2016 20:44:57 +0800 Subject: [PATCH] Use oslo.utils.reflection to extract class name The oslo.utils.reflection.get_class_name() handles more variations of where a class name may come from (on) python 2 and python 3. Its usage allows getting more accurate class names so we'd better use it. Change-Id: I97cc7f1e818161c2fe265da1ed1b52add1951c90 --- heatclient/exc.py | 7 ++++--- heatclient/openstack/common/apiclient/base.py | 4 +++- heatclient/tests/unit/osc/fakes.py | 4 +++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/heatclient/exc.py b/heatclient/exc.py index ea7d5758..7d4968ce 100644 --- a/heatclient/exc.py +++ b/heatclient/exc.py @@ -13,6 +13,7 @@ import sys from oslo_serialization import jsonutils +from oslo_utils import reflection from heatclient.openstack.common._i18n import _ @@ -78,9 +79,9 @@ class HTTPMultipleChoices(HTTPException): "available.") return (_("%(name)s (HTTP %(code)s) %(details)s") % { - 'name': self.__class__.__name__, - 'code': self.code, - 'details': self.details}) + 'name': reflection.get_class_name(self, fully_qualified=False), + 'code': self.code, + 'details': self.details}) class BadRequest(HTTPException): diff --git a/heatclient/openstack/common/apiclient/base.py b/heatclient/openstack/common/apiclient/base.py index 13faeb67..8251e4fe 100644 --- a/heatclient/openstack/common/apiclient/base.py +++ b/heatclient/openstack/common/apiclient/base.py @@ -41,6 +41,7 @@ import abc import copy import logging +from oslo_utils import reflection from oslo_utils import strutils import six from six.moves.urllib import parse @@ -466,7 +467,8 @@ class Resource(object): for k in self.__dict__.keys() if k[0] != '_' and k != 'manager') info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys) - return "<%s %s>" % (self.__class__.__name__, info) + class_name = reflection.get_class_name(self, fully_qualified=False) + return "<%s %s>" % (class_name, info) @property def human_id(self): diff --git a/heatclient/tests/unit/osc/fakes.py b/heatclient/tests/unit/osc/fakes.py index 1fcd6e59..8ce67c74 100644 --- a/heatclient/tests/unit/osc/fakes.py +++ b/heatclient/tests/unit/osc/fakes.py @@ -16,6 +16,7 @@ import json import sys +from oslo_utils import reflection import requests import six @@ -222,7 +223,8 @@ class FakeResource(object): reprkeys = sorted(k for k in self.__dict__.keys() if k[0] != '_' and k != 'manager') info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys) - return "<%s %s>" % (self.__class__.__name__, info) + class_name = reflection.get_class_name(self, fully_qualified=False) + return "<%s %s>" % (class_name, info) class FakeResponse(requests.Response):