diff options
author | Tim Burke <tim.burke@gmail.com> | 2019-04-10 16:22:27 -0700 |
---|---|---|
committer | Tim Burke <tim.burke@gmail.com> | 2019-08-08 10:36:41 -0700 |
commit | b960279280199f59417ad3e20ca5de11241ef1b0 (patch) | |
tree | a5535efe652d3d326ec04f136c6d1986d7ddd4f1 /tests/unit/test_shell.py | |
parent | 12bd870a02fc3528f45d27152c62fb0b9598bc84 (diff) | |
download | python-swiftclient-b960279280199f59417ad3e20ca5de11241ef1b0.tar.gz |
Fix SLO re-upload
Previously, if you uploaded a file as an SLO then re-uploaded it
with the same segment size and mtime, the second upload would
go delete the segments it just (re)uploaded. This was due to
us tracking old_slo_manifest_paths and new_slo_manifest_paths
in different formats; one would have a leading slash while the
other would not.
Now, normalize to the stripped-slash version so we stop deleting
segments we just uploaded.
Change-Id: Ibcbed3df4febe81cdf13855656e2daaca8d521b4
(cherry picked from commit 9021a58c240e156f54ffafdc4609868f348d3ebc)
(cherry picked from commit 2cd8b86075997f2997118bd92286849ddb0c93d7)
Diffstat (limited to 'tests/unit/test_shell.py')
-rw-r--r-- | tests/unit/test_shell.py | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/tests/unit/test_shell.py b/tests/unit/test_shell.py index 91496b8..ffea060 100644 --- a/tests/unit/test_shell.py +++ b/tests/unit/test_shell.py @@ -799,11 +799,11 @@ class TestShell(unittest.TestCase): response_dict={}) expected_delete_calls = [ mock.call( - b'container1', b'old_seg1', + 'container1', 'old_seg1', response_dict={} ), mock.call( - b'container2', b'old_seg2', + 'container2', 'old_seg2', response_dict={} ) ] @@ -835,6 +835,46 @@ class TestShell(unittest.TestCase): self.assertFalse(connection.return_value.delete_object.mock_calls) @mock.patch('swiftclient.service.Connection') + def test_reupload_leaves_slo_segments(self, connection): + with open(self.tmpfile, "wb") as fh: + fh.write(b'12345678901234567890') + mtime = '{:.6f}'.format(os.path.getmtime(self.tmpfile)) + expected_segments = [ + 'container_segments/{}/slo/{}/20/10/{:08d}'.format( + self.tmpfile[1:], mtime, i) + for i in range(2) + ] + + # Test re-upload overwriting a manifest doesn't remove + # segments it just wrote + connection.return_value.head_container.return_value = { + 'x-storage-policy': 'one'} + connection.return_value.attempts = 0 + argv = ["", "upload", "container", self.tmpfile, + "--use-slo", "-S", "10"] + connection.return_value.head_object.side_effect = [ + {'x-static-large-object': 'true', # For the upload call + 'content-length': '20'}] + connection.return_value.get_object.return_value = ( + {}, + # we've already *got* the expected manifest! + json.dumps([ + {'name': seg} for seg in expected_segments + ]).encode('ascii') + ) + connection.return_value.put_object.return_value = ( + 'd41d8cd98f00b204e9800998ecf8427e') + swiftclient.shell.main(argv) + connection.return_value.put_object.assert_called_with( + 'container', + self.tmpfile[1:], # drop leading / + mock.ANY, + headers={'x-object-meta-mtime': mtime}, + query_string='multipart-manifest=put', + response_dict={}) + self.assertFalse(connection.return_value.delete_object.mock_calls) + + @mock.patch('swiftclient.service.Connection') def test_upload_delete_dlo_segments(self, connection): # Upload delete existing segments connection.return_value.head_container.return_value = { |