Fix Requests breaking download progress bar
The move to the requests library (dbb242b) broke the progress bar during
downloading an image with --progress enabled, due to requests returning
a generator, which has no __len__ function. This patch adds an iterable
wrapper which provides the length, sourced from Content-Length headers.
Closes-Bug: #1384664
Change-Id: I48598a824396bc6e7cba69eb3ce32e7c8f30a18a
This commit is contained in:
@@ -140,14 +140,15 @@ class ImageManager(base.ManagerWithFind):
|
||||
image_id = base.getid(image)
|
||||
resp, body = self.client.get('/v1/images/%s'
|
||||
% urlparse.quote(str(image_id)))
|
||||
content_length = int(resp.headers.get('content-length', 0))
|
||||
checksum = resp.headers.get('x-image-meta-checksum', None)
|
||||
if do_checksum and checksum is not None:
|
||||
return utils.integrity_iter(body, checksum)
|
||||
body = utils.integrity_iter(body, checksum)
|
||||
return_request_id = kwargs.get('return_req_id', None)
|
||||
if return_request_id is not None:
|
||||
return_request_id.append(resp.headers.get(OS_REQ_ID_HDR, None))
|
||||
|
||||
return body
|
||||
return utils.IterableWithLength(body, content_length)
|
||||
|
||||
def list(self, **kwargs):
|
||||
"""Get a list of images.
|
||||
|
||||
Reference in New Issue
Block a user