summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Yang <alex890714@gmail.com>2012-08-17 19:44:21 +0800
committerAlex Yang <alex890714@gmail.com>2012-08-21 15:51:24 +0800
commit6dbac845d5096063d6b344cd0314d0b50f7c50b0 (patch)
treed75ef3f45f2dad9c24c8b8cca032b7bed7ad03b5
parent73b00ca9de888bd7936b72d3b92e7d217c38d929 (diff)
downloadswift-6dbac845d5096063d6b344cd0314d0b50f7c50b0.tar.gz
Retuen a reasonable response to client.
As we use the 'account_autocreate' for auto-create accounts, we send a request to HEAD an account which is just deleted(the account-reaper not reclaim it immediately), the proxy-server will return 'HTTP 500 Internal Server Error'. In my opinion, this is unreasonable, so I change the code in swift/proxy /server.py for returning a reasonable response. I modified the code in POST, GETorHEAD and account_info. At last, I modified some code in the unittest test/unit/proxy/test_server.py. Change-Id: Ib057b387c9da073d707ffae49ead54206a8fb7dd Fixes: Bug #1037889
-rw-r--r--swift/proxy/server.py14
-rw-r--r--test/unit/proxy/test_server.py42
2 files changed, 44 insertions, 12 deletions
diff --git a/swift/proxy/server.py b/swift/proxy/server.py
index 6061cc5f4..c42632cc2 100644
--- a/swift/proxy/server.py
+++ b/swift/proxy/server.py
@@ -439,7 +439,9 @@ class Controller(object):
self.app.account_ring, partition, 'PUT',
path, [headers] * len(nodes))
if not is_success(resp.status_int):
- raise Exception('Could not autocreate account %r' % path)
+ self.app.logger.warning('Could not autocreate account %r' % \
+ path)
+ return None, None, None
result_code = HTTP_OK
if self.app.memcache and result_code in (HTTP_OK, HTTP_NOT_FOUND):
if result_code == HTTP_OK:
@@ -1808,8 +1810,9 @@ class AccountController(Controller):
self.app.account_ring, partition, 'PUT',
'/' + self.account_name, [headers] * len(nodes))
if not is_success(resp.status_int):
- raise Exception('Could not autocreate account %r' %
- self.account_name)
+ self.app.logger.warning('Could not autocreate account %r' %
+ self.account_name)
+ return resp
resp = self.GETorHEAD_base(req, _('Account'), partition, nodes,
req.path_info.rstrip('/'), len(nodes))
self.app.logger.timing_since('%s.timing' % (stats_type,), start_time)
@@ -1876,8 +1879,9 @@ class AccountController(Controller):
self.app.account_ring, account_partition, 'PUT',
'/' + self.account_name, [headers] * len(accounts))
if not is_success(resp.status_int):
- raise Exception('Could not autocreate account %r' %
- self.account_name)
+ self.app.logger.warning('Could not autocreate account %r' %
+ self.account_name)
+ return resp
self.app.logger.timing_since('POST.timing', start_time)
return resp
diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py
index 329b4597e..6eddf9e15 100644
--- a/test/unit/proxy/test_server.py
+++ b/test/unit/proxy/test_server.py
@@ -450,13 +450,28 @@ class TestController(unittest.TestCase):
proxy_server.http_connect = \
fake_http_connect(404, 404, 404, 503, 201, 503)
exc = None
- try:
- partition, nodes, count = \
- self.controller.account_info(self.account, autocreate=True)
- except Exception, err:
- exc = err
- self.assertEquals(str(exc),
- "Could not autocreate account '/some_account'")
+ partition, nodes, count = \
+ self.controller.account_info(self.account, autocreate=True)
+ self.check_account_info_return(partition, nodes, is_none=True)
+ self.assertEquals(None, count)
+
+ self.memcache.store = {}
+ proxy_server.http_connect = \
+ fake_http_connect(404, 404, 404, 403, 403, 403)
+ exc = None
+ partition, nodes, count = \
+ self.controller.account_info(self.account, autocreate=True)
+ self.check_account_info_return(partition, nodes, is_none=True)
+ self.assertEquals(None, count)
+
+ self.memcache.store = {}
+ proxy_server.http_connect = \
+ fake_http_connect(404, 404, 404, 409, 409, 409)
+ exc = None
+ partition, nodes, count = \
+ self.controller.account_info(self.account, autocreate=True)
+ self.check_account_info_return(partition, nodes, is_none=True)
+ self.assertEquals(None, count)
def check_container_info_return(self, ret, is_none=False):
if is_none:
@@ -3812,6 +3827,11 @@ class TestAccountController(unittest.TestCase):
controller.app.account_autocreate = True
self.assert_status_map(controller.GET,
(404, 404, 404, 201, 201, 201, 204), 204)
+ self.assert_status_map(controller.GET,
+ (404, 404, 404, 403, 403, 403, 403), 403)
+ self.assert_status_map(controller.GET,
+ (404, 404, 404, 409, 409, 409, 409), 409)
+
def test_HEAD(self):
with save_globals():
@@ -3840,6 +3860,10 @@ class TestAccountController(unittest.TestCase):
controller.app.account_autocreate = True
self.assert_status_map(controller.HEAD,
(404, 404, 404, 201, 201, 201, 204), 204)
+ self.assert_status_map(controller.HEAD,
+ (404, 404, 404, 403, 403, 403, 403), 403)
+ self.assert_status_map(controller.HEAD,
+ (404, 404, 404, 409, 409, 409, 409), 409)
def test_POST_autocreate(self):
with save_globals():
@@ -3850,6 +3874,10 @@ class TestAccountController(unittest.TestCase):
controller.app.account_autocreate = True
self.assert_status_map(controller.POST,
(404, 404, 404, 201, 201, 201), 201)
+ self.assert_status_map(controller.POST,
+ (404, 404, 404, 403, 403, 403, 403), 403)
+ self.assert_status_map(controller.POST,
+ (404, 404, 404, 409, 409, 409, 409), 409)
def test_connection_refused(self):
self.app.account_ring.get_nodes('account')