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 sys
import os 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 # make unittests pass on all locale
import swift import swift

View File

@ -28,6 +28,8 @@ from nose import SkipTest
from xml.dom import minidom from xml.dom import minidom
from swiftclient import get_auth from swiftclient import get_auth
from test import safe_repr
class AuthenticationFailed(Exception): class AuthenticationFailed(Exception):
pass pass
@ -216,18 +218,22 @@ class Connection(object):
self.response = None self.response = None
try_count = 0 try_count = 0
fail_messages = []
while try_count < 5: while try_count < 5:
try_count += 1 try_count += 1
try: try:
self.response = try_request() self.response = try_request()
except httplib.HTTPException: except httplib.HTTPException as e:
fail_messages.append(safe_repr(e))
continue continue
if self.response.status == 401: if self.response.status == 401:
fail_messages.append("Response 401")
self.authenticate() self.authenticate()
continue continue
elif self.response.status == 503: elif self.response.status == 503:
fail_messages.append("Response 503")
if try_count != 5: if try_count != 5:
time.sleep(5) time.sleep(5)
continue continue
@ -237,7 +243,11 @@ class Connection(object):
if self.response: if self.response:
return self.response.status 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): def put_start(self, path, hdrs={}, parms={}, cfg={}, chunked=False):
self.http_connect() self.http_connect()

View File

@ -14,23 +14,9 @@
# limitations under the License. # limitations under the License.
import unittest 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 import mock
from test import safe_repr
from test.unit import MockTrue from test.unit import MockTrue
from swift.common.swob import HTTPBadRequest, Request from swift.common.swob import HTTPBadRequest, Request