From 90543244423692cade8673cf78fa601c9af04f1c Mon Sep 17 00:00:00 2001 From: Louis Taylor Date: Tue, 16 Dec 2014 17:59:28 +0000 Subject: [PATCH] Disable progress bar if image is piped into client Previously, running: cat something.img | glance image-create --progress --container-format=bare --disk-format=raw or cat something.img | glance --os-image-api-version 2 image-upload --progress would result in an error. This error was caused by the length of the input being unknown, so the overall progress cannot be found. This patch disables the progress bar whenever the size of the input file cannot be determined. Change-Id: I6bfef7441864b638194126880241cc2c96d5b18b Closes-Bug: #1402746 --- glanceclient/v1/shell.py | 9 ++++++--- glanceclient/v2/shell.py | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/glanceclient/v1/shell.py b/glanceclient/v1/shell.py index d4d117e3..a7888f96 100644 --- a/glanceclient/v1/shell.py +++ b/glanceclient/v1/shell.py @@ -225,9 +225,12 @@ def do_image_create(gc, args): # Only show progress bar for local image files if fields.get('data') and args.progress: filesize = utils.get_file_size(fields['data']) - fields['data'] = progressbar.VerboseFileWrapper( - fields['data'], filesize - ) + if filesize is not None: + # NOTE(kragniz): do not show a progress bar if the size of the + # input is unknown (most likely a piped input) + fields['data'] = progressbar.VerboseFileWrapper( + fields['data'], filesize + ) image = gc.images.create(**fields) _image_show(image, args.human_readable) diff --git a/glanceclient/v2/shell.py b/glanceclient/v2/shell.py index 4da2d990..d8cd194b 100644 --- a/glanceclient/v2/shell.py +++ b/glanceclient/v2/shell.py @@ -254,7 +254,10 @@ def do_image_upload(gc, args): image_data = utils.get_data_file(args) if args.progress: filesize = utils.get_file_size(image_data) - image_data = progressbar.VerboseFileWrapper(image_data, filesize) + if filesize is not None: + # NOTE(kragniz): do not show a progress bar if the size of the + # input is unknown (most likely a piped input) + image_data = progressbar.VerboseFileWrapper(image_data, filesize) gc.images.upload(args.id, image_data, args.size)