63 Commits

Author SHA1 Message Date
Timur Alperovich
2faea93287 Allow for object uploads > 5GB from stdin.
When uploading from standard input, swiftclient should turn the upload
into an SLO in the case of large objects. This patch picks the
threshold as 10MB (and uses that as the default segment size). The
consumers can also supply the --segment-size option to alter that
threshold and the SLO segment size. The patch does buffer one segment
in memory (which is why 10MB default was chosen).

(test is updated)

Change-Id: Ib13e0b687bc85930c29fe9f151cf96bc53b2e594
2018-01-18 04:56:12 +00:00
Zuul
cde257de5c Merge "Allow --meta on upload" 2017-12-08 19:51:05 +00:00
Tim Burke
638d7c789c Buffer reads from disk
Otherwise, Python defaults to 8k reads which seems kinda terrible.

Change-Id: I3160626e947083af487fd1c3cb0aa6a62646527b
Closes-Bug: #1671621
2017-07-11 17:04:49 -07:00
Tim Burke
484d7ee9b2 Allow --meta on upload
Previously, the --meta option was only allowed on post or copy subcommands.

Change-Id: I87bf0338c34b5e89aa946505bee68dbeb37d784c
Closes-Bug: #1616238
2017-07-06 12:43:11 -07:00
Christopher Bartz
cde73c196d Option to ignore mtime metadata entry.
Currently, the swiftclient upload command passes a custom metadata
header for each object (called object-meta-mtime), whose value is
the current UNIX timestamp. When downloading such an object with the
swiftclient, the mtime header is parsed and passed as the atime and
mtime for the newly created file.

There are use-cases where this is not desired, for example when using
tmp or scratch directories in which files older than a specific date
are deleted. This commit provides a boolean option for ignoring the
mtime header.

Change-Id: If60b389aa910c6f1969b999b5d3b6d0940375686
2017-07-06 10:19:12 -07:00
Jenkins
1d57403668 Merge "Skip checksum validation on partial downloads" 2017-06-22 01:13:26 +00:00
Jenkins
bc3171cfac Merge "Tolerate RFC-compliant ETags" 2017-06-22 01:13:04 +00:00
Tim Burke
527f2ff687 Skip checksum validation on partial downloads
If we get back some partial content, we can't validate the MD5.
That's OK.

Change-Id: Ic1d65272190af0d3d982f3cd06833cac5c791a1e
Closes-Bug: 1642021
2017-04-21 10:30:01 -07:00
Tim Burke
64da481ccd Tolerate RFC-compliant ETags
Since time immemorial, Swift has returned unquoted ETags for plain-old
Swift objects -- I hear tell that we once tried to change this, but
quickly backed it out when some clients broke.

However, some proxies (such as nginx) apparently may force the ETag to
adhere to the RFC, which states [1]:

    An entity-tag consists of an opaque *quoted* string

(emphasis mine). See the related bug for an instance of this happening.

Since we can still get the original ETag easily, we should tolerate the
more-compliant format.

[1] https://tools.ietf.org/html/rfc2616.html#section-3.11 or, if you
    prefer the new ones, https://tools.ietf.org/html/rfc7232#section-2.3

Change-Id: I7cfacab3f250a9443af4b67111ef8088d37d9171
Closes-Bug: 1681529
Related-Bug: 1678976
2017-04-21 10:28:33 -07:00
John Dickinson
0cc4d8af18 respect bulk delete page size and fix logic error
Previously, using SwiftService to delete "many" objects would use
bulk delete if available, but it would not respect the bulk delete
page size. If the number of objects to delete exceeded the bulk delete
page size, SwiftService would ignore the error and nothing would be
deleted.

This patch changes _should_bulk_delete() to be _bulk_delete_page_size();
instead of returning a simple True/False, it returns the page size for
the bulk deleter, or 1 if objects should be deleted one at a time.
Delete SDK calls are then spread across multiple bulk DELETEs if the
requested number of objects to delete exceeds the returned page size.

Fixed the logic in _should_bulk_delete() so that if the object list
is exactly 2x the thread count, it will not bulk delete. This is the
natural conclusion following the logic that existed previously: if
the delete request can be satisfied by every worker thread doing one
or two tasks, don't bulk delete. But if it requires a worker thread
to do three or more tasks, do a bulk delete instead. Previously, the
logic would mean that if every worker thread did exactly two tasks, it
would bulk delete. This patch changes a "<" to a "<=".

Closes-Bug: 1679851
Change-Id: I3c18f89bac1170dc62187114ef06dbe721afcc2e
2017-04-20 09:41:53 -07:00
Kazufumi Noto
809e4cf98f Close file handle after upload job
The opened file for upload is not closed.
This fix prevents possible file handle leak.

Closes-Bug: #1559079
Change-Id: Ibc58667789e8f54c74ae2bbd32717a45f7b30550
2017-03-16 18:03:13 +00:00
Tim Burke
a1e2bcde4a Accept more types of input for headers/meta
Previously, we only accepted iterables of strings like 'Header: Value'.
Now, we'll also accept lists of tuples like ('Header', 'Value') as well
as dictionaries like {'Header': 'Value'}.

This should be more intuitive for application developers, who are
already used to being able to pass dicts or lists of tuples to libraries
like requests.

Change-Id: I93ed2f1e8305f0168b7a4bd90c205b04730da836
2016-11-18 11:47:14 -08:00
Charles Hsu
6cf2bd6626 Add additional headers for HEAD/GET/DELETE requests.
Change-Id: I69276ba711057c122f97deac412e492e313c34dd
Closes-Bug: 1615830
2016-11-07 13:18:29 +08:00
Jenkins
5acefd27e4 Merge "Strip leading/trailing whitespace from headers" 2016-08-25 04:24:16 +00:00
Jenkins
b57044a853 Merge "Add copy object method" 2016-08-24 23:59:34 +00:00
Marek Kaleta
4a2465fb12 Add copy object method
Implement copy object method in swiftclient Connection, Service and CLI.

Although COPY functionality can be accomplished with 'X-Copy-From'
header in PUT request, using copy is more convenient especially when
using copy for updating object metadata non-destructively.

Closes-Bug: 1474939
Change-Id: I1338ac411f418f4adb3d06753d044a484a7f32a4
2016-08-23 14:37:11 -07:00
Tim Burke
8fbe118cea Strip leading/trailing whitespace from headers
New versions of requests will raise an InvalidHeader error otherwise.

Change-Id: Idf3bcd8ac359bdda9a847bf99a78988943374134
Closes-Bug: #1614280
Closes-Bug: #1613814
2016-08-19 19:53:11 +00:00
zheng yin
d460db84ed Modify assert
For example: self.assertEqual(a,None) is equal to self.assertIsNone(a)

Change-Id: I063145d034979cf3d36645a00a30cc27defac7c4
2016-07-26 22:23:43 +08:00
Cheng Li
69bf4634b9 Add an option: disable etag check on downloads
This patch is to add an option of disable etag
check on downloads.

Change-Id: I9ad389dd691942dea6db470ca3f0543eb6e9703e
Closes-bug: #1581147
2016-06-02 22:53:18 +08:00
Jenkins
8ffc5c11ae Merge "Use application/directory content-type for dir markers" 2016-05-19 08:53:50 +00:00
Jenkins
6b065dd4a6 Merge "Identify segments uploaded via swiftclient" 2016-05-02 10:35:20 +00:00
Sergey Gotliv
909bdf8954 Fix downloading from "marker" item
The documentation of "swift download" hints that "marker" option
is supported, but in reality we forgot to patch it through, so
all downloads were always done with the default, empty marker.

Closes-Bug: #1565393
Change-Id: I38bd29d2baa9188b61397dec75ce1d864041653c
2016-04-08 20:55:18 -06:00
Tim Burke
9fd537a082 Use application/directory content-type for dir markers
Previously, we were using a content-type of text/directory, but that is
already defined in RFC 2425 and doesn't reflect our usage:

   The text/directory Content-Type is defined for holding a variety
   of directory information, for example, name, or email address,
   or logo.

(From there it goes on to describe a superset of the vCard format
defined in RFC 2426.)

application/directory, on the other hand, is used by Static Web [1] and
is used by cloudfuse [2]. Seems like as sane a choice as any to
standardize on.

[1] https://github.com/openstack/swift/blob/2.5.0/swift/common/middleware/staticweb.py#L71-L75
[2] https://github.com/redbo/cloudfuse/blob/1.0/README#L105-L106

Change-Id: I19e30484270886292d83f50e7ee997b6e1623ec7
2016-04-08 16:57:51 -07:00
Tim Burke
4a6fa02c28 Identify segments uploaded via swiftclient
...using a new "application/swiftclient-segment" content-type.

Segments uploaded by swiftclient are expected to have a many-to-one
relationship to large objects, rather than the more-general many-to-many
relationship that SLO and DLO generally allow. Later, we may use this
information to make more intelligent decisions, such as when to
automatically clean up segments.

Change-Id: Ie56a3aa10065db754ac572cc37d93f2c901aac60
2016-04-08 13:41:29 -07:00
Tim Burke
f86b2d8138 Clean up some unnecessary variables
Change-Id: Iac93ced6344d4a6fee7e6390e891fde765814c03
2016-03-24 13:06:42 -07:00
Marek Kaleta
51a8a5a7ae Fix SwiftPostObject options usage in SwiftService
SwiftService().post(cont, [SwiftPostObject(obj, options]) currently
ignores options['header'], raises exception when options['headers']
is set and make malformed metadata when options['meta'] is set.

Fix tipos in code, add unittest for SwiftService().post
Closes-Bug: #1560052

Change-Id: Ie460f753492e9b73836b4adfc7c9c0f2130a8a91
2016-03-23 15:38:10 +01:00
Jenkins
c023893dd3 Merge "download method shouldn't download all object" 2016-03-02 11:15:11 +00:00
Hu Bing
b7d20b8a18 download method shouldn't download all object
in python-swiftclient/swiftclient/service.py,
there is a method
def download(self, container=None, objects=None, options=None):

if container is specified but objects not, it download all
objects in specified container.
if both container and objects are specified, it download all
specified objects in the container.

when it comes to the case that, objects argument is specified,
but it turned out to be empty array [ ], the download method
download all the objects under specified container.
this may be not reasonable.

for example,
the objects was not empty when it came from command line,
but it's filtered, maybe by --prefix argument.
at last, it turned out to be empty array.

when calling download method with objects arguments
being empty array, we should download nothing instead of
all the objects under the specified container.

Change-Id: I81aab935533a50b40679c8b3575f298c285233a8
Closes-bug: #1549881
2016-03-01 03:10:34 +08:00
Tim Burke
bed6bbd5ef Drop testtools from test-requirements.txt
My understanding is that it was mainly being used so we could have sane
testing on py26.  With py26 support being dropped, we no longer need it.

Also drop discover from test-requirements.txt, as we don't seem to
actually use it.

Change-Id: Iee04c42890596d3b483c1473169480a3ae19aac8
Related-Change: I37116731db11449d0c374a6a83a3a43789a19d5f
2016-02-12 09:57:58 -08:00
Jenkins
8918c292d7 Merge "more tests for pseudo/dir" 2016-02-10 19:56:27 +00:00
Jenkins
50f3396620 Merge "Fix segmented upload to pseudo-dir via <container>" 2016-02-10 19:55:30 +00:00
Clay Gerrard
9a97b51c0c more tests for pseudo/dir
Change-Id: Idab172aefd8e69ca8e4d623918eba1bc1da91a42
2016-02-09 13:15:22 -08:00
James Nzomo
5ed02345d3 Fix segmented upload to pseudo-dir via <container>
This fix ensures creation and use of the correct default segment
container when pseudo-folder paths are passed via <container> arg.

Change-Id: I90356b041dc9dfbd55eb341271975621759476b9
Closes-Bug: 1532981
Related-Bug: 1478210
2016-02-04 05:02:17 +03:00
Jenkins
fee68f7324 Merge "Don't trust X-Object-Meta-Mtime" 2016-02-01 17:43:03 +00:00
Clay Gerrard
34ae109173 Tighten up to unittests to expect rounding
Change-Id: Ic453fd990ebbf17e0eeabc39b126d2bc14234e23
2016-01-29 19:27:11 -08:00
Tim Burke
337570a03a Don't trust X-Object-Meta-Mtime
Still use it if we can, but stop throwing ValueErrors if it's garbage.

Change-Id: I2cf25b535ad62cfacb7561954a92a4a73d91000a
2016-01-29 16:50:15 -08:00
Ondřej Nový
0fe02eb1c0 mock time in unit test
It's crashing now (sometimes):

_StringException: Traceback (most recent call last):
  File "/build/python-swiftclient-2.6.0/tests/unit/test_service.py", line 1085, in test_upload_object_job_stream
    self.assertAlmostEqual(mtime, expected_mtime, delta=0.5)
  File "/usr/lib/python3/dist-packages/unittest2/case.py", line 883, in assertAlmostEqual
    raise self.failureException(msg)
AssertionError: 1453224313.0 != 1453224312.4944572 within 0.5 delta

Change-Id: Ib2eeb13cd07febcb7c8b4e1435b885c4339093e4
2016-01-29 00:18:28 +01:00
Jude Job
47f673ed9f Error with uploading large object includes unicode path
This patch include a test case to test unicode path.

Change-Id: I7697679f0034ce65b068791d7d5145286d992bd1
Closes-Bug: #1532096
2016-01-18 12:56:27 +05:30
Ondřej Nový
21a841a003 Fixed few misspellings in comments
Change-Id: I29d891e2dc900eb93e703f77f4e56f68710a8955
2016-01-05 20:28:47 +01:00
Tim Burke
62bfe10f58 Fix some typos
Change-Id: Iaf7f30a7ae0c2ac76fc5cdcee31ea74c08ce601e
2015-12-30 11:01:33 -08:00
Joel Wright
a3a78be87b New API documentation for python-swiftclient
New documentation for python-swiftclient that introduces
the APIs available and gives some opinionated advice about
when to use the shell, the client API and the service API.

Change-Id: I19020f041fab2e72469979f712ffe3951c431d24
2015-11-25 15:15:09 +00:00
Tim Burke
9fed7ed5e1 Miscellaneous (mostly test) cleanup
* Always use testtools.TestCase, since we're relying on testtools
 * Always use mock (as opposed to unittest.mock) since we're relying on
   mock
 * Add note about when a missing logging handler was added
 * Stop %-formatting the giant usage string that doesn't actually need
   any formatting
 * Prefer assertIs, assertIn, assertIsInstance over assertTrue
 * Use else-self.fail instead of sentinel values
 * Check resp.get('error') is None before checking resp['success'] is
   True, so test failures actually tell you something useful
 * Tighten some isinstance assertions
 * Import MockHttpTest from correct location
 * Only populate clean_os_environ once
 * Use setUp for setup, not __init__
 * Replace assertIn(key, dict) and assertEqual(foo, dict[key]) with
   assertEqual(foo, dict.get(key)) when key is a literal and foo is not
   None
 * Use mock.patch.object instead of manually patching for tests
 * Use six.binary_type instead of type(''.encode('utf-8'))
 * Stop shadowing builtin bytes
 * Reclaim some margin
 * Stop checking the return-type of encode_utf8; we already know it's
   bytes

Change-Id: I2138ea553378ce88810b7353147c8645a8f8c90e
2015-10-07 22:33:42 -07:00
Jenkins
93666bb84a Merge "Log and report trace on service operation fails" 2015-09-04 01:46:18 +00:00
Alistair Coles
d5eb818228 Cleanup and improve tests for download
Some improvements to the tests for staggered download
that were added in [1].

[1] Ie737cbb7f8b1fa8a79bbb88914730b05aa7f2906

Change-Id: Ib999bc7bd198c1d9c217c57501f751e854d4c6ad
2015-09-02 13:06:13 +01:00
Joel Wright
3c0289844f Log and report trace on service operation fails
This patch adds exception logging to the swift service API. Each
operation that results in failure of any operation will now log
the exception as well as report a timestamp and full stack trace
in the results returned by the service API calls.

Change-Id: I7336b28354e7740ea7d048bdf355e3c1a1b4436c
2015-08-31 22:03:26 +01:00
Joel Wright
a8c4df98ee Reduce memory usage for download/delete and add --no-shuffle option to st_download
The current code builds a full object listing before performing either a multiple
download or delete operation (and also shuffles this complete list in the case of
a download). This patch removes the creation of the full object list and adds the
ability to turn off shuffle for files when downloading. Also added is a limit on
the number of list results that can be queued by a single call to service.list
without consuming results (reduces memory overhead for large listings).

Some tests added for service.py download and list.

Change-Id: Ie737cbb7f8b1fa8a79bbb88914730b05aa7f2906
2015-07-20 20:44:51 +01:00
Jenkins
0b592caabf Merge "Add ability to download objects to particular folder." 2015-07-11 06:21:40 +00:00
Charles Hsu
d5d3127744 Add ability to download objects to particular folder.
This patch adds "--output-dir" and "--remove-prefix" options
to the "download" command and unit tests for it.

Example:

    $ swift list example --prefix swift2.2
    swift2.2/bin/swift-object-auditor
    swift2.2/bin/swift-object-expirer
    swift2.2/bin/swift-object-info
    swift2.2/bin/swift-object-replicator
    swift2.2/bin/swift-object-server
    swift2.2/bin/swift-object-updater

When given "--output-dir <directory>", client downloads objects to <directory>.

    $ swift download example --prefix swift2.2 \
                    --output-dir new/swift/dir

    The folder structure:
    .
    └── new
        └── swift
            └── dir
                └── swift2.2
                    └── bin
                        ├── swift-object-auditor
                        ├── swift-object-expirer
                        ├── swift-object-info
                        ├── swift-object-replicator
                        ├── swift-object-server
                        └── swift-object-updater

When given "--remove-prefix", client downloads objects without <prefix>.

    $ swift download example --prefix swift2.2 \
                    --remove-prefix \
                    --output-dir swift

    The folder structure:
    .
    └── swift
        └── bin
            ├── swift-object-auditor
            ├── swift-object-expirer
            ├── swift-object-info
            ├── swift-object-replicator
            ├── swift-object-server
            └── swift-object-updater

Co-Authored-By: Clay Gerrard <clay.gerrard@gmail.com>
Change-Id: I7463fe2941cc94f9a50a4756a97c2ccdf946294d
Implements: blueprint swiftclient-download-pseudo-folder-to-specific-target
2015-07-08 14:23:05 +08:00
Jenkins
92b8277752 Merge "SwiftClient object upload beginning with / or "./"" 2015-07-07 22:21:38 +00:00
Pradeep Kumar Singh
794b125e76 SwiftClient object upload beginning with / or "./"
Currently SwiftClient populate response dictionary before
removing "./" or "/" at begining of object name. This patch
fixes that by changing that order.

Closes-bug: #1412425
Change-Id: I80222754caba5d42a468f4677ac539e46682dd31
2015-06-17 12:27:43 +05:30