Removed bin/glance's TTY detection.

Fixes bug 907906

The logic is sound: if location=XXX is specified, use that.
If it's not specified, use sys.stdin to read image data. No need to
error when location=XXX is specified and stdin just happens to be a TTY.

(cherry picked from commit 1571cd8f83)

Change-Id: I057312becad59b3dd7a71f94d25ebd032e1a7b52
This commit is contained in:
Brian Lamar 2011-12-22 14:22:48 -05:00 committed by Mark McLoughlin
parent 845646eaa7
commit 2b97b7e561
2 changed files with 86 additions and 7 deletions

View File

@ -241,13 +241,6 @@ EXAMPLES
# Grab the image data stream from stdin or redirect,
# otherwise error out
image_data = sys.stdin
else:
# Ensure no image data has been given
if not sys.stdin.isatty():
print "Either supply a location=LOCATION argument or supply image "
print "data via a redirect. You have supplied BOTH image data "
print "AND a location."
return FAILURE
# Add custom attributes, which are all the arguments remaining
image_meta['properties'] = fields

View File

@ -37,6 +37,92 @@ class TestBinGlance(functional.FunctionalTest):
# NoAuth strategy.
os.environ['OS_AUTH_STRATEGY'] = 'noauth'
def test_add_with_location(self):
self.cleanup()
self.start_servers(**self.__dict__.copy())
api_port = self.api_port
registry_port = self.registry_port
# 0. Verify no public images
cmd = "bin/glance --port=%d index" % api_port
exitcode, out, err = execute(cmd)
self.assertEqual(0, exitcode)
self.assertEqual('', out.strip())
# 1. Add public image
cmd = "bin/glance --port=%d add is_public=True"\
" name=MyImage location=http://example.com" % api_port
exitcode, out, err = execute(cmd)
self.assertEqual(0, exitcode)
self.assertTrue(out.strip().startswith('Added new image with ID:'))
# 2. Verify image added as public image
cmd = "bin/glance --port=%d index" % api_port
exitcode, out, err = execute(cmd)
self.assertEqual(0, exitcode)
lines = out.split("\n")[2:-1]
self.assertEqual(1, len(lines))
line = lines[0]
image_id, name, disk_format, container_format, size = \
[c.strip() for c in line.split()]
self.assertEqual('MyImage', name)
self.assertEqual('0', size, "Expected image to be 0 bytes in size, "
"but got %s. " % size)
def test_add_with_location_and_stdin(self):
self.cleanup()
self.start_servers(**self.__dict__.copy())
api_port = self.api_port
registry_port = self.registry_port
# 0. Verify no public images
cmd = "bin/glance --port=%d index" % api_port
exitcode, out, err = execute(cmd)
self.assertEqual(0, exitcode)
self.assertEqual('', out.strip())
# 1. Add public image
with tempfile.NamedTemporaryFile() as image_file:
image_file.write("XXX")
image_file.flush()
file_name = image_file.name
cmd = "bin/glance --port=%d add is_public=True name=MyImage " \
"location=http://example.com < %s" % (api_port, file_name)
exitcode, out, err = execute(cmd)
self.assertEqual(0, exitcode)
self.assertTrue(out.strip().startswith('Added new image with ID:'))
# 2. Verify image added as public image
cmd = "bin/glance --port=%d index" % api_port
exitcode, out, err = execute(cmd)
self.assertEqual(0, exitcode)
lines = out.split("\n")[2:-1]
self.assertEqual(1, len(lines))
line = lines[0]
image_id, name, disk_format, container_format, size = \
[c.strip() for c in line.split()]
self.assertEqual('MyImage', name)
self.assertEqual('0', size, "Expected image to be 0 bytes in size, "
"but got %s. " % size)
def test_add_list_delete_list(self):
"""
We test the following: