From 4c8512afb16c831f9d58b58457aa9b2adfda88df Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Mon, 27 Apr 2020 14:04:51 -0700 Subject: [PATCH] Use separate name for HeaderKeyDict var vs list of response headers Closes-Bug: #1875538 Change-Id: I1bcef61157594329f6978f7380bf7293aa1ca65e Related-Change: Ia832e9bab13167948f01bc50aa8a61974ce189fb --- swift/proxy/controllers/obj.py | 10 ++++++---- test/unit/proxy/controllers/test_obj.py | 12 ++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/swift/proxy/controllers/obj.py b/swift/proxy/controllers/obj.py index 68472b4be3..058c445f10 100644 --- a/swift/proxy/controllers/obj.py +++ b/swift/proxy/controllers/obj.py @@ -2441,10 +2441,12 @@ class ECObjectController(BaseObjectController): headers = [] for getter, _parts_iter in bad_bucket.get_responses(): if best_bucket and best_bucket.durable: - headers = HeaderKeyDict(getter.last_headers) - t_data_file = headers.get('X-Backend-Data-Timestamp') - t_obj = headers.get('X-Backend-Timestamp', - headers.get('X-Timestamp')) + bad_resp_headers = HeaderKeyDict(getter.last_headers) + t_data_file = bad_resp_headers.get( + 'X-Backend-Data-Timestamp') + t_obj = bad_resp_headers.get( + 'X-Backend-Timestamp', + bad_resp_headers.get('X-Timestamp')) bad_ts = Timestamp(t_data_file or t_obj or '0') if bad_ts <= Timestamp(best_bucket.timestamp_str): # We have reason to believe there's still good data diff --git a/test/unit/proxy/controllers/test_obj.py b/test/unit/proxy/controllers/test_obj.py index b7ab7d335a..12849962b7 100644 --- a/test/unit/proxy/controllers/test_obj.py +++ b/test/unit/proxy/controllers/test_obj.py @@ -2280,6 +2280,18 @@ class TestECObjController(ECObjectControllerMixin, unittest.TestCase): self.assertIn('Accept-Ranges', resp.headers) self.assertNotIn('Connection', resp.headers) + def test_GET_not_found_when_404_newer(self): + # if proxy receives a 404, it keeps waiting for other connections until + # max number of nodes in hopes of finding an object, but if 404 is + # more recent than a 200, then it should ignore 200 and return 404 + req = swift.common.swob.Request.blank('/v1/a/c/o') + rest = 2 * self.policy.object_ring.replica_count - 2 + codes = [200, 404] + [200] * rest + ts_iter = iter([1, 2] + [1] * rest) + with set_http_connect(*codes, timestamps=ts_iter): + resp = req.get_response(self.app) + self.assertEqual(resp.status_int, 404) + def _test_if_match(self, method): num_responses = self.policy.ec_ndata if method == 'GET' else 1