Fix best response to return correct status

Current best response could return "503 Internal Server Error".
However, "503" means "Service Unavailable". (The status int of
Internal Server Error is 500)

This patch fixes the response status as "503 Service Unavailable"

Change-Id: I88b8c52c26b19e9e76ba3375f1e16ced555ed54c
This commit is contained in:
Kota Tsuyuzaki 2015-04-15 11:25:13 -07:00 committed by Christian Schwede
parent f6628ae2c4
commit e440d6aed8
2 changed files with 3 additions and 4 deletions

View File

@ -49,7 +49,7 @@ from swift.common.http import is_informational, is_success, is_redirection, \
HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVICE_UNAVAILABLE, \
HTTP_INSUFFICIENT_STORAGE, HTTP_UNAUTHORIZED, HTTP_CONTINUE
from swift.common.swob import Request, Response, HeaderKeyDict, Range, \
HTTPException, HTTPRequestedRangeNotSatisfiable
HTTPException, HTTPRequestedRangeNotSatisfiable, HTTPServiceUnavailable
from swift.common.request_helpers import strip_sys_meta_prefix, \
strip_user_meta_prefix, is_user_meta, is_sys_meta, is_sys_or_user_meta
from swift.common.storage_policy import POLICIES
@ -1256,10 +1256,9 @@ class Controller(object):
quorum_size=quorum_size)
if not resp:
resp = Response(request=req)
resp = HTTPServiceUnavailable(request=req)
self.app.logger.error(_('%(type)s returning 503 for %(statuses)s'),
{'type': server_type, 'statuses': statuses})
resp.status = '503 Internal Server Error'
return resp

View File

@ -579,7 +579,7 @@ class TestFuncs(unittest.TestCase):
overrides = {302: 204, 100: 204}
resp = base.best_response(req, statuses, reasons, bodies, server_type,
headers=headers, overrides=overrides)
self.assertEqual(resp.status, '503 Internal Server Error')
self.assertEqual(resp.status, '503 Service Unavailable')
# next make a 404 quorum and make sure the last delete (real) 404
# status is the one returned.