Skip to content

Commit

Permalink
Fixes LP#934492 - Allow Null Name
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jaypipes committed Mar 13, 2012
1 parent 101e3ef commit 1615a1f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
8 changes: 2 additions & 6 deletions bin/glance
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion glance/tests/functional/store_utils.py
Expand Up @@ -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__)
Expand Down
41 changes: 41 additions & 0 deletions glance/tests/functional/test_bin_glance.py
Expand Up @@ -145,6 +145,47 @@ def test_add_with_location(self):
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()
Expand Down

0 comments on commit 1615a1f

Please sign in to comment.