From cbc52a7a4ea32f7d84f54948aa9ebb5decd26813 Mon Sep 17 00:00:00 2001 From: Christian Schwede Date: Thu, 23 Oct 2014 16:23:20 +0200 Subject: [PATCH] Return verbose message if account quota exceeded This message is already used in the container quota middleware, so let's use it in the account middleware too. Change-Id: I136fe6102c28cc8ccc021555c42ec7b0be716444 Closes-Bug: 1381875 --- swift/common/middleware/account_quotas.py | 5 ++--- test/unit/common/middleware/test_account_quotas.py | 3 +++ test/unit/common/middleware/test_quotas.py | 6 ++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/swift/common/middleware/account_quotas.py b/swift/common/middleware/account_quotas.py index ec4a3fda2e..a3c7dc96cd 100644 --- a/swift/common/middleware/account_quotas.py +++ b/swift/common/middleware/account_quotas.py @@ -53,8 +53,7 @@ account size has been updated. """ from swift.common.constraints import check_copy_from_header -from swift.common.swob import HTTPForbidden, HTTPRequestEntityTooLarge, \ - HTTPBadRequest, wsgify +from swift.common.swob import HTTPForbidden, Response, HTTPBadRequest, wsgify from swift.common.utils import register_swift_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 if quota < new_size: - return HTTPRequestEntityTooLarge() + return Response(status=413, body='Upload exceeds quota.') return self.app diff --git a/test/unit/common/middleware/test_account_quotas.py b/test/unit/common/middleware/test_account_quotas.py index 8660cf5e48..75bd1d70eb 100644 --- a/test/unit/common/middleware/test_account_quotas.py +++ b/test/unit/common/middleware/test_account_quotas.py @@ -140,6 +140,7 @@ class TestAccountQuota(unittest.TestCase): 'swift.cache': cache}) res = req.get_response(app) self.assertEquals(res.status_int, 413) + self.assertEquals(res.body, 'Upload exceeds quota.') def test_over_quota_container_create_still_works(self): headers = [('x-account-bytes-used', '1001'), @@ -189,6 +190,7 @@ class TestAccountQuota(unittest.TestCase): headers={'x-copy-from': '/c2/o2'}) res = req.get_response(app) self.assertEquals(res.status_int, 413) + self.assertEquals(res.body, 'Upload exceeds quota.') def test_exceed_bytes_quota_copy_verb(self): headers = [('x-account-bytes-used', '500'), @@ -202,6 +204,7 @@ class TestAccountQuota(unittest.TestCase): headers={'Destination': '/c/o'}) res = req.get_response(app) self.assertEquals(res.status_int, 413) + self.assertEquals(res.body, 'Upload exceeds quota.') def test_not_exceed_bytes_quota_copy_from(self): headers = [('x-account-bytes-used', '0'), diff --git a/test/unit/common/middleware/test_quotas.py b/test/unit/common/middleware/test_quotas.py index da060e1229..b0548cc56c 100644 --- a/test/unit/common/middleware/test_quotas.py +++ b/test/unit/common/middleware/test_quotas.py @@ -93,6 +93,7 @@ class TestContainerQuotas(unittest.TestCase): 'CONTENT_LENGTH': '100'}) res = req.get_response(app) self.assertEquals(res.status_int, 413) + self.assertEquals(res.body, 'Upload exceeds quota.') def test_exceed_bytes_quota_copy_from(self): app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {}) @@ -105,6 +106,7 @@ class TestContainerQuotas(unittest.TestCase): headers={'x-copy-from': '/c2/o2'}) res = req.get_response(app) self.assertEquals(res.status_int, 413) + self.assertEquals(res.body, 'Upload exceeds quota.') def test_exceed_bytes_quota_copy_verb(self): app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {}) @@ -117,6 +119,7 @@ class TestContainerQuotas(unittest.TestCase): headers={'Destination': '/c/o'}) res = req.get_response(app) self.assertEquals(res.status_int, 413) + self.assertEquals(res.body, 'Upload exceeds quota.') def test_not_exceed_bytes_quota(self): app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {}) @@ -191,6 +194,7 @@ class TestContainerQuotas(unittest.TestCase): 'CONTENT_LENGTH': '100'}) res = req.get_response(app) self.assertEquals(res.status_int, 413) + self.assertEquals(res.body, 'Upload exceeds quota.') def test_exceed_counts_quota_copy_from(self): app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {}) @@ -202,6 +206,7 @@ class TestContainerQuotas(unittest.TestCase): headers={'x-copy-from': '/c2/o2'}) res = req.get_response(app) self.assertEquals(res.status_int, 413) + self.assertEquals(res.body, 'Upload exceeds quota.') def test_exceed_counts_quota_copy_verb(self): app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {}) @@ -212,6 +217,7 @@ class TestContainerQuotas(unittest.TestCase): headers={'Destination': '/c/o'}) res = req.get_response(app) self.assertEquals(res.status_int, 413) + self.assertEquals(res.body, 'Upload exceeds quota.') def test_not_exceed_counts_quota(self): app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {})