diff options
-rw-r--r-- | swiftclient/service.py | 2 | ||||
-rwxr-xr-x | swiftclient/shell.py | 11 | ||||
-rw-r--r-- | tests/unit/test_service.py | 35 | ||||
-rw-r--r-- | tests/unit/test_shell.py | 6 |
4 files changed, 24 insertions, 30 deletions
diff --git a/swiftclient/service.py b/swiftclient/service.py index 31ea898..7b5ecd4 100644 --- a/swiftclient/service.py +++ b/swiftclient/service.py @@ -1917,6 +1917,8 @@ class SwiftService(object): return res # Merge the command line header options to the put_headers + put_headers.update(split_headers( + options['meta'], 'X-Object-Meta-')) put_headers.update(split_headers(options['header'], '')) # Don't do segment job if object is not big enough, and never do diff --git a/swiftclient/shell.py b/swiftclient/shell.py index 894cd29..43fcf47 100755 --- a/swiftclient/shell.py +++ b/swiftclient/shell.py @@ -891,8 +891,8 @@ def st_copy(parser, args, output_manager): st_upload_options = '''[--changed] [--skip-identical] [--segment-size <size>] [--segment-container <container>] [--leave-segments] [--object-threads <thread>] [--segment-threads <threads>] - [--header <header>] [--use-slo] [--ignore-checksum] - [--object-name <object-name>] + [--meta <name:value>] [--header <header>] [--use-slo] + [--ignore-checksum] [--object-name <object-name>] <container> <file_or_directory> [<file_or_directory>] [...] ''' @@ -928,6 +928,9 @@ Optional arguments: --segment-threads <threads> Number of threads to use for uploading object segments. Default is 10. + -m, --meta <name:value> + Sets a meta data item. This option may be repeated. + Example: -m Color:Blue -m Size:Large -H, --header <header:value> Adds a customized request header. This option may be repeated. Example: -H "content-type:text/plain" @@ -979,6 +982,10 @@ def st_upload(parser, args, output_manager): help='Number of threads to use for uploading object segments. ' 'Its value must be a positive integer. Default is 10.') parser.add_argument( + '-m', '--meta', action='append', dest='meta', default=[], + help='Sets a meta data item. This option may be repeated. ' + 'Example: -m Color:Blue -m Size:Large') + parser.add_argument( '-H', '--header', action='append', dest='header', default=[], help='Set request headers with the syntax header:value. ' ' This option may be repeated. Example: -H "content-type:text/plain" ' diff --git a/tests/unit/test_service.py b/tests/unit/test_service.py index 54f0a11..5ccc081 100644 --- a/tests/unit/test_service.py +++ b/tests/unit/test_service.py @@ -1146,14 +1146,9 @@ class TestServiceUpload(_TestServiceBase): container='test_c', source=f.name, obj='ใในใ/dummy.dat', - options={'changed': False, - 'skip_identical': False, - 'leave_segments': True, - 'header': '', - 'segment_size': 10, - 'segment_container': None, - 'use_slo': False, - 'checksum': True}) + options=dict(s._options, + segment_size=10, + leave_segments=True)) mtime = r['headers']['x-object-meta-mtime'] self.assertEqual(expected_mtime, mtime) @@ -1350,12 +1345,8 @@ class TestServiceUpload(_TestServiceBase): container='test_c', source=f.name, obj='test_o', - options={'changed': False, - 'skip_identical': False, - 'leave_segments': True, - 'header': '', - 'segment_size': 0, - 'checksum': True}) + options=dict(s._options, + leave_segments=True)) mtime = r['headers']['x-object-meta-mtime'] self.assertEqual(expected_mtime, mtime) @@ -1405,12 +1396,8 @@ class TestServiceUpload(_TestServiceBase): container='test_c', source=f, obj='test_o', - options={'changed': False, - 'skip_identical': False, - 'leave_segments': True, - 'header': '', - 'segment_size': 0, - 'checksum': True}) + options=dict(s._options, + leave_segments=True)) mtime = float(r['headers']['x-object-meta-mtime']) self.assertEqual(mtime, expected_mtime) @@ -1452,12 +1439,8 @@ class TestServiceUpload(_TestServiceBase): container='test_c', source=f.name, obj='test_o', - options={'changed': False, - 'skip_identical': False, - 'leave_segments': True, - 'header': '', - 'segment_size': 0, - 'checksum': True}) + options=dict(s._options, + leave_segments=True)) self.assertIs(r['success'], False) self.assertIn('md5 mismatch', str(r.get('error'))) diff --git a/tests/unit/test_shell.py b/tests/unit/test_shell.py index 2e20a87..110fb01 100644 --- a/tests/unit/test_shell.py +++ b/tests/unit/test_shell.py @@ -624,7 +624,8 @@ class TestShell(unittest.TestCase): connection.return_value.put_object.return_value = EMPTY_ETAG connection.return_value.attempts = 0 argv = ["", "upload", "container", self.tmpfile, - "-H", "X-Storage-Policy:one"] + "-H", "X-Storage-Policy:one", + "--meta", "Color:Blue"] swiftclient.shell.main(argv) connection.return_value.put_container.assert_called_once_with( 'container', @@ -637,7 +638,8 @@ class TestShell(unittest.TestCase): mock.ANY, content_length=0, headers={'x-object-meta-mtime': mock.ANY, - 'X-Storage-Policy': 'one'}, + 'X-Storage-Policy': 'one', + 'X-Object-Meta-Color': 'Blue'}, response_dict={}) # upload to pseudo-folder (via <container> param) |