Made 507s report drive, if known.

This functionality was lost with the swob change, but is back now.

Change-Id: I13b3154080a7c601235711b274e4899efb6adc93
This commit is contained in:
gholt 2012-12-18 01:18:57 +00:00
parent 2a9bf20065
commit 52a2a65ed4
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.
"""
from collections import defaultdict
from cStringIO import StringIO
import UserDict
import time
@ -87,7 +88,7 @@ RESPONSE_REASONS = {
504: ('Gateway Timeout', 'A timeout has occurred speaking to a '
'backend server.'),
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]
if 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)
return [body]
return ['']

View File

@ -772,6 +772,20 @@ class TestResponse(unittest.TestCase):
env['HTTP_HOST'] = '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):
def test_tzname(self):