diff options
author | Louis Taylor <kragniz@gmail.com> | 2014-12-03 02:24:44 +0000 |
---|---|---|
committer | Louis Taylor <kragniz@gmail.com> | 2015-02-19 10:40:12 +0000 |
commit | af29e0a1b0185caa61c3aed30c35a2d8f0e216cc (patch) | |
tree | b3823af383e2528f16b63c8b7b2538a8226807ae /glanceclient/v1 | |
parent | a3eaafefbdcec0231db33c44cca718526f9c96cc (diff) | |
download | python-glanceclient-af29e0a1b0185caa61c3aed30c35a2d8f0e216cc.tar.gz |
Show error on trying to upload to non-queued image
Previously, attempting to upload data to an image which has a status
which is not 'queued' would appear to succeed, when the data has
actually never been sent to the glance server. To the user, it appeared
that their request was successful. This patch adds a check for incoming
image data on the 'image-update' command, and exits with an error if the
specified image does not have the status 'queued'.
Examples:
$ cat os.img | glance image-update d50b0236-b27c-412a-91b9-18ceafa9cc5a
Unable to upload image data to an image which is active.
$ glance image-update --file os.img d50b0236-b27c-412a-91b9-18ceafa9cc5a
Unable to upload image data to an image which is killed.
Change-Id: I91bbd7f86d5851a5e35946c711dba1932283ed79
Closes-Bug: #1395084
Diffstat (limited to 'glanceclient/v1')
-rw-r--r-- | glanceclient/v1/shell.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/glanceclient/v1/shell.py b/glanceclient/v1/shell.py index c4e53dc..dcc1d91 100644 --- a/glanceclient/v1/shell.py +++ b/glanceclient/v1/shell.py @@ -17,6 +17,7 @@ from __future__ import print_function import copy import functools +import os import six from oslo_utils import encodeutils @@ -244,6 +245,17 @@ def do_image_create(gc, args): _image_show(image, args.human_readable) +def _is_image_data_provided(args): + """Return True if some image data has probably been provided by the user""" + # NOTE(kragniz): Check stdin works, then check is there is any data + # on stdin or a filename has been provided with --file + try: + os.fstat(0) + except OSError: + return False + return not sys.stdin.isatty() or args.file or args.copy_from + + @utils.arg('image', metavar='<IMAGE>', help='Name or ID of image to modify.') @utils.arg('--name', metavar='<NAME>', help='Name of image.') @@ -322,6 +334,12 @@ def do_image_update(gc, args): fields['data'], filesize ) + elif _is_image_data_provided(args): + # NOTE(kragniz): Exit with an error if the status is not queued + # and image data was provided + utils.exit('Unable to upload image data to an image which ' + 'is %s.' % image.status) + image = gc.images.update(image, purge_props=args.purge_props, **fields) _image_show(image, args.human_readable) |