Show a pretty progressbar when uploading and downloading an image.
Add a new module that contain generic wrapper for file and iterator, which are used to wrap image to upload and the request body iterator in upload and download cases repectively, to show and advance a pretty progress bar when this laters are consumed, The progress bar is triggered by adding a --progress command line argument to commands: image-create, image-download or image-update. Change-Id: I2ba42fd0c58f4fa087adb568ec3f08246cae3759 bug fix: LP#1112309 blueprint: progressbar-when-uploading
This commit is contained in:
@@ -15,11 +15,16 @@
|
||||
# under the License.
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
import StringIO
|
||||
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
from glanceclient.common import http
|
||||
from glanceclient.common import progressbar
|
||||
from glanceclient.common import utils
|
||||
from glanceclient.v2 import shell as test_shell
|
||||
from tests import utils as test_utils
|
||||
|
||||
|
||||
class ShellV2Test(testtools.TestCase):
|
||||
@@ -109,15 +114,32 @@ class ShellV2Test(testtools.TestCase):
|
||||
self.gc.schemas.get.assert_called_once_with('test')
|
||||
|
||||
def test_image_download(self):
|
||||
args = self._make_args({'id': 'pass', 'file': 'test'})
|
||||
args = self._make_args(
|
||||
{'id': 'pass', 'file': 'test', 'progress': False})
|
||||
|
||||
with mock.patch.object(self.gc.images, 'data') as mocked_data:
|
||||
mocked_data.return_value = 'test_passed'
|
||||
|
||||
resp = test_utils.FakeResponse({}, StringIO.StringIO('CCC'))
|
||||
ret = mocked_data.return_value = http.ResponseBodyIterator(resp)
|
||||
test_shell.do_image_download(self.gc, args)
|
||||
|
||||
mocked_data.assert_called_once_with('pass')
|
||||
utils.save_image.assert_called_once_with('test_passed', 'test')
|
||||
utils.save_image.assert_called_once_with(ret, 'test')
|
||||
|
||||
def test_image_download_with_progressbar(self):
|
||||
args = self._make_args(
|
||||
{'id': 'pass', 'file': 'test', 'progress': True})
|
||||
|
||||
with mock.patch.object(self.gc.images, 'data') as mocked_data:
|
||||
resp = test_utils.FakeResponse({}, StringIO.StringIO('CCC'))
|
||||
mocked_data.return_value = http.ResponseBodyIterator(resp)
|
||||
test_shell.do_image_download(self.gc, args)
|
||||
|
||||
mocked_data.assert_called_once_with('pass')
|
||||
utils.save_image.assert_called_once_with(mock.ANY, 'test')
|
||||
self.assertIsInstance(
|
||||
utils.save_image.call_args[0][0],
|
||||
progressbar.VerboseIteratorWrapper
|
||||
)
|
||||
|
||||
def test_do_image_delete(self):
|
||||
args = self._make_args({'id': 'pass', 'file': 'test'})
|
||||
|
||||
Reference in New Issue
Block a user