From 54de326a297f29f0872e4192d8bd338984b5f508 Mon Sep 17 00:00:00 2001 From: Dougal Matthews Date: Tue, 20 Jan 2015 11:43:45 +0000 Subject: [PATCH] Sync with oslo-incubator Change-Id: I6119906951adec95b30f47f355c664f245f66703 --- tuskarclient/openstack/common/_i18n.py | 43 +++++++++++-------- .../openstack/common/apiclient/auth.py | 13 ++++++ .../openstack/common/apiclient/base.py | 14 ++++++ .../openstack/common/apiclient/client.py | 2 +- .../openstack/common/apiclient/exceptions.py | 35 ++++++++++++--- .../openstack/common/apiclient/fake_client.py | 13 ++++++ .../openstack/common/apiclient/utils.py | 13 ++++++ tuskarclient/openstack/common/cliutils.py | 11 ++++- tuskarclient/openstack/common/uuidutils.py | 2 +- 9 files changed, 116 insertions(+), 30 deletions(-) diff --git a/tuskarclient/openstack/common/_i18n.py b/tuskarclient/openstack/common/_i18n.py index 51d97b9..3d37afb 100644 --- a/tuskarclient/openstack/common/_i18n.py +++ b/tuskarclient/openstack/common/_i18n.py @@ -16,25 +16,30 @@ See http://docs.openstack.org/developer/oslo.i18n/usage.html """ -import oslo.i18n +try: + import oslo.i18n + # NOTE(dhellmann): This reference to o-s-l-o will be replaced by the + # application name when this module is synced into the separate + # repository. It is OK to have more than one translation function + # using the same domain, since there will still only be one message + # catalog. + _translators = oslo.i18n.TranslatorFactory(domain='tuskarclient') -# NOTE(dhellmann): This reference to o-s-l-o will be replaced by the -# application name when this module is synced into the separate -# repository. It is OK to have more than one translation function -# using the same domain, since there will still only be one message -# catalog. -_translators = oslo.i18n.TranslatorFactory(domain='tuskarclient') + # The primary translation function using the well-known name "_" + _ = _translators.primary -# The primary translation function using the well-known name "_" -_ = _translators.primary - -# Translators for log levels. -# -# The abbreviated names are meant to reflect the usual use of a short -# name like '_'. The "L" is for "log" and the other letter comes from -# the level. -_LI = _translators.log_info -_LW = _translators.log_warning -_LE = _translators.log_error -_LC = _translators.log_critical + # Translators for log levels. + # + # The abbreviated names are meant to reflect the usual use of a short + # name like '_'. The "L" is for "log" and the other letter comes from + # the level. + _LI = _translators.log_info + _LW = _translators.log_warning + _LE = _translators.log_error + _LC = _translators.log_critical +except ImportError: + # NOTE(dims): Support for cases where a project wants to use + # code from oslo-incubator, but is not ready to be internationalized + # (like tempest) + _ = _LI = _LW = _LE = _LC = lambda x: x diff --git a/tuskarclient/openstack/common/apiclient/auth.py b/tuskarclient/openstack/common/apiclient/auth.py index ab8763b..70a995f 100644 --- a/tuskarclient/openstack/common/apiclient/auth.py +++ b/tuskarclient/openstack/common/apiclient/auth.py @@ -17,6 +17,19 @@ # E0202: An attribute inherited from %s hide this method # pylint: disable=E0202 +######################################################################## +# +# THIS MODULE IS DEPRECATED +# +# Please refer to +# https://etherpad.openstack.org/p/kilo-tuskarclient-library-proposals for +# the discussion leading to this deprecation. +# +# We recommend checking out the python-openstacksdk project +# (https://launchpad.net/python-openstacksdk) instead. +# +######################################################################## + import abc import argparse import os diff --git a/tuskarclient/openstack/common/apiclient/base.py b/tuskarclient/openstack/common/apiclient/base.py index d627635..7a02aeb 100644 --- a/tuskarclient/openstack/common/apiclient/base.py +++ b/tuskarclient/openstack/common/apiclient/base.py @@ -20,6 +20,20 @@ Base utilities to build API operation managers and objects on top of. """ +######################################################################## +# +# THIS MODULE IS DEPRECATED +# +# Please refer to +# https://etherpad.openstack.org/p/kilo-tuskarclient-library-proposals for +# the discussion leading to this deprecation. +# +# We recommend checking out the python-openstacksdk project +# (https://launchpad.net/python-openstacksdk) instead. +# +######################################################################## + + # E1102: %s is not callable # pylint: disable=E1102 diff --git a/tuskarclient/openstack/common/apiclient/client.py b/tuskarclient/openstack/common/apiclient/client.py index 2b49c9e..a80747c 100644 --- a/tuskarclient/openstack/common/apiclient/client.py +++ b/tuskarclient/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/tuskarclient/openstack/common/apiclient/exceptions.py b/tuskarclient/openstack/common/apiclient/exceptions.py index 9f941b8..77615a7 100644 --- a/tuskarclient/openstack/common/apiclient/exceptions.py +++ b/tuskarclient/openstack/common/apiclient/exceptions.py @@ -20,6 +20,19 @@ Exception definitions. """ +######################################################################## +# +# THIS MODULE IS DEPRECATED +# +# Please refer to +# https://etherpad.openstack.org/p/kilo-tuskarclient-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 @@ -439,10 +457,13 @@ 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 diff --git a/tuskarclient/openstack/common/apiclient/fake_client.py b/tuskarclient/openstack/common/apiclient/fake_client.py index 0391e0c..d43117a 100644 --- a/tuskarclient/openstack/common/apiclient/fake_client.py +++ b/tuskarclient/openstack/common/apiclient/fake_client.py @@ -21,6 +21,19 @@ wrong the tests might raise AssertionError. I've indicated in comments the places where actual behavior differs from the spec. """ +######################################################################## +# +# THIS MODULE IS DEPRECATED +# +# Please refer to +# https://etherpad.openstack.org/p/kilo-tuskarclient-library-proposals for +# the discussion leading to this deprecation. +# +# We recommend checking out the python-openstacksdk project +# (https://launchpad.net/python-openstacksdk) instead. +# +######################################################################## + # W0102: Dangerous default value %s as argument # pylint: disable=W0102 diff --git a/tuskarclient/openstack/common/apiclient/utils.py b/tuskarclient/openstack/common/apiclient/utils.py index 648862e..e67912b 100644 --- a/tuskarclient/openstack/common/apiclient/utils.py +++ b/tuskarclient/openstack/common/apiclient/utils.py @@ -11,6 +11,19 @@ # License for the specific language governing permissions and limitations # under the License. +######################################################################## +# +# THIS MODULE IS DEPRECATED +# +# Please refer to +# https://etherpad.openstack.org/p/kilo-tuskarclient-library-proposals for +# the discussion leading to this deprecation. +# +# We recommend checking out the python-openstacksdk project +# (https://launchpad.net/python-openstacksdk) instead. +# +######################################################################## + from oslo.utils import encodeutils import six diff --git a/tuskarclient/openstack/common/cliutils.py b/tuskarclient/openstack/common/cliutils.py index 21c98b9..a1cc1d0 100644 --- a/tuskarclient/openstack/common/cliutils.py +++ b/tuskarclient/openstack/common/cliutils.py @@ -180,7 +180,10 @@ def print_list(objs, fields, formatters=None, sortby_index=0, row.append(data) pt.add_row(row) - print(encodeutils.safe_encode(pt.get_string(**kwargs))) + if six.PY3: + print(encodeutils.safe_encode(pt.get_string(**kwargs)).decode()) + else: + print(encodeutils.safe_encode(pt.get_string(**kwargs))) def print_dict(dct, dict_property="Property", wrap=0): @@ -208,7 +211,11 @@ def print_dict(dct, dict_property="Property", wrap=0): col1 = '' else: pt.add_row([k, v]) - print(encodeutils.safe_encode(pt.get_string())) + + if six.PY3: + print(encodeutils.safe_encode(pt.get_string()).decode()) + else: + print(encodeutils.safe_encode(pt.get_string())) def get_password(max_password_prompts=3): diff --git a/tuskarclient/openstack/common/uuidutils.py b/tuskarclient/openstack/common/uuidutils.py index 234b880..69a78b9 100644 --- a/tuskarclient/openstack/common/uuidutils.py +++ b/tuskarclient/openstack/common/uuidutils.py @@ -32,6 +32,6 @@ def is_uuid_like(val): """ try: - return str(uuid.UUID(val)) == val + return str(uuid.UUID(val)).lower() == val.lower() except (TypeError, ValueError, AttributeError): return False