From 80d8f1a056620725a73bb920861255cd4f82295b Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Sun, 7 Jun 2015 10:13:06 -0400 Subject: [PATCH] Sync from latest oslo-incubator _i18n.py: * typo - probably old update.py script apiclient/base.py: * 18bf5ca Fix usage of NotFound exception in apiclient.base apiclient/client.py: * 002999b Curl statements to include globoff for IPv6 URLs apiclient/utils.py: * a908d66 Remove uuidutils apiclient/exceptions.py: * 03e6272 Add ConnectionError exception * 5985b35 Prefer delayed %r formatting over explicit repr use * fd8dc0c Handle different format of api exception Change-Id: Ia8d4d40089cc5577e86c84cd3b20b18ee9259414 --- magnumclient/openstack/common/_i18n.py | 2 +- .../openstack/common/apiclient/base.py | 2 +- .../openstack/common/apiclient/client.py | 2 +- .../openstack/common/apiclient/exceptions.py | 24 ++++++++++++------- .../openstack/common/apiclient/utils.py | 2 +- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/magnumclient/openstack/common/_i18n.py b/magnumclient/openstack/common/_i18n.py index 3cc6d0eb..73ddcb9f 100644 --- a/magnumclient/openstack/common/_i18n.py +++ b/magnumclient/openstack/common/_i18n.py @@ -40,6 +40,6 @@ try: _LC = _translators.log_critical except ImportError: # NOTE(dims): Support for cases where a project wants to use - # code from magnumclient-incubator, but is not ready to be internationalized + # code from oslo-incubator, but is not ready to be internationalized # (like tempest) _ = _LI = _LW = _LE = _LC = lambda x: x diff --git a/magnumclient/openstack/common/apiclient/base.py b/magnumclient/openstack/common/apiclient/base.py index 635cbc64..f6491b17 100644 --- a/magnumclient/openstack/common/apiclient/base.py +++ b/magnumclient/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/magnumclient/openstack/common/apiclient/client.py b/magnumclient/openstack/common/apiclient/client.py index 1c15f532..a6b4f052 100644 --- a/magnumclient/openstack/common/apiclient/client.py +++ b/magnumclient/openstack/common/apiclient/client.py @@ -118,7 +118,7 @@ class HTTPClient(object): return string_parts = [ - "curl -i", + "curl -g -i", "-X '%s'" % method, "'%s'" % url, ] diff --git a/magnumclient/openstack/common/apiclient/exceptions.py b/magnumclient/openstack/common/apiclient/exceptions.py index 341ac3a4..3ce658b0 100644 --- a/magnumclient/openstack/common/apiclient/exceptions.py +++ b/magnumclient/openstack/common/apiclient/exceptions.py @@ -67,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): @@ -85,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 @@ -108,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 @@ -452,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] diff --git a/magnumclient/openstack/common/apiclient/utils.py b/magnumclient/openstack/common/apiclient/utils.py index 635e7c48..8e9da935 100644 --- a/magnumclient/openstack/common/apiclient/utils.py +++ b/magnumclient/openstack/common/apiclient/utils.py @@ -25,11 +25,11 @@ ######################################################################## from oslo_utils import encodeutils +from oslo_utils import uuidutils import six from magnumclient.openstack.common._i18n import _ from magnumclient.openstack.common.apiclient import exceptions -from magnumclient.openstack.common import uuidutils def find_resource(manager, name_or_id, **find_args):