Include transaction ID on content-check failures
Change-Id: I6b667db26ffc5dccdcadfc8c73f7accb81f03dac
This commit is contained in:
@@ -419,6 +419,9 @@ class _SwiftReader:
|
|||||||
def __init__(self, path, body, headers, checksum=True):
|
def __init__(self, path, body, headers, checksum=True):
|
||||||
self._path = path
|
self._path = path
|
||||||
self._body = body
|
self._body = body
|
||||||
|
self._txn_id = headers.get('x-openstack-request-id')
|
||||||
|
if self._txn_id is None:
|
||||||
|
self._txn_id = headers.get('x-trans-id')
|
||||||
self._actual_read = 0
|
self._actual_read = 0
|
||||||
self._content_length = None
|
self._content_length = None
|
||||||
self._actual_md5 = None
|
self._actual_md5 = None
|
||||||
@@ -459,17 +462,20 @@ class _SwiftReader:
|
|||||||
def _check_contents(self):
|
def _check_contents(self):
|
||||||
if (self._content_length is not None and
|
if (self._content_length is not None and
|
||||||
self._actual_read != self._content_length):
|
self._actual_read != self._content_length):
|
||||||
raise SwiftError('Error downloading {0}: read_length != '
|
raise SwiftError(
|
||||||
'content_length, {1:d} != {2:d}'.format(
|
'Error downloading {0}: read_length != content_length, '
|
||||||
self._path, self._actual_read,
|
'{1:d} != {2:d} (txn: {3})'.format(
|
||||||
self._content_length))
|
self._path, self._actual_read, self._content_length,
|
||||||
|
self._txn_id or 'unknown'))
|
||||||
|
|
||||||
if self._actual_md5 and self._expected_md5:
|
if self._actual_md5 and self._expected_md5:
|
||||||
etag = self._actual_md5.hexdigest()
|
etag = self._actual_md5.hexdigest()
|
||||||
if etag != self._expected_md5:
|
if etag != self._expected_md5:
|
||||||
raise SwiftError('Error downloading {0}: md5sum != etag, '
|
raise SwiftError(
|
||||||
'{1} != {2}'.format(
|
'Error downloading {0}: md5sum != etag, '
|
||||||
self._path, etag, self._expected_md5))
|
'{1} != {2} (txn: {3})'.format(
|
||||||
|
self._path, etag, self._expected_md5,
|
||||||
|
self._txn_id or 'unknown'))
|
||||||
|
|
||||||
def bytes_read(self):
|
def bytes_read(self):
|
||||||
return self._actual_read
|
return self._actual_read
|
||||||
|
@@ -201,7 +201,19 @@ class TestSwiftReader(unittest.TestCase):
|
|||||||
with self.assertRaises(SwiftError) as cm:
|
with self.assertRaises(SwiftError) as cm:
|
||||||
_consume(sr)
|
_consume(sr)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"'Error downloading path: read_length != content_length, 4 != 5'",
|
"'Error downloading path: read_length != content_length, "
|
||||||
|
"4 != 5 (txn: unknown)'",
|
||||||
|
str(cm.exception))
|
||||||
|
|
||||||
|
# Check error includes txn id if available
|
||||||
|
sr = self.sr('path', BytesIO(b'body'), {'content-length': 5,
|
||||||
|
'etag': 'bad etag',
|
||||||
|
'x-trans-id': 'uuid'})
|
||||||
|
with self.assertRaises(SwiftError) as cm:
|
||||||
|
_consume(sr)
|
||||||
|
self.assertEqual(
|
||||||
|
"'Error downloading path: read_length != content_length, "
|
||||||
|
"4 != 5 (txn: uuid)'",
|
||||||
str(cm.exception))
|
str(cm.exception))
|
||||||
|
|
||||||
# Check error is raised if SwiftReader doesn't calculate the expected
|
# Check error is raised if SwiftReader doesn't calculate the expected
|
||||||
@@ -212,7 +224,7 @@ class TestSwiftReader(unittest.TestCase):
|
|||||||
_consume(sr)
|
_consume(sr)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"'Error downloading path: md5sum != etag, "
|
"'Error downloading path: md5sum != etag, "
|
||||||
"841a2d689ad86bd1611447453c22c6fc != bad etag'",
|
"841a2d689ad86bd1611447453c22c6fc != bad etag (txn: unknown)'",
|
||||||
str(cm.exception))
|
str(cm.exception))
|
||||||
|
|
||||||
sr = self.sr('path', BytesIO(b'body'), {'content-length': 4})
|
sr = self.sr('path', BytesIO(b'body'), {'content-length': 4})
|
||||||
|
Reference in New Issue
Block a user