Return 503 if insufficient permission on filestore

Fixes lp 919257

Return 503 "Service Unavailable" status from POST /images request
where there's insufficient permission to write image content to
the backend filestore.

Change-Id: I0c4e8bb1e70d6542852a86903a4a2a200dd23f01
This commit is contained in:
Eoghan Glynn 2012-02-16 20:24:39 +00:00
parent 3b8ff189a1
commit 45f9e05572
4 changed files with 24 additions and 1 deletions

View File

@ -30,7 +30,9 @@ from webob.exc import (HTTPError,
HTTPBadRequest,
HTTPForbidden,
HTTPUnauthorized,
HTTPRequestEntityTooLarge)
HTTPRequestEntityTooLarge,
HTTPServiceUnavailable,
)
from glance.api import policy
import glance.api.v1
@ -404,6 +406,14 @@ class Controller(controller.BaseController):
raise HTTPRequestEntityTooLarge(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,
content_type='text/plain')
except HTTPError, e:
self._safe_kill(req, image_id)
self.notifier.error('image.upload', e.explanation)

View File

@ -83,6 +83,10 @@ class StorageFull(GlanceException):
message = _("There is not enough disk space on the image storage media.")
class StorageWriteDenied(GlanceException):
message = _("Permission to write image storage media denied.")
class ImportFailure(GlanceException):
message = _("Failed to import requested object/class: '%(import_str)s'. "
"Reason: %(reason)s")

View File

@ -208,6 +208,8 @@ class Store(glance.store.base.Store):
except IOError as e:
if e.errno in [errno.EFBIG, errno.ENOSPC]:
raise exception.StorageFull()
elif e.errno == errno.EACCES:
raise exception.StorageWriteDenied()
else:
raise

View File

@ -167,6 +167,13 @@ class TestStore(base.IsolatedUnitTest):
"""
self._do_test_add_failure(errno.EFBIG, exception.StorageFull)
def test_add_storage_write_denied(self):
"""
Tests that adding an image with insufficient filestore permissions
raises an appropriate exception
"""
self._do_test_add_failure(errno.EACCES, exception.StorageWriteDenied)
def test_add_other_failure(self):
"""
Tests that a non-space-related IOError does not raise a