Merge "Add logging of non-standard error message documents"

This commit is contained in:
Jenkins 2017-06-02 13:09:30 +00:00 committed by Gerrit Code Review
commit fdd67b8396
2 changed files with 35 additions and 0 deletions

View File

@ -53,6 +53,13 @@ def simple_logging(debug=False, http_debug=False):
log = _log.setup_logging('keystoneauth')
log.addHandler(logging.StreamHandler())
log.setLevel(log_level)
# We only want extra shade HTTP tracing in http debug mode
log = _log.setup_logging('shade.http')
log.setLevel(log_level)
else:
# We only want extra shade HTTP tracing in http debug mode
log = _log.setup_logging('shade.http')
log.setLevel(logging.WARNING)
# Simple case - we only care about request id log during debug
log = _log.setup_logging('shade.request_ids')
log.setLevel(log_level)

View File

@ -88,6 +88,32 @@ class OpenStackCloudURINotFound(OpenStackCloudHTTPError):
OpenStackCloudResourceNotFound = OpenStackCloudURINotFound
def _log_response_extras(response):
# Sometimes we get weird HTML errors. This is usually from load balancers
# or other things. Log them to a special logger so that they can be
# toggled indepdently - and at debug level so that a person logging
# shade.* only gets them at debug.
if response.headers.get('content-type') != 'text/html':
return
try:
if int(response.headers.get('content-length', 0)) == 0:
return
except Exception:
return
logger = _log.setup_logging('shade.http')
if response.reason:
logger.debug(
"Non-standard error '{reason}' returned from {url}:".format(
reason=response.reason,
url=response.url))
else:
logger.debug(
"Non-standard error returned from {url}:".format(
url=response.url))
for response_line in response.text.split('\n'):
logger.debug(response_line)
# Logic shamelessly stolen from requests
def raise_from_response(response, error_message=None):
msg = ''
@ -113,6 +139,8 @@ def raise_from_response(response, error_message=None):
if response.reason:
remote_error += " {reason}".format(reason=response.reason)
_log_response_extras(response)
if error_message:
msg = '{error_message}. ({code}) {source} {remote_error}'.format(
error_message=error_message,