Fixups from Rick's review

This commit is contained in:
jaypipes@gmail.com 2011-02-23 14:28:25 -05:00
parent ffc0054bfd
commit b5c6a8bfe8
3 changed files with 16 additions and 18 deletions
glance
registry/db
server.py
tests/unit

@ -152,12 +152,12 @@ def validate_image(values):
:param values: Mapping of image metadata to check
"""
type = values.get('type', None)
if not type:
image_type = values.get('type', None)
if not image_type:
msg = "Image type is required."
raise exception.Invalid(msg)
if type not in ('machine', 'kernel', 'ramdisk', 'raw', 'vhd'):
msg = "Invalid image type '%s' for image." % type
if image_type not in ('machine', 'kernel', 'ramdisk', 'raw', 'vhd'):
msg = "Invalid image type '%s' for image." % image_type
raise exception.Invalid(msg)
status = values.get('status', None)
if not status:

@ -217,10 +217,10 @@ class Controller(wsgi.Controller):
raise HTTPBadRequest(
"Content-Type must be application/octet-stream")
image_store = req.headers.get(
store_name = req.headers.get(
'x-image-meta-store', self.options['default_store'])
store = self.get_store_or_400(req, image_store)
store = self.get_store_or_400(req, store_name)
image_meta['status'] = 'saving'
image_id = image_meta['id']
@ -232,9 +232,7 @@ class Controller(wsgi.Controller):
try:
logger.debug("Uploading image data for image %(image_id)s "
"to %(store_name)s store"
% {'image_id': image_id,
'store_name': image_store})
"to %(store_name)s store" % locals())
location, size = store.add(image_meta['id'],
req.body_file,
self.options)

@ -92,7 +92,7 @@ class TestMiscellaneous(unittest.TestCase):
# A config file to use just for this test...we don't want
# to trample on currently-running Glance servers, now do we?
with tempfile.NamedTemporaryFile() as f:
with tempfile.NamedTemporaryFile() as conf_file:
conf_contents = """[DEFAULT]
verbose = True
debug = True
@ -113,9 +113,9 @@ bind_port = %(reg_port)s
sql_connection = sqlite://
sql_idle_timeout = 3600
""" % locals()
f.write(conf_contents)
f.flush()
conf_file = f.name
conf_file.write(conf_contents)
conf_file.flush()
conf_file_name = conf_file.name
venv = ""
if 'VIRTUAL_ENV' in os.environ:
@ -123,14 +123,14 @@ sql_idle_timeout = 3600
# Start up the API and default registry server
cmd = venv + "./bin/glance-control api start "\
"%s --pid-file=glance-api.pid" % conf_file
"%s --pid-file=glance-api.pid" % conf_file_name
exitcode, out, err = execute(cmd)
self.assertEquals(0, exitcode)
self.assertTrue("Starting glance-api with" in out)
cmd = venv + "./bin/glance-control registry start "\
"%s --pid-file=glance-registry.pid" % conf_file
"%s --pid-file=glance-registry.pid" % conf_file_name
exitcode, out, err = execute(cmd)
self.assertEquals(0, exitcode)
@ -154,7 +154,7 @@ sql_idle_timeout = 3600
"in output: %s" % out)
cmd = "./bin/glance-upload --port=%(api_port)d "\
"--type=invalid %(conf_file)s 'my image'" % locals()
"--type=invalid %(conf_file_name)s 'my image'" % locals()
# Normally, we would simply self.assertRaises() here, but
# we also want to check that the Invalid image type is in
@ -169,8 +169,8 @@ sql_idle_timeout = 3600
# Spin down the API and default registry server
cmd = "./bin/glance-control api stop "\
"%s --pid-file=glance-api.pid" % conf_file
"%s --pid-file=glance-api.pid" % conf_file_name
ignored, out, err = execute(cmd)
cmd = "./bin/glance-control registry stop "\
"%s --pid-file=glance-registry.pid" % conf_file
"%s --pid-file=glance-registry.pid" % conf_file_name
ignored, out, err = execute(cmd)