Merge "Verbose functional test request failures."

This commit is contained in:
Jenkins 2013-09-12 20:37:33 +00:00 committed by Gerrit Code Review
commit 63e0c01a23
3 changed files with 27 additions and 17 deletions

View File

@ -18,6 +18,20 @@
import sys
import os
try:
from unittest.util import safe_repr
except ImportError:
# Probably py26
_MAX_LENGTH = 80
def safe_repr(obj, short=False):
try:
result = repr(obj)
except Exception:
result = object.__repr__(obj)
if not short or len(result) < _MAX_LENGTH:
return result
return result[:_MAX_LENGTH] + ' [truncated]...'
# make unittests pass on all locale
import swift

View File

@ -28,6 +28,8 @@ from nose import SkipTest
from xml.dom import minidom
from swiftclient import get_auth
from test import safe_repr
class AuthenticationFailed(Exception):
pass
@ -216,18 +218,22 @@ class Connection(object):
self.response = None
try_count = 0
fail_messages = []
while try_count < 5:
try_count += 1
try:
self.response = try_request()
except httplib.HTTPException:
except httplib.HTTPException as e:
fail_messages.append(safe_repr(e))
continue
if self.response.status == 401:
fail_messages.append("Response 401")
self.authenticate()
continue
elif self.response.status == 503:
fail_messages.append("Response 503")
if try_count != 5:
time.sleep(5)
continue
@ -237,7 +243,11 @@ class Connection(object):
if self.response:
return self.response.status
raise RequestError('Unable to complete http request')
request = "{method} {path} headers: {headers} data: {data}".format(
method=method, path=path, headers=headers, data=data)
raise RequestError('Unable to complete http request: %s. '
'Attempts: %s, Failures: %s' %
(request, len(fail_messages), fail_messages))
def put_start(self, path, hdrs={}, parms={}, cfg={}, chunked=False):
self.http_connect()

View File

@ -14,23 +14,9 @@
# limitations under the License.
import unittest
try:
from unittest.util import safe_repr
except ImportError:
# Probably py26
_MAX_LENGTH = 80
def safe_repr(obj, short=False):
try:
result = repr(obj)
except Exception:
result = object.__repr__(obj)
if not short or len(result) < _MAX_LENGTH:
return result
return result[:_MAX_LENGTH] + ' [truncated]...'
import mock
from test import safe_repr
from test.unit import MockTrue
from swift.common.swob import HTTPBadRequest, Request