From b0b202bda21901db19c392c65bd38ec301ea4110 Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Sun, 7 Jun 2015 10:12:03 -0400 Subject: [PATCH] cleanup openstack-common.conf and sync updated files Periodic update of latest code from oslo-incubator. Change-Id: I9f7fccaa9bd3f20d111c7e406d91e588e974a14d --- heatclient/openstack/common/apiclient/base.py | 2 +- .../openstack/common/apiclient/exceptions.py | 41 ++++++++++++++----- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/heatclient/openstack/common/apiclient/base.py b/heatclient/openstack/common/apiclient/base.py index 193494d9..d3d772ca 100644 --- a/heatclient/openstack/common/apiclient/base.py +++ b/heatclient/openstack/common/apiclient/base.py @@ -402,7 +402,7 @@ class CrudManager(BaseManager): 'name': self.resource_class.__name__, 'args': kwargs } - raise exceptions.NotFound(404, msg) + raise exceptions.NotFound(msg) elif num > 1: raise exceptions.NoUniqueMatch else: diff --git a/heatclient/openstack/common/apiclient/exceptions.py b/heatclient/openstack/common/apiclient/exceptions.py index d151a150..247db55e 100644 --- a/heatclient/openstack/common/apiclient/exceptions.py +++ b/heatclient/openstack/common/apiclient/exceptions.py @@ -20,6 +20,19 @@ Exception definitions. """ +######################################################################## +# +# THIS MODULE IS DEPRECATED +# +# Please refer to +# https://etherpad.openstack.org/p/kilo-oslo-library-proposals for +# the discussion leading to this deprecation. +# +# We recommend checking out the python-openstacksdk project +# (https://launchpad.net/python-openstacksdk) instead. +# +######################################################################## + import inspect import sys @@ -54,11 +67,16 @@ class AuthorizationFailure(ClientException): pass -class ConnectionRefused(ClientException): +class ConnectionError(ClientException): """Cannot connect to API service.""" pass +class ConnectionRefused(ConnectionError): + """Connection refused while trying to connect to API service.""" + pass + + class AuthPluginOptionsMissing(AuthorizationFailure): """Auth plugin misses some options.""" def __init__(self, opt_names): @@ -72,7 +90,7 @@ class AuthSystemNotFound(AuthorizationFailure): """User has specified an AuthSystem that is not installed.""" def __init__(self, auth_system): super(AuthSystemNotFound, self).__init__( - _("AuthSystemNotFound: %s") % repr(auth_system)) + _("AuthSystemNotFound: %r") % auth_system) self.auth_system = auth_system @@ -95,7 +113,7 @@ class AmbiguousEndpoints(EndpointException): """Found more than one matching endpoint in Service Catalog.""" def __init__(self, endpoints=None): super(AmbiguousEndpoints, self).__init__( - _("AmbiguousEndpoints: %s") % repr(endpoints)) + _("AmbiguousEndpoints: %r") % endpoints) self.endpoints = endpoints @@ -115,9 +133,9 @@ class HttpError(ClientException): self.response = response self.url = url self.method = method - formatted_string = _("%s (HTTP %s)") % (self.message, self.http_status) + formatted_string = "%s (HTTP %s)" % (self.message, self.http_status) if request_id: - formatted_string += _(" (Request-ID: %s)") % request_id + formatted_string += " (Request-ID: %s)" % request_id super(HttpError, self).__init__(formatted_string) @@ -439,12 +457,15 @@ def from_response(response, method, url): except ValueError: pass else: - if isinstance(body, dict) and isinstance(body.get("error"), dict): - error = body["error"] - kwargs["message"] = error.get("message") - kwargs["details"] = error.get("details") + if isinstance(body, dict): + error = body.get(list(body)[0]) + if isinstance(error, dict): + kwargs["message"] = (error.get("message") or + error.get("faultstring")) + kwargs["details"] = (error.get("details") or + six.text_type(body)) elif content_type.startswith("text/"): - kwargs["details"] = response.text + kwargs["details"] = getattr(response, 'text', '') try: cls = _code_map[response.status_code]