Skip to content

Commit

Permalink
webob exception incorrectly used in v1 images.py
Browse files Browse the repository at this point in the history
Fixes bug 1010681

Change-Id: I42cf5a8e87e07b94fbba4af7ad3b16a62817007e
  • Loading branch information
iccha committed Jun 11, 2012
1 parent 5756518 commit fc3f13c
Showing 1 changed file with 49 additions and 22 deletions.
71 changes: 49 additions & 22 deletions glance/api/v1/images.py
Expand Up @@ -237,7 +237,9 @@ def _validate_source(source, req):
return source
msg = _("External sourcing not supported for store %s") % source
logger.error(msg)
raise HTTPBadRequest(msg, request=req, content_type="text/plain")
raise HTTPBadRequest(explanation=msg,
request=req,
content_type="text/plain")

@staticmethod
def _copy_from(req):
Expand Down Expand Up @@ -316,16 +318,22 @@ def _reserve(self, req, image_meta):
msg = (_("An image with identifier %s already exists")
% image_meta['id'])
logger.error(msg)
raise HTTPConflict(msg, request=req, content_type="text/plain")
raise HTTPConflict(explanation=msg,
request=req,
content_type="text/plain")
except exception.Invalid, e:
msg = (_("Failed to reserve image. Got error: %(e)s") % locals())
for line in msg.split('\n'):
logger.error(line)
raise HTTPBadRequest(msg, request=req, content_type="text/plain")
raise HTTPBadRequest(explanation=msg,
request=req,
content_type="text/plain")
except exception.Forbidden:
msg = _("Forbidden to reserve image.")
logger.error(msg)
raise HTTPForbidden(msg, request=req, content_type="text/plain")
raise HTTPForbidden(explanation=msg,
request=req,
content_type="text/plain")

def _upload(self, req, image_meta):
"""
Expand Down Expand Up @@ -383,7 +391,7 @@ def _upload(self, req, image_meta):
"%(max_image_size)d. Supplied image size was "
"%(image_size)d") % locals()
logger.warn(msg)
raise HTTPBadRequest(msg, request=req)
raise HTTPBadRequest(explanation=msg, request=req)

location, size, checksum = store.add(image_meta['id'],
image_data,
Expand All @@ -399,7 +407,8 @@ def _upload(self, req, image_meta):
"status to 'killed'.") % locals()
logger.error(msg)
self._safe_kill(req, image_id)
raise HTTPBadRequest(msg, content_type="text/plain",
raise HTTPBadRequest(explanation=msg,
content_type="text/plain",
request=req)

# Update the database with the checksum returned
Expand All @@ -419,29 +428,31 @@ def _upload(self, req, image_meta):
logger.error(msg)
self._safe_kill(req, image_id)
self.notifier.error('image.upload', msg)
raise HTTPConflict(msg, request=req)
raise HTTPConflict(explanation=msg, request=req)

except exception.Forbidden, e:
msg = _("Forbidden upload attempt: %s") % e
logger.error(msg)
self._safe_kill(req, image_id)
self.notifier.error('image.upload', msg)
raise HTTPForbidden(msg, request=req, content_type="text/plain")
raise HTTPForbidden(explanation=msg,
request=req,
content_type="text/plain")

except exception.StorageFull, e:
msg = _("Image storage media is full: %s") % e
logger.error(msg)
self._safe_kill(req, image_id)
self.notifier.error('image.upload', msg)
raise HTTPRequestEntityTooLarge(msg, request=req,
raise HTTPRequestEntityTooLarge(explanation=msg, request=req,
content_type='text/plain')

except exception.StorageWriteDenied, e:
msg = _("Insufficient permissions on image storage media: %s") % e
logger.error(msg)
self._safe_kill(req, image_id)
self.notifier.error('image.upload', msg)
raise HTTPServiceUnavailable(msg, request=req,
raise HTTPServiceUnavailable(explanation=msg, request=req,
content_type='text/plain')

except HTTPError, e:
Expand All @@ -460,7 +471,7 @@ def _upload(self, req, image_meta):
'exc': str(e)})

self.notifier.error('image.upload', msg)
raise HTTPBadRequest(msg, request=req)
raise HTTPBadRequest(explanation=msg, request=req)

def _activate(self, req, image_id, location):
"""
Expand All @@ -485,7 +496,9 @@ def _activate(self, req, image_id, location):
for line in msg.split('\n'):
logger.error(line)
self.notifier.error('image.update', msg)
raise HTTPBadRequest(msg, request=req, content_type="text/plain")
raise HTTPBadRequest(explanation=msg,
request=req,
content_type="text/plain")

def _kill(self, req, image_id):
"""
Expand Down Expand Up @@ -647,7 +660,9 @@ def update(self, req, id, image_meta, image_data):
if reactivating:
msg = _("Attempted to update Location field for an image "
"not in queued status.")
raise HTTPBadRequest(msg, request=req, content_type="text/plain")
raise HTTPBadRequest(explanation=msg,
request=req,
content_type="text/plain")

try:
if location:
Expand All @@ -667,19 +682,25 @@ def update(self, req, id, image_meta, image_data):
for line in msg.split('\n'):
logger.error(line)
self.notifier.error('image.update', msg)
raise HTTPBadRequest(msg, request=req, content_type="text/plain")
raise HTTPBadRequest(explanation=msg,
request=req,
content_type="text/plain")
except exception.NotFound, e:
msg = ("Failed to find image to update: %(e)s" % locals())
for line in msg.split('\n'):
logger.info(line)
self.notifier.info('image.update', msg)
raise HTTPNotFound(msg, request=req, content_type="text/plain")
raise HTTPNotFound(explanation=msg,
request=req,
content_type="text/plain")
except exception.Forbidden, e:
msg = ("Forbidden to update image: %(e)s" % locals())
for line in msg.split('\n'):
logger.info(line)
self.notifier.info('image.update', msg)
raise HTTPForbidden(msg, request=req, content_type="text/plain")
raise HTTPForbidden(explanation=msg,
request=req,
content_type="text/plain")
else:
self.notifier.info('image.update', image_meta)

Expand Down Expand Up @@ -708,7 +729,8 @@ def delete(self, req, id):
if image['protected']:
msg = _("Image is protected")
logger.debug(msg)
raise HTTPForbidden(msg, request=req,
raise HTTPForbidden(explanation=msg,
request=req,
content_type="text/plain")

# The image's location field may be None in the case
Expand All @@ -725,13 +747,17 @@ def delete(self, req, id):
for line in msg.split('\n'):
logger.info(line)
self.notifier.info('image.delete', msg)
raise HTTPNotFound(msg, request=req, content_type="text/plain")
raise HTTPNotFound(explanation=msg,
request=req,
content_type="text/plain")
except exception.Forbidden, e:
msg = ("Forbidden to delete image: %(e)s" % locals())
for line in msg.split('\n'):
logger.info(line)
self.notifier.info('image.delete', msg)
raise HTTPForbidden(msg, request=req, content_type="text/plain")
raise HTTPForbidden(explanation=msg,
request=req,
content_type="text/plain")
else:
self.notifier.info('image.delete', image)

Expand All @@ -750,7 +776,8 @@ def get_store_or_400(self, request, scheme):
except exception.UnknownScheme:
msg = _("Store for scheme %s not found")
logger.error(msg % scheme)
raise HTTPBadRequest(msg, request=request,
raise HTTPBadRequest(explanation=msg,
request=request,
content_type='text/plain')

def verify_scheme_or_exit(self, scheme):
Expand Down Expand Up @@ -782,7 +809,7 @@ def _deserialize(self, request):
image_size_str = request.headers['x-image-meta-size']
msg = _("Incoming image size of %s was not convertible to "
"an integer.") % image_size_str
raise HTTPBadRequest(msg, request=request)
raise HTTPBadRequest(explanation=msg, request=request)

image_meta = result['image_meta']
if 'size' in image_meta:
Expand All @@ -793,7 +820,7 @@ def _deserialize(self, request):
"%(max_image_size)d. Supplied image size was "
"%(incoming_image_size)d") % locals()
logger.warn(msg)
raise HTTPBadRequest(msg, request=request)
raise HTTPBadRequest(explanation=msg, request=request)

data = request.body_file if self.has_body(request) else None
result['image_data'] = data
Expand Down

0 comments on commit fc3f13c

Please sign in to comment.