diff options
author | Tim Burke <tim.burke@gmail.com> | 2023-03-14 11:52:50 -0700 |
---|---|---|
committer | Tim Burke <tim.burke@gmail.com> | 2023-03-15 12:37:02 -0700 |
commit | e3432982405a8446ca2c7384334fa9c6d10a6271 (patch) | |
tree | 7bc57aa61a4393b313c92d44b79457c1aa87604e /swiftclient | |
parent | d572ccfae9328e205a39559f2f83ed5c844231c5 (diff) | |
download | python-swiftclient-e3432982405a8446ca2c7384334fa9c6d10a6271.tar.gz |
Include transaction ID on content-check failures
Change-Id: I6b667db26ffc5dccdcadfc8c73f7accb81f03dac
Diffstat (limited to 'swiftclient')
-rw-r--r-- | swiftclient/service.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/swiftclient/service.py b/swiftclient/service.py index d1c98d6..e905ea6 100644 --- a/swiftclient/service.py +++ b/swiftclient/service.py @@ -419,6 +419,9 @@ class _SwiftReader: def __init__(self, path, body, headers, checksum=True): self._path = path 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._content_length = None self._actual_md5 = None @@ -459,17 +462,20 @@ class _SwiftReader: def _check_contents(self): if (self._content_length is not None and self._actual_read != self._content_length): - raise SwiftError('Error downloading {0}: read_length != ' - 'content_length, {1:d} != {2:d}'.format( - self._path, self._actual_read, - self._content_length)) + raise SwiftError( + 'Error downloading {0}: read_length != content_length, ' + '{1:d} != {2:d} (txn: {3})'.format( + self._path, self._actual_read, self._content_length, + self._txn_id or 'unknown')) if self._actual_md5 and self._expected_md5: etag = self._actual_md5.hexdigest() if etag != self._expected_md5: - raise SwiftError('Error downloading {0}: md5sum != etag, ' - '{1} != {2}'.format( - self._path, etag, self._expected_md5)) + raise SwiftError( + 'Error downloading {0}: md5sum != etag, ' + '{1} != {2} (txn: {3})'.format( + self._path, etag, self._expected_md5, + self._txn_id or 'unknown')) def bytes_read(self): return self._actual_read |