From 4500ff340f021e4e5f6fd53960de03cb3c207925 Mon Sep 17 00:00:00 2001 From: Kota Tsuyuzaki Date: Wed, 13 May 2015 00:43:59 -0700 Subject: [PATCH] Fix the missing SLO state on fast-post When using fast-post and POST (i.e. metadata update) is requested to a SLO manifest files, current Swift drops the 'X-Static-Large-Object' header from the existing metadata. It results in breaking the SLO state because the manifest missing the 'X-Static-Large-Object' metadata will be maintained as a normal files. This patch fixes object-server to keep the existing 'X-Static-Large-Object' flag and then keep the SLO state. Change-Id: Ib1eb569071372c322dd105c52baeeb094003291e Closes-bug: #1453807 --- swift/obj/server.py | 6 ++++++ test/functional/tests.py | 4 ++-- test/unit/obj/test_server.py | 7 +++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/swift/obj/server.py b/swift/obj/server.py index d16ec50f54..e0d43920c5 100644 --- a/swift/obj/server.py +++ b/swift/obj/server.py @@ -444,6 +444,11 @@ class ObjectController(BaseStorageServer): override = key.lower().replace(override_prefix, 'x-') update_headers[override] = val + def _preserve_slo_manifest(self, update_metadata, orig_metadata): + if 'X-Static-Large-Object' in orig_metadata: + update_metadata['X-Static-Large-Object'] = \ + orig_metadata['X-Static-Large-Object'] + @public @timing_stats() def POST(self, request): @@ -473,6 +478,7 @@ class ObjectController(BaseStorageServer): request=request, headers={'X-Backend-Timestamp': orig_timestamp.internal}) metadata = {'X-Timestamp': req_timestamp.internal} + self._preserve_slo_manifest(metadata, orig_metadata) metadata.update(val for val in request.headers.items() if is_user_meta('object', val[0])) for header_key in self.allowed_headers: diff --git a/test/functional/tests.py b/test/functional/tests.py index 8c64d8d12d..d72e665f60 100644 --- a/test/functional/tests.py +++ b/test/functional/tests.py @@ -2450,8 +2450,6 @@ class TestSlo(Base): self.fail("COPY didn't copy the manifest (invalid json on GET)") def _make_manifest(self): - # To avoid the bug 1453807 on fast-post, make a new manifest - # for post test. file_item = self.env.container.file("manifest-post") seg_info = self.env.seg_info file_item.write( @@ -2473,6 +2471,7 @@ class TestSlo(Base): updated = self.env.container.file("manifest-post") updated.info() updated.header_fields([('user-meta', 'x-object-meta-post')]) # sanity + updated.header_fields([('slo', 'x-static-large-object')]) updated_contents = updated.read(parms={'multipart-manifest': 'get'}) try: json.loads(updated_contents) @@ -2493,6 +2492,7 @@ class TestSlo(Base): updated.info() updated.header_fields( [('user-meta', 'x-object-meta-post')]) # sanity + updated.header_fields([('slo', 'x-static-large-object')]) updated_contents = updated.read( parms={'multipart-manifest': 'get'}) try: diff --git a/test/unit/obj/test_server.py b/test/unit/obj/test_server.py index 1fb966c991..3a5119369b 100755 --- a/test/unit/obj/test_server.py +++ b/test/unit/obj/test_server.py @@ -253,6 +253,7 @@ class TestObjectController(unittest.TestCase): 'X-Object-Manifest': 'c/bar', 'Content-Encoding': 'gzip', 'Content-Disposition': 'bar', + 'X-Static-Large-Object': 'True', }) req.body = 'VERIFY' resp = req.get_response(self.object_controller) @@ -263,7 +264,8 @@ class TestObjectController(unittest.TestCase): "Foo" not in resp.headers and "Content-Encoding" in resp.headers and "X-Object-Manifest" in resp.headers and - "Content-Disposition" in resp.headers) + "Content-Disposition" in resp.headers and + "X-Static-Large-Object" in resp.headers) self.assertEqual(resp.headers['Content-Type'], 'application/x-test') timestamp = normalize_timestamp(time()) @@ -282,7 +284,8 @@ class TestObjectController(unittest.TestCase): "Content-Encoding" not in resp.headers and "X-Object-Manifest" not in resp.headers and "Content-Disposition" not in resp.headers and - "X-Object-Meta-3" in resp.headers) + "X-Object-Meta-3" in resp.headers and + "X-Static-Large-Object" in resp.headers) self.assertEqual(resp.headers['Content-Type'], 'application/x-test') # Test for empty metadata