Fixes LP#934492 - Allow Null Name

* Modify bin/glance to allow nullable name property,
  in accordance with API spec

This changeset also adds a fix for Swift functional
tests where HTTPS locations weren't being properly
constructed.

Change-Id: Ibad2d3ab150ee347449b4e9b3b9e941ce7a0fc6f
This commit is contained in:
Jay Pipes 2012-03-13 15:21:40 -04:00
parent 101e3ef9f9
commit 1615a1fc57
3 changed files with 46 additions and 7 deletions

View File

@ -164,7 +164,7 @@ Field names of note:
id Optional. If not specified, an image identifier will be
automatically assigned.
name Required. A name for the image.
name Optional. A name for the image.
size Optional. Should be size in bytes of the image if
specified.
is_public Optional. If specified, interpreted as a boolean value
@ -217,12 +217,8 @@ EXAMPLES
print e
return FAILURE
if 'name' not in fields.keys():
print "Please specify a name for the image using name=VALUE"
return FAILURE
image_meta = {'id': fields.pop('id', None),
'name': fields.pop('name'),
'name': fields.pop('name', None),
'is_public': utils.bool_from_string(
fields.pop('is_public', False)),
'protected': utils.bool_from_string(

View File

@ -173,7 +173,9 @@ def teardown_swift(test):
def get_swift_uri(test, image_id):
uri = ('swift+http://%(swift_store_user)s:%(swift_store_key)s' %
# Apparently we must use HTTPS with Cloud Files now, otherwise
# we will get a 301 Moved.... :(
uri = ('swift+https://%(swift_store_user)s:%(swift_store_key)s' %
test.__dict__)
uri += ('@%(swift_store_auth_address)s/%(swift_store_container)s/' %
test.__dict__)

View File

@ -145,6 +145,47 @@ class TestBinGlance(functional.FunctionalTest):
self.assertEqual('0', size, "Expected image to be 0 bytes in size, "
"but got %s. " % size)
def test_add_no_name(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
# Can't use minimal_add_command since that uses
# name...
cmd = ("bin/glance --port=%d add is_public=True"
" disk_format=raw container_format=ovf"
" %s" % (api_port, 'location=http://example.com'))
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('None', name)
@requires(setup_http, teardown_http)
def test_add_copying_from(self):
self.cleanup()