From 4ccf75fc35c287ac3888baca7e852b3c1ea94b48 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Wed, 22 Feb 2017 22:35:21 -0500 Subject: [PATCH] Log correct status code for conditional requests Previously, we'd log a 200 even when we were returning a 412 or 304 Change-Id: I66c871f1f15fb43f19d59331b05cc7567ce10063 Closes-Bug: 1667122 --- swift/obj/server.py | 1 + test/unit/obj/test_server.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/swift/obj/server.py b/swift/obj/server.py index be0f68575e..b6d911656a 100644 --- a/swift/obj/server.py +++ b/swift/obj/server.py @@ -1113,6 +1113,7 @@ class ObjectController(BaseStorageServer): ' %(path)s '), {'method': req.method, 'path': req.path}) res = HTTPInternalServerError(body=traceback.format_exc()) trans_time = time.time() - start_time + res.fix_conditional_response() if self.log_requests: log_line = get_log_line(req, res, trans_time, '') if req.method in ('REPLICATE', 'SSYNC') or \ diff --git a/test/unit/obj/test_server.py b/test/unit/obj/test_server.py index 488f2a55f6..7114c78209 100644 --- a/test/unit/obj/test_server.py +++ b/test/unit/obj/test_server.py @@ -2862,6 +2862,9 @@ class TestObjectController(unittest.TestCase): headers={'If-Match': '"11111111111111111111111111111111"'}) resp = req.get_response(self.object_controller) self.assertEqual(resp.status_int, 412) + self.assertIn( + '"GET /sda1/p/a/c/o" 412 - ', + self.object_controller.logger.get_lines_for_level('info')[-1]) req = Request.blank( '/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'GET'}, @@ -6445,7 +6448,7 @@ class TestObjectController(unittest.TestCase): self.assertEqual( self.logger.get_lines_for_level('info'), ['None - - [01/Jan/1970:02:46:41 +0000] "PUT' - ' /sda1/p/a/c/o" 405 - "-" "-" "-" 1.0000 "-"' + ' /sda1/p/a/c/o" 405 91 "-" "-" "-" 1.0000 "-"' ' 1234 -']) def test_call_incorrect_replication_method(self):