Merge "Return verbose message if account quota exceeded"

This commit is contained in:
Jenkins 2014-10-30 00:23:00 +00:00 committed by Gerrit Code Review
commit 16e1e1e3c6
3 changed files with 11 additions and 3 deletions

View File

@ -53,8 +53,7 @@ account size has been updated.
""" """
from swift.common.constraints import check_copy_from_header from swift.common.constraints import check_copy_from_header
from swift.common.swob import HTTPForbidden, HTTPRequestEntityTooLarge, \ from swift.common.swob import HTTPForbidden, Response, HTTPBadRequest, wsgify
HTTPBadRequest, wsgify
from swift.common.utils import register_swift_info from swift.common.utils import register_swift_info
from swift.proxy.controllers.base import get_account_info, get_object_info from swift.proxy.controllers.base import get_account_info, get_object_info
@ -137,7 +136,7 @@ class AccountQuotaMiddleware(object):
new_size = int(account_info['bytes']) + content_length new_size = int(account_info['bytes']) + content_length
if quota < new_size: if quota < new_size:
return HTTPRequestEntityTooLarge() return Response(status=413, body='Upload exceeds quota.')
return self.app return self.app

View File

@ -140,6 +140,7 @@ class TestAccountQuota(unittest.TestCase):
'swift.cache': cache}) 'swift.cache': cache})
res = req.get_response(app) res = req.get_response(app)
self.assertEquals(res.status_int, 413) self.assertEquals(res.status_int, 413)
self.assertEquals(res.body, 'Upload exceeds quota.')
def test_over_quota_container_create_still_works(self): def test_over_quota_container_create_still_works(self):
headers = [('x-account-bytes-used', '1001'), headers = [('x-account-bytes-used', '1001'),
@ -189,6 +190,7 @@ class TestAccountQuota(unittest.TestCase):
headers={'x-copy-from': '/c2/o2'}) headers={'x-copy-from': '/c2/o2'})
res = req.get_response(app) res = req.get_response(app)
self.assertEquals(res.status_int, 413) self.assertEquals(res.status_int, 413)
self.assertEquals(res.body, 'Upload exceeds quota.')
def test_exceed_bytes_quota_copy_verb(self): def test_exceed_bytes_quota_copy_verb(self):
headers = [('x-account-bytes-used', '500'), headers = [('x-account-bytes-used', '500'),
@ -202,6 +204,7 @@ class TestAccountQuota(unittest.TestCase):
headers={'Destination': '/c/o'}) headers={'Destination': '/c/o'})
res = req.get_response(app) res = req.get_response(app)
self.assertEquals(res.status_int, 413) self.assertEquals(res.status_int, 413)
self.assertEquals(res.body, 'Upload exceeds quota.')
def test_not_exceed_bytes_quota_copy_from(self): def test_not_exceed_bytes_quota_copy_from(self):
headers = [('x-account-bytes-used', '0'), headers = [('x-account-bytes-used', '0'),

View File

@ -93,6 +93,7 @@ class TestContainerQuotas(unittest.TestCase):
'CONTENT_LENGTH': '100'}) 'CONTENT_LENGTH': '100'})
res = req.get_response(app) res = req.get_response(app)
self.assertEquals(res.status_int, 413) self.assertEquals(res.status_int, 413)
self.assertEquals(res.body, 'Upload exceeds quota.')
def test_exceed_bytes_quota_copy_from(self): def test_exceed_bytes_quota_copy_from(self):
app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {}) app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {})
@ -105,6 +106,7 @@ class TestContainerQuotas(unittest.TestCase):
headers={'x-copy-from': '/c2/o2'}) headers={'x-copy-from': '/c2/o2'})
res = req.get_response(app) res = req.get_response(app)
self.assertEquals(res.status_int, 413) self.assertEquals(res.status_int, 413)
self.assertEquals(res.body, 'Upload exceeds quota.')
def test_exceed_bytes_quota_copy_verb(self): def test_exceed_bytes_quota_copy_verb(self):
app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {}) app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {})
@ -117,6 +119,7 @@ class TestContainerQuotas(unittest.TestCase):
headers={'Destination': '/c/o'}) headers={'Destination': '/c/o'})
res = req.get_response(app) res = req.get_response(app)
self.assertEquals(res.status_int, 413) self.assertEquals(res.status_int, 413)
self.assertEquals(res.body, 'Upload exceeds quota.')
def test_not_exceed_bytes_quota(self): def test_not_exceed_bytes_quota(self):
app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {}) app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {})
@ -191,6 +194,7 @@ class TestContainerQuotas(unittest.TestCase):
'CONTENT_LENGTH': '100'}) 'CONTENT_LENGTH': '100'})
res = req.get_response(app) res = req.get_response(app)
self.assertEquals(res.status_int, 413) self.assertEquals(res.status_int, 413)
self.assertEquals(res.body, 'Upload exceeds quota.')
def test_exceed_counts_quota_copy_from(self): def test_exceed_counts_quota_copy_from(self):
app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {}) app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {})
@ -202,6 +206,7 @@ class TestContainerQuotas(unittest.TestCase):
headers={'x-copy-from': '/c2/o2'}) headers={'x-copy-from': '/c2/o2'})
res = req.get_response(app) res = req.get_response(app)
self.assertEquals(res.status_int, 413) self.assertEquals(res.status_int, 413)
self.assertEquals(res.body, 'Upload exceeds quota.')
def test_exceed_counts_quota_copy_verb(self): def test_exceed_counts_quota_copy_verb(self):
app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {}) app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {})
@ -212,6 +217,7 @@ class TestContainerQuotas(unittest.TestCase):
headers={'Destination': '/c/o'}) headers={'Destination': '/c/o'})
res = req.get_response(app) res = req.get_response(app)
self.assertEquals(res.status_int, 413) self.assertEquals(res.status_int, 413)
self.assertEquals(res.body, 'Upload exceeds quota.')
def test_not_exceed_counts_quota(self): def test_not_exceed_counts_quota(self):
app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {}) app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {})