summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhishek Kekane <abhishek.kekane@nttdata.com>2017-03-09 13:20:13 +0530
committerAbhishek Kekane <abhishek.kekane@nttdata.com>2017-05-29 17:56:11 +0530
commit60c06d526c228de314ad659bda57c42750852ef9 (patch)
tree58b646b9e92bbbb2fe6df33ee8a7a9713bbcaf4a
parent3338ed91d4b9a0a33885d48969d71de0d30bed7e (diff)
downloadpython-glanceclient-60c06d526c228de314ad659bda57c42750852ef9.tar.gz
Downloading image with --progress fails
Downloading image with --progress fails with "RequestIdProxy object is not an iterator". This is because to display download progress VerboseFileWrapper in progressbar requires object of IterableWithLength, but after support of returning request-id [1] to caller it returns RequestIdProxy object which is wrapped around IterableWithLength and response. To resolve this issue overridden next and __next__ methods in RequestIdProxy so that it can act as iterator for python 2.x and 3.x as well. [1] 610177a779b95f931356c1e90b05a5bffd2616b3 Closes-Bug: #1670464 Change-Id: I188e67c2487b7e4178ea246f02154bbcbc35a2b1
-rw-r--r--glanceclient/common/utils.py7
-rw-r--r--glanceclient/tests/unit/test_progressbar.py7
2 files changed, 13 insertions, 1 deletions
diff --git a/glanceclient/common/utils.py b/glanceclient/common/utils.py
index 3c10e4d..0c1d986 100644
--- a/glanceclient/common/utils.py
+++ b/glanceclient/common/utils.py
@@ -494,6 +494,13 @@ class RequestIdProxy(wrapt.ObjectProxy):
def wrapped(self):
return self._self_wrapped
+ # Overriden next method to act as iterator
+ def next(self):
+ return next(self._self_wrapped)
+
+ # In Python 3, __next__() has replaced next().
+ __next__ = next
+
class GeneratorProxy(wrapt.ObjectProxy):
def __init__(self, wrapped):
diff --git a/glanceclient/tests/unit/test_progressbar.py b/glanceclient/tests/unit/test_progressbar.py
index 1841cd0..76f96fb 100644
--- a/glanceclient/tests/unit/test_progressbar.py
+++ b/glanceclient/tests/unit/test_progressbar.py
@@ -15,6 +15,7 @@
import sys
+import requests
import six
import testtools
@@ -27,12 +28,16 @@ class TestProgressBarWrapper(testtools.TestCase):
def test_iter_iterator_display_progress_bar(self):
size = 100
+ # create fake response object to return request-id with iterator
+ resp = requests.Response()
+ resp.headers['x-openstack-request-id'] = 'req-1234'
iterator_with_len = utils.IterableWithLength(iter('X' * 100), size)
+ requestid_proxy = utils.RequestIdProxy((iterator_with_len, resp))
saved_stdout = sys.stdout
try:
sys.stdout = output = test_utils.FakeTTYStdout()
# Consume iterator.
- data = list(progressbar.VerboseIteratorWrapper(iterator_with_len,
+ data = list(progressbar.VerboseIteratorWrapper(requestid_proxy,
size))
self.assertEqual(['X'] * 100, data)
self.assertEqual(