Don't attempt to read stdin if it is empty.

* Check for available data size in v1/shell.py/_set_data_field, don't
   read if 0.
 * Add test_shell.py including tests for 3x stdin scenarios:
	* closed
 	* open and empty
	* open with data

Change-Id: I6ff65b0e226be509de9cd3f021560081529283b0
Fixes: bug #1173044
This commit is contained in:
Hugh Saunders
2013-04-26 08:26:11 +01:00
parent 2a56a32edb
commit a3585ef62d
2 changed files with 292 additions and 2 deletions
+2 -2
View File
@@ -121,12 +121,12 @@ def _set_data_field(fields, args):
# (3) no image data provided:
# glance ...
try:
os.fstat(0)
stat_result = os.fstat(0)
except OSError:
# (1) stdin is not valid (closed...)
fields['data'] = None
return
if not sys.stdin.isatty():
if not sys.stdin.isatty() and stat_result.st_size != 0:
# (2) image data is provided through standard input
if msvcrt:
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)