summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTim Burke <tim.burke@gmail.com>2022-01-11 16:05:39 -0800
committerTim Burke <tim.burke@gmail.com>2022-01-11 16:39:38 -0800
commitf1858d89e0e1889664ced654755c508f47a0c1f3 (patch)
tree8fde46aff27506a596d30d306baf94028a47fc1c /test
parent3f5d5b0252b3690af1e6577bf6584efe506f15fe (diff)
downloadpython-swiftclient-f1858d89e0e1889664ced654755c508f47a0c1f3.tar.gz
Add option to skip container PUT during upload
Currently, a user with read/write access to a container (but without access to creat new containers) recieves a warning every time they upload. Now, allow them to avoid the extra request and warning by specifying --skip-container-put on the command line. This is also useful when testing: developers can HEAD a container to ensure it's in memcache, shut down all container servers, then upload and creaate a bunch of async pendings. Previously, the 503 on container PUT would prevent the object upload from even being attempted. Closes-Bug: 1317956 Related-Bug: 1204558 Change-Id: I3d9129a0b6b65c6c6187ae6af003b221afceef47 Related-Change: If1f8a02ee7459ea2158ffa6e958f67d299ec529e
Diffstat (limited to 'test')
-rw-r--r--test/unit/test_shell.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/unit/test_shell.py b/test/unit/test_shell.py
index 295c918..2331eaa 100644
--- a/test/unit/test_shell.py
+++ b/test/unit/test_shell.py
@@ -912,6 +912,48 @@ class TestShell(unittest.TestCase):
query_string='multipart-manifest=put',
response_dict=mock.ANY)
+ @mock.patch('swiftclient.shell.walk')
+ @mock.patch('swiftclient.service.Connection')
+ def test_upload_skip_container_put(self, connection, walk):
+ connection.return_value.head_object.return_value = {
+ 'content-length': '0'}
+ connection.return_value.put_object.return_value = EMPTY_ETAG
+ connection.return_value.attempts = 0
+ argv = ["", "upload", "container", "--skip-container-put",
+ self.tmpfile, "-H", "X-Storage-Policy:one",
+ "--meta", "Color:Blue"]
+ swiftclient.shell.main(argv)
+ connection.return_value.put_container.assert_not_called()
+
+ connection.return_value.put_object.assert_called_with(
+ 'container',
+ self.tmpfile.lstrip('/'),
+ mock.ANY,
+ content_length=0,
+ headers={'x-object-meta-mtime': mock.ANY,
+ 'X-Storage-Policy': 'one',
+ 'X-Object-Meta-Color': 'Blue'},
+ response_dict={})
+
+ # Upload in segments
+ connection.return_value.head_container.return_value = {
+ 'x-storage-policy': 'one'}
+ argv = ["", "upload", "container", "--skip-container-put",
+ self.tmpfile, "-S", "10"]
+ with open(self.tmpfile, "wb") as fh:
+ fh.write(b'12345678901234567890')
+ swiftclient.shell.main(argv)
+ # Both base and segments container are assumed to exist already
+ connection.return_value.put_container.assert_not_called()
+ connection.return_value.put_object.assert_called_with(
+ 'container',
+ self.tmpfile.lstrip('/'),
+ '',
+ content_length=0,
+ headers={'x-object-manifest': mock.ANY,
+ 'x-object-meta-mtime': mock.ANY},
+ response_dict={})
+
@mock.patch('swiftclient.service.SwiftService.upload')
def test_upload_object_with_account_readonly(self, upload):
argv = ["", "upload", "container", self.tmpfile]