Skip to content

Commit

Permalink
Removed bin/glance's TTY detection.
Browse files Browse the repository at this point in the history
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 1571cd8)

Change-Id: I057312becad59b3dd7a71f94d25ebd032e1a7b52
  • Loading branch information
Brian Lamar authored and markmc committed Jan 5, 2012
1 parent 845646e commit 2b97b7e
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 7 deletions.
7 changes: 0 additions & 7 deletions bin/glance
Expand Up @@ -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
Expand Down
86 changes: 86 additions & 0 deletions glance/tests/functional/test_bin_glance.py
Expand Up @@ -37,6 +37,92 @@ def setUp(self):
# 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:
Expand Down

0 comments on commit 2b97b7e

Please sign in to comment.