diff --git a/bin/glance b/bin/glance index 1008ef614f..11081af7ea 100755 --- a/bin/glance +++ b/bin/glance @@ -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 diff --git a/glance/tests/functional/test_bin_glance.py b/glance/tests/functional/test_bin_glance.py index bf441daff6..868a43c5d7 100644 --- a/glance/tests/functional/test_bin_glance.py +++ b/glance/tests/functional/test_bin_glance.py @@ -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: