Instead of using os.system(), we can open the file that we want to put
via stdin, and pass that file handle to test_s3cmd(), which gets it to
the Popen() call as the stdin argument. This way, any failure in
s3cmd we can capture and report like for all other tests.
... | ... |
@@ -87,7 +87,7 @@ if not os.path.isdir('testsuite/crappy-file-name'): |
87 | 87 |
# TODO: also unpack if the tarball is newer than the directory timestamp |
88 | 88 |
# for instance when a new version was pulled from SVN. |
89 | 89 |
|
90 |
-def test(label, cmd_args = [], retcode = 0, must_find = [], must_not_find = [], must_find_re = [], must_not_find_re = []): |
|
90 |
+def test(label, cmd_args = [], retcode = 0, must_find = [], must_not_find = [], must_find_re = [], must_not_find_re = [], stdin = None): |
|
91 | 91 |
def command_output(): |
92 | 92 |
print "----" |
93 | 93 |
print " ".join([" " in arg and "'%s'" % arg or arg for arg in cmd_args]) |
... | ... |
@@ -137,7 +137,7 @@ def test(label, cmd_args = [], retcode = 0, must_find = [], must_not_find = [], |
137 | 137 |
if not cmd_args: |
138 | 138 |
return skip() |
139 | 139 |
|
140 |
- p = Popen(cmd_args, stdout = PIPE, stderr = STDOUT, universal_newlines = True, close_fds = True) |
|
140 |
+ p = Popen(cmd_args, stdin = stdin, stdout = PIPE, stderr = STDOUT, universal_newlines = True, close_fds = True) |
|
141 | 141 |
stdout, stderr = p.communicate() |
142 | 142 |
if type(retcode) not in [list, tuple]: retcode = [retcode] |
143 | 143 |
if p.returncode not in retcode: |
... | ... |
@@ -342,23 +342,24 @@ test_s3cmd("List bucket recursive", ['ls', '--recursive', pbucket(1)], |
342 | 342 |
test_flushdir("Clean testsuite-out/", "testsuite-out") |
343 | 343 |
|
344 | 344 |
## ====== Put from stdin |
345 |
-cmd_args = ['cat', 'testsuite/single-file/single-file.txt', '|', 'python2', 's3cmd', 'put', '-', '%s/single-file/single-file.txt' % pbucket(1), '> /dev/null 2>&1'] |
|
346 |
-# hack - execute using os.system to match user's usage of s3cmd exactly |
|
347 |
-os.system(' '.join(cmd_args)) |
|
348 |
-test_s3cmd("Put from stdin", ['ls', '%s/single-file/single-file.txt' % pbucket(1)], |
|
349 |
- must_find = ['%s/single-file/single-file.txt' % pbucket(1)]) |
|
345 |
+f = open('testsuite/single-file/single-file.txt', 'r') |
|
346 |
+test_s3cmd("Put from stdin", ['put', '-', '%s/single-file/single-file.txt' % pbucket(1)], |
|
347 |
+ must_find = ["File '-' stored as '%s/single-file/single-file.txt'" % pbucket(1)], |
|
348 |
+ stdin = f) |
|
349 |
+f.close() |
|
350 | 350 |
|
351 | 351 |
## ====== Multipart put |
352 |
-os.system('dd if=/dev/urandom of=testsuite-out/urandom.bin bs=1M count=16') |
|
352 |
+os.system('dd if=/dev/urandom of=testsuite-out/urandom.bin bs=1M count=16 > /dev/null 2>&1') |
|
353 | 353 |
test_s3cmd("Put multipart", ['put', '--multipart-chunk-size-mb=5', 'testsuite-out/urandom.bin', '%s/urandom.bin' % pbucket(1)], |
354 |
- must_not_find = 'abortmp') |
|
354 |
+ must_not_find = ['abortmp']) |
|
355 | 355 |
|
356 | 356 |
## ====== Multipart put from stdin |
357 |
-cmd_args = ['cat', 'testsuite-out/urandom.bin', '|', 'python2', 's3cmd', 'put', '--multipart-chunk-size-mb=5', '-', '%s/urandom2.bin' % pbucket(1), '> /dev/null 2>&1'] |
|
358 |
-# hack - execute using os.system to match user's usage of s3cmd exactly |
|
359 |
-os.system(' '.join(cmd_args)) |
|
360 |
-test_s3cmd("Multipart large put from stdin", ['ls', '%s/urandom2.bin' % pbucket(1)], |
|
361 |
- must_find = ['%s/urandom2.bin' % pbucket(1)]) |
|
357 |
+f = open('testsuite-out/urandom.bin', 'r') |
|
358 |
+test_s3cmd("Multipart large put from stdin", ['put', '--multipart-chunk-size-mb=5', '-', '%s/urandom2.bin' % pbucket(1)], |
|
359 |
+ must_find = ['%s/urandom2.bin' % pbucket(1)], |
|
360 |
+ must_not_find = ['abortmp'], |
|
361 |
+ stdin = f) |
|
362 |
+f.close() |
|
362 | 363 |
|
363 | 364 |
## ====== Clean up local destination dir |
364 | 365 |
test_flushdir("Clean testsuite-out/", "testsuite-out") |