From 52a2a65ed4b0ab5174eaaba2c43ac80b63971380 Mon Sep 17 00:00:00 2001 From: gholt Date: Tue, 18 Dec 2012 01:18:57 +0000 Subject: [PATCH] Made 507s report drive, if known. This functionality was lost with the swob change, but is back now. Change-Id: I13b3154080a7c601235711b274e4899efb6adc93 --- swift/common/swob.py | 5 ++++- test/unit/common/test_swob.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/swift/common/swob.py b/swift/common/swob.py index 1fcff0423f..47a9069cee 100755 --- a/swift/common/swob.py +++ b/swift/common/swob.py @@ -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 = '

%s

%s

' % (title, exp) + if '%(' in body: + body = body % defaultdict(lambda: 'unknown', self.__dict__) self.content_length = len(body) return [body] return [''] diff --git a/test/unit/common/test_swob.py b/test/unit/common/test_swob.py index ca065c0509..3c823b7f5f 100755 --- a/test/unit/common/test_swob.py +++ b/test/unit/common/test_swob.py @@ -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, + '

Insufficient Storage

There was not enough space ' + 'to save the resource. Drive: unknown

') + resp = swift.common.swob.HTTPInsufficientStorage(drive='sda1') + content = ''.join(resp._response_iter(resp.app_iter, resp._body)) + self.assertEquals( + content, + '

Insufficient Storage

There was not enough space ' + 'to save the resource. Drive: sda1

') + class TestUTC(unittest.TestCase): def test_tzname(self):