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
This commit is contained in:
Alex Yang
2012-08-17 19:44:21 +08:00
parent 73b00ca9de
commit 6dbac845d5
2 changed files with 44 additions and 12 deletions

View File

@@ -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

View File

@@ -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')