Merge "progress flag not supported in v2 API"
This commit is contained in:
@@ -215,19 +215,24 @@ def do_image_download(gc, args):
|
||||
|
||||
|
||||
@utils.arg('--file', metavar='<FILE>',
|
||||
help=('Local file that contains disk image to be uploaded'
|
||||
' during creation. Alternatively, images can be passed'
|
||||
help=('Local file that contains disk image to be uploaded.'
|
||||
' Alternatively, images can be passed'
|
||||
' to the client via stdin.'))
|
||||
@utils.arg('--size', metavar='<IMAGE_SIZE>', type=int,
|
||||
help='Size in bytes of image to be uploaded. Default is to get '
|
||||
'size from provided data object but this is supported in case '
|
||||
'where size cannot be inferred.',
|
||||
default=None)
|
||||
@utils.arg('--progress', action='store_true', default=False,
|
||||
help='Show upload progress bar.')
|
||||
@utils.arg('id', metavar='<IMAGE_ID>',
|
||||
help='ID of image to upload data to.')
|
||||
def do_image_upload(gc, args):
|
||||
"""Upload data for a specific image."""
|
||||
image_data = utils.get_data_file(args)
|
||||
if args.progress:
|
||||
filesize = utils.get_file_size(image_data)
|
||||
image_data = progressbar.VerboseFileWrapper(image_data, filesize)
|
||||
gc.images.upload(args.id, image_data, args.size)
|
||||
|
||||
|
||||
|
||||
@@ -221,7 +221,8 @@ class ShellV2Test(testtools.TestCase):
|
||||
self.gc.schemas.get.assert_called_once_with('test')
|
||||
|
||||
def test_image_upload(self):
|
||||
args = self._make_args({'id': 'IMG-01', 'file': 'test', 'size': 1024})
|
||||
args = self._make_args(
|
||||
{'id': 'IMG-01', 'file': 'test', 'size': 1024, 'progress': False})
|
||||
|
||||
with mock.patch.object(self.gc.images, 'upload') as mocked_upload:
|
||||
utils.get_data_file = mock.Mock(return_value='testfile')
|
||||
@@ -229,6 +230,18 @@ class ShellV2Test(testtools.TestCase):
|
||||
test_shell.do_image_upload(self.gc, args)
|
||||
mocked_upload.assert_called_once_with('IMG-01', 'testfile', 1024)
|
||||
|
||||
def test_image_upload_with_progressbar(self):
|
||||
args = self._make_args(
|
||||
{'id': 'IMG-01', 'file': 'test', 'size': 1024, 'progress': True})
|
||||
|
||||
with mock.patch.object(self.gc.images, 'upload') as mocked_upload:
|
||||
utils.get_data_file = mock.Mock(return_value='testfile')
|
||||
utils.get_file_size = mock.Mock(return_value=8)
|
||||
mocked_upload.return_value = None
|
||||
test_shell.do_image_upload(self.gc, args)
|
||||
self.assertIsInstance(mocked_upload.call_args[0][1],
|
||||
progressbar.VerboseFileWrapper)
|
||||
|
||||
def test_image_download(self):
|
||||
args = self._make_args(
|
||||
{'id': 'pass', 'file': 'test', 'progress': False})
|
||||
|
||||
Reference in New Issue
Block a user