Merge "Sync latest code from oslo-incubator"

This commit is contained in:
Jenkins 2015-05-08 18:52:14 +00:00 committed by Gerrit Code Review
commit f2b762733a
7 changed files with 131 additions and 36 deletions

@ -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='novaclient')
# NOTE(dhellmann): This reference to o-s-l-o will be replaced by the # The primary translation function using the well-known name "_"
# application name when this module is synced into the separate _ = _translators.primary
# 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='novaclient')
# The primary translation function using the well-known name "_" # Translators for log levels.
_ = _translators.primary #
# The abbreviated names are meant to reflect the usual use of a short
# Translators for log levels. # name like '_'. The "L" is for "log" and the other letter comes from
# # the level.
# The abbreviated names are meant to reflect the usual use of a short _LI = _translators.log_info
# name like '_'. The "L" is for "log" and the other letter comes from _LW = _translators.log_warning
# the level. _LE = _translators.log_error
_LI = _translators.log_info _LC = _translators.log_critical
_LW = _translators.log_warning except ImportError:
_LE = _translators.log_error # NOTE(dims): Support for cases where a project wants to use
_LC = _translators.log_critical # code from oslo-incubator, but is not ready to be internationalized
# (like tempest)
_ = _LI = _LW = _LE = _LC = lambda x: x

@ -17,6 +17,19 @@
# E0202: An attribute inherited from %s hide this method # E0202: An attribute inherited from %s hide this method
# pylint: disable=E0202 # pylint: disable=E0202
########################################################################
#
# THIS MODULE IS DEPRECATED
#
# Please refer to
# https://etherpad.openstack.org/p/kilo-novaclient-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 abc
import argparse import argparse
import os import os

@ -25,6 +25,7 @@ OpenStack Client interface. Handles the REST calls and responses.
# E0202: An attribute inherited from %s hide this method # E0202: An attribute inherited from %s hide this method
# pylint: disable=E0202 # pylint: disable=E0202
import hashlib
import logging import logging
import time import time
@ -33,14 +34,15 @@ try:
except ImportError: except ImportError:
import json import json
from oslo.utils import importutils from oslo_utils import encodeutils
from oslo_utils import importutils
import requests import requests
from novaclient.openstack.common._i18n import _ from novaclient.openstack.common._i18n import _
from novaclient.openstack.common.apiclient import exceptions from novaclient.openstack.common.apiclient import exceptions
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
SENSITIVE_HEADERS = ('X-Auth-Token', 'X-Subject-Token',)
class HTTPClient(object): class HTTPClient(object):
@ -98,6 +100,18 @@ class HTTPClient(object):
self.http = http or requests.Session() self.http = http or requests.Session()
self.cached_token = None self.cached_token = None
self.last_request_id = None
def _safe_header(self, name, value):
if name in SENSITIVE_HEADERS:
# because in python3 byte string handling is ... ug
v = value.encode('utf-8')
h = hashlib.sha1(v)
d = h.hexdigest()
return encodeutils.safe_decode(name), "{SHA1}%s" % d
else:
return (encodeutils.safe_decode(name),
encodeutils.safe_decode(value))
def _http_log_req(self, method, url, kwargs): def _http_log_req(self, method, url, kwargs):
if not self.debug: if not self.debug:
@ -110,7 +124,8 @@ class HTTPClient(object):
] ]
for element in kwargs['headers']: for element in kwargs['headers']:
header = "-H '%s: %s'" % (element, kwargs['headers'][element]) header = ("-H '%s: %s'" %
self._safe_header(element, kwargs['headers'][element]))
string_parts.append(header) string_parts.append(header)
_logger.debug("REQ: %s" % " ".join(string_parts)) _logger.debug("REQ: %s" % " ".join(string_parts))
@ -177,6 +192,8 @@ class HTTPClient(object):
start_time, time.time())) start_time, time.time()))
self._http_log_resp(resp) self._http_log_resp(resp)
self.last_request_id = resp.headers.get('x-openstack-request-id')
if resp.status_code >= 400: if resp.status_code >= 400:
_logger.debug( _logger.debug(
"Request returned failure status: %s", "Request returned failure status: %s",
@ -327,6 +344,10 @@ class BaseClient(object):
return self.http_client.client_request( return self.http_client.client_request(
self, method, url, **kwargs) self, method, url, **kwargs)
@property
def last_request_id(self):
return self.http_client.last_request_id
def head(self, url, **kwargs): def head(self, url, **kwargs):
return self.client_request("HEAD", url, **kwargs) return self.client_request("HEAD", url, **kwargs)

@ -20,6 +20,19 @@
Exception definitions. Exception definitions.
""" """
########################################################################
#
# THIS MODULE IS DEPRECATED
#
# Please refer to
# https://etherpad.openstack.org/p/kilo-novaclient-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 inspect
import sys import sys
@ -54,11 +67,16 @@ class AuthorizationFailure(ClientException):
pass pass
class ConnectionRefused(ClientException): class ConnectionError(ClientException):
"""Cannot connect to API service.""" """Cannot connect to API service."""
pass pass
class ConnectionRefused(ConnectionError):
"""Connection refused while trying to connect to API service."""
pass
class AuthPluginOptionsMissing(AuthorizationFailure): class AuthPluginOptionsMissing(AuthorizationFailure):
"""Auth plugin misses some options.""" """Auth plugin misses some options."""
def __init__(self, opt_names): def __init__(self, opt_names):
@ -72,7 +90,7 @@ class AuthSystemNotFound(AuthorizationFailure):
"""User has specified an AuthSystem that is not installed.""" """User has specified an AuthSystem that is not installed."""
def __init__(self, auth_system): def __init__(self, auth_system):
super(AuthSystemNotFound, self).__init__( super(AuthSystemNotFound, self).__init__(
_("AuthSystemNotFound: %s") % repr(auth_system)) _("AuthSystemNotFound: %r") % auth_system)
self.auth_system = auth_system self.auth_system = auth_system
@ -95,7 +113,7 @@ class AmbiguousEndpoints(EndpointException):
"""Found more than one matching endpoint in Service Catalog.""" """Found more than one matching endpoint in Service Catalog."""
def __init__(self, endpoints=None): def __init__(self, endpoints=None):
super(AmbiguousEndpoints, self).__init__( super(AmbiguousEndpoints, self).__init__(
_("AmbiguousEndpoints: %s") % repr(endpoints)) _("AmbiguousEndpoints: %r") % endpoints)
self.endpoints = endpoints self.endpoints = endpoints
@ -439,12 +457,15 @@ def from_response(response, method, url):
except ValueError: except ValueError:
pass pass
else: else:
if isinstance(body, dict) and isinstance(body.get("error"), dict): if isinstance(body, dict):
error = body["error"] error = body.get(list(body)[0])
kwargs["message"] = error.get("message") if isinstance(error, dict):
kwargs["details"] = error.get("details") kwargs["message"] = (error.get("message") or
error.get("faultstring"))
kwargs["details"] = (error.get("details") or
six.text_type(body))
elif content_type.startswith("text/"): elif content_type.startswith("text/"):
kwargs["details"] = response.text kwargs["details"] = getattr(response, 'text', '')
try: try:
cls = _code_map[response.status_code] cls = _code_map[response.status_code]

@ -21,6 +21,19 @@ wrong the tests might raise AssertionError. I've indicated in comments the
places where actual behavior differs from the spec. places where actual behavior differs from the spec.
""" """
########################################################################
#
# THIS MODULE IS DEPRECATED
#
# Please refer to
# https://etherpad.openstack.org/p/kilo-novaclient-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 # W0102: Dangerous default value %s as argument
# pylint: disable=W0102 # pylint: disable=W0102
@ -168,6 +181,8 @@ class FakeHTTPClient(client.HTTPClient):
else: else:
status, body = resp status, body = resp
headers = {} headers = {}
self.last_request_id = headers.get('x-openstack-request-id',
'req-test')
return TestResponse({ return TestResponse({
"status_code": status, "status_code": status,
"text": body, "text": body,

@ -11,12 +11,25 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo.utils import encodeutils ########################################################################
#
# THIS MODULE IS DEPRECATED
#
# Please refer to
# https://etherpad.openstack.org/p/kilo-novaclient-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
from oslo_utils import uuidutils
import six import six
from novaclient.openstack.common._i18n import _ from novaclient.openstack.common._i18n import _
from novaclient.openstack.common.apiclient import exceptions from novaclient.openstack.common.apiclient import exceptions
from novaclient.openstack.common import uuidutils
def find_resource(manager, name_or_id, **find_args): def find_resource(manager, name_or_id, **find_args):

@ -24,8 +24,8 @@ import os
import sys import sys
import textwrap import textwrap
from oslo.utils import encodeutils from oslo_utils import encodeutils
from oslo.utils import strutils from oslo_utils import strutils
import prettytable import prettytable
import six import six
from six import moves from six import moves
@ -180,7 +180,10 @@ def print_list(objs, fields, formatters=None, sortby_index=0,
row.append(data) row.append(data)
pt.add_row(row) 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): def print_dict(dct, dict_property="Property", wrap=0):
@ -208,7 +211,11 @@ def print_dict(dct, dict_property="Property", wrap=0):
col1 = '' col1 = ''
else: else:
pt.add_row([k, v]) 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): def get_password(max_password_prompts=3):