From a1cb91993096971934755cae08aa8013c10fc8f9 Mon Sep 17 00:00:00 2001 From: Alistair Coles Date: Wed, 20 Jun 2018 10:09:38 +0100 Subject: [PATCH] Use valid eventlet logger method eventlet<=0.17.4 LoggerFileWrapper does not have an error() method so don't try to call it. Instead, use info() which even in newer eventlet versions does exactly the same as error(). This bug only manifests in unit tests once the Related-Bug has been fixed (see Related-Change). Closes-Bug: #1777836 Related-Bug: #1777701 Related-Change: I68fd9d0263a6720aaf0d90b8ea6da1158105ac01 Change-Id: I46190567549826c811ffa51e9a71a38a20d9ce97 --- swift/common/wsgi.py | 9 +++++++-- test/unit/common/test_wsgi.py | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py index 5bbe604b5c..fe250d5354 100644 --- a/swift/common/wsgi.py +++ b/swift/common/wsgi.py @@ -432,8 +432,13 @@ class SwiftHttpProtocol(wsgi.HttpProtocol): """ Redirect logging other messages by the underlying WSGI software. """ - logger = getattr(self.server.app, 'logger', None) or self.server.log - logger.error('ERROR WSGI: ' + f, *a) + logger = getattr(self.server.app, 'logger', None) + if logger: + logger.error('ERROR WSGI: ' + f, *a) + else: + # eventlet<=0.17.4 doesn't have an error method, and in newer + # versions the output from error is same as info anyway + self.server.log.info('ERROR WSGI: ' + f, *a) class SwiftHttpProxiedProtocol(SwiftHttpProtocol): diff --git a/test/unit/common/test_wsgi.py b/test/unit/common/test_wsgi.py index 6c9d485942..5c6b91c0cb 100644 --- a/test/unit/common/test_wsgi.py +++ b/test/unit/common/test_wsgi.py @@ -1043,14 +1043,14 @@ class TestSwiftHttpProtocol(unittest.TestCase): delattr(proto_obj.server.app, 'logger') proto_obj.log_message('a%sc', 'b') - self.assertEqual([mock.call.error('ERROR WSGI: a%sc', 'b')], + self.assertEqual([mock.call.info('ERROR WSGI: a%sc', 'b')], proto_obj.server.log.mock_calls) proto_obj.server.log.reset_mock() proto_obj.server.app.logger = None proto_obj.log_message('a%sc', 'b') - self.assertEqual([mock.call.error('ERROR WSGI: a%sc', 'b')], + self.assertEqual([mock.call.info('ERROR WSGI: a%sc', 'b')], proto_obj.server.log.mock_calls) def test_swift_http_protocol_parse_request_no_proxy(self):