Merge "Made 507s report drive, if known."

This commit is contained in:
Jenkins 2012-12-18 06:12:22 +00:00 committed by Gerrit Code Review
commit c840bd44a7
2 changed files with 18 additions and 1 deletions

View File

@ -21,6 +21,7 @@ environments and response values into objects that are more friendly to
interact with. interact with.
""" """
from collections import defaultdict
from cStringIO import StringIO from cStringIO import StringIO
import UserDict import UserDict
import time import time
@ -87,7 +88,7 @@ RESPONSE_REASONS = {
504: ('Gateway Timeout', 'A timeout has occurred speaking to a ' 504: ('Gateway Timeout', 'A timeout has occurred speaking to a '
'backend server.'), 'backend server.'),
507: ('Insufficient Storage', 'There was not enough space to save the ' 507: ('Insufficient Storage', 'There was not enough space to save the '
'resource.'), 'resource. Drive: %(drive)s'),
} }
@ -964,6 +965,8 @@ class Response(object):
title, exp = RESPONSE_REASONS[self.status_int] title, exp = RESPONSE_REASONS[self.status_int]
if exp: if exp:
body = '<html><h1>%s</h1><p>%s</p></html>' % (title, exp) body = '<html><h1>%s</h1><p>%s</p></html>' % (title, exp)
if '%(' in body:
body = body % defaultdict(lambda: 'unknown', self.__dict__)
self.content_length = len(body) self.content_length = len(body)
return [body] return [body]
return [''] return ['']

View File

@ -772,6 +772,20 @@ class TestResponse(unittest.TestCase):
env['HTTP_HOST'] = 'someother:5678' env['HTTP_HOST'] = 'someother:5678'
self.assertEquals(resp.host_url(), 'https://someother:5678') self.assertEquals(resp.host_url(), 'https://someother:5678')
def test_507(self):
resp = swift.common.swob.HTTPInsufficientStorage()
content = ''.join(resp._response_iter(resp.app_iter, resp._body))
self.assertEquals(
content,
'<html><h1>Insufficient Storage</h1><p>There was not enough space '
'to save the resource. Drive: unknown</p></html>')
resp = swift.common.swob.HTTPInsufficientStorage(drive='sda1')
content = ''.join(resp._response_iter(resp.app_iter, resp._body))
self.assertEquals(
content,
'<html><h1>Insufficient Storage</h1><p>There was not enough space '
'to save the resource. Drive: sda1</p></html>')
class TestUTC(unittest.TestCase): class TestUTC(unittest.TestCase):
def test_tzname(self): def test_tzname(self):