Created
December 26, 2017 09:49
-
-
Save bloodeagle40234/055732e0495633b61f00a791a182b9ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/swift/common/internal_client.py b/swift/common/internal_client.py | |
index 529005f..b92e70a 100644 | |
--- a/swift/common/internal_client.py | |
+++ b/swift/common/internal_client.py | |
@@ -197,6 +197,11 @@ class InternalClient(object): | |
return resp | |
except (Exception, Timeout): | |
exc_type, exc_value, exc_traceback = exc_info() | |
+ else: | |
+ # Drain all response body to log correct status, | |
+ # even if we'll do retry | |
+ for iter_body in resp.app_iter: | |
+ pass | |
# sleep only between tries, not after each one | |
if attempt < self.request_tries - 1: | |
sleep(2 ** (attempt + 1)) | |
diff --git a/test/unit/common/test_internal_client.py b/test/unit/common/test_internal_client.py | |
index e075d1b..8b36817 100644 | |
--- a/test/unit/common/test_internal_client.py | |
+++ b/test/unit/common/test_internal_client.py | |
@@ -28,8 +28,10 @@ from test.unit import FakeLogger | |
from swift.common import exceptions, internal_client, swob | |
from swift.common.header_key_dict import HeaderKeyDict | |
from swift.common.storage_policy import StoragePolicy | |
+from swift.common.middleware.proxy_logging import ProxyLoggingMiddleware | |
-from test.unit import with_tempdir, write_fake_ring, patch_policies | |
+from test.unit import with_tempdir, write_fake_ring, patch_policies, \ | |
+ DebugLogger | |
from test.unit.common.middleware.helpers import FakeSwift | |
if six.PY3: | |
@@ -434,6 +436,26 @@ class TestInternalClient(unittest.TestCase): | |
self.assertEqual(client.env['PATH_INFO'], path) | |
self.assertEqual(client.env['HTTP_X_TEST'], path) | |
+ def test_make_request_error_case(self): | |
+ class InternalClient(internal_client.InternalClient): | |
+ def __init__(self): | |
+ self.logger = DebugLogger() | |
+ # wrap the fake app with ProxyLoggingMiddleware | |
+ self.app = ProxyLoggingMiddleware(self.fake_app, {}, self.logger) | |
+ self.user_agent = 'some_agent' | |
+ self.request_tries = 3 | |
+ | |
+ def fake_app(self, env, start_response): | |
+ body = 'fake error response' | |
+ start_response('409 Ok', [('Content-Length', str(len(body)))]) | |
+ return [body] | |
+ | |
+ client = InternalClient() | |
+ with self.assertRaises(internal_client.UnexpectedResponse) as e: | |
+ resp = client.make_request('DELETE', '/container', {}, (200,)) | |
+ for logline in client.logger.get_lines_for_level('info'): | |
+ self.assertIn('409', logline) | |
+ | |
def test_make_request_codes(self): | |
class InternalClient(internal_client.InternalClient): | |
def __init__(self): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment