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:
@@ -439,7 +439,9 @@ class Controller(object):
|
|||||||
self.app.account_ring, partition, 'PUT',
|
self.app.account_ring, partition, 'PUT',
|
||||||
path, [headers] * len(nodes))
|
path, [headers] * len(nodes))
|
||||||
if not is_success(resp.status_int):
|
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
|
result_code = HTTP_OK
|
||||||
if self.app.memcache and result_code in (HTTP_OK, HTTP_NOT_FOUND):
|
if self.app.memcache and result_code in (HTTP_OK, HTTP_NOT_FOUND):
|
||||||
if result_code == HTTP_OK:
|
if result_code == HTTP_OK:
|
||||||
@@ -1808,8 +1810,9 @@ class AccountController(Controller):
|
|||||||
self.app.account_ring, partition, 'PUT',
|
self.app.account_ring, partition, 'PUT',
|
||||||
'/' + self.account_name, [headers] * len(nodes))
|
'/' + self.account_name, [headers] * len(nodes))
|
||||||
if not is_success(resp.status_int):
|
if not is_success(resp.status_int):
|
||||||
raise Exception('Could not autocreate account %r' %
|
self.app.logger.warning('Could not autocreate account %r' %
|
||||||
self.account_name)
|
self.account_name)
|
||||||
|
return resp
|
||||||
resp = self.GETorHEAD_base(req, _('Account'), partition, nodes,
|
resp = self.GETorHEAD_base(req, _('Account'), partition, nodes,
|
||||||
req.path_info.rstrip('/'), len(nodes))
|
req.path_info.rstrip('/'), len(nodes))
|
||||||
self.app.logger.timing_since('%s.timing' % (stats_type,), start_time)
|
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.app.account_ring, account_partition, 'PUT',
|
||||||
'/' + self.account_name, [headers] * len(accounts))
|
'/' + self.account_name, [headers] * len(accounts))
|
||||||
if not is_success(resp.status_int):
|
if not is_success(resp.status_int):
|
||||||
raise Exception('Could not autocreate account %r' %
|
self.app.logger.warning('Could not autocreate account %r' %
|
||||||
self.account_name)
|
self.account_name)
|
||||||
|
return resp
|
||||||
self.app.logger.timing_since('POST.timing', start_time)
|
self.app.logger.timing_since('POST.timing', start_time)
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
|||||||
@@ -450,13 +450,28 @@ class TestController(unittest.TestCase):
|
|||||||
proxy_server.http_connect = \
|
proxy_server.http_connect = \
|
||||||
fake_http_connect(404, 404, 404, 503, 201, 503)
|
fake_http_connect(404, 404, 404, 503, 201, 503)
|
||||||
exc = None
|
exc = None
|
||||||
try:
|
partition, nodes, count = \
|
||||||
partition, nodes, count = \
|
self.controller.account_info(self.account, autocreate=True)
|
||||||
self.controller.account_info(self.account, autocreate=True)
|
self.check_account_info_return(partition, nodes, is_none=True)
|
||||||
except Exception, err:
|
self.assertEquals(None, count)
|
||||||
exc = err
|
|
||||||
self.assertEquals(str(exc),
|
self.memcache.store = {}
|
||||||
"Could not autocreate account '/some_account'")
|
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):
|
def check_container_info_return(self, ret, is_none=False):
|
||||||
if is_none:
|
if is_none:
|
||||||
@@ -3812,6 +3827,11 @@ class TestAccountController(unittest.TestCase):
|
|||||||
controller.app.account_autocreate = True
|
controller.app.account_autocreate = True
|
||||||
self.assert_status_map(controller.GET,
|
self.assert_status_map(controller.GET,
|
||||||
(404, 404, 404, 201, 201, 201, 204), 204)
|
(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):
|
def test_HEAD(self):
|
||||||
with save_globals():
|
with save_globals():
|
||||||
@@ -3840,6 +3860,10 @@ class TestAccountController(unittest.TestCase):
|
|||||||
controller.app.account_autocreate = True
|
controller.app.account_autocreate = True
|
||||||
self.assert_status_map(controller.HEAD,
|
self.assert_status_map(controller.HEAD,
|
||||||
(404, 404, 404, 201, 201, 201, 204), 204)
|
(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):
|
def test_POST_autocreate(self):
|
||||||
with save_globals():
|
with save_globals():
|
||||||
@@ -3850,6 +3874,10 @@ class TestAccountController(unittest.TestCase):
|
|||||||
controller.app.account_autocreate = True
|
controller.app.account_autocreate = True
|
||||||
self.assert_status_map(controller.POST,
|
self.assert_status_map(controller.POST,
|
||||||
(404, 404, 404, 201, 201, 201), 201)
|
(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):
|
def test_connection_refused(self):
|
||||||
self.app.account_ring.get_nodes('account')
|
self.app.account_ring.get_nodes('account')
|
||||||
|
|||||||
Reference in New Issue
Block a user