363 Commits

Author SHA1 Message Date
Jenkins
6d52264c30 Merge "Error with uploading large object includes unicode path" 2016-01-28 00:22:35 +00:00
Jenkins
e65e01014e Merge "Convert http response(byte string) to string in python3." 2016-01-22 13:16:44 +00:00
Jenkins
88874ae441 Merge "Use bulk-delete middleware when available" 2016-01-22 05:49:31 +00:00
Tim Burke
38f9664167 Prevent test runs from cluttering current directory
Previously, the following empty directories would be created:
  * container
  * container/pseudo
  * pseudo

Change-Id: I002e2da8d28a873728e0b5c2d33f94f21132d058
2016-01-19 14:26:13 -08:00
Tim Burke
dcdd715215 Get rid of FakeConn cruft
Presumably, this was left over from before the httplib -> requests
transition?

Change-Id: I7f505514070bf9d8fefda77203bee78f0a5dd71d
2016-01-18 21:14:53 -08:00
Pratik Mallya
a175689418 Accept token and tenant_id for authenticating against KS
Allow swiftclient to authenticate against keystone using tenant
name/id and token only. Without this patch, the password is
required, which may not always be available. Authentication
against keystone is required to get the service catalog,
which includes the endpoints for swift.

Change-Id: I4477af445474c5fa97ff864c4942f1330b59e5d6
Closes-Bug: #1476002
2016-01-18 10:47:05 -08: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
Tim Burke
7a1e192803 Use bulk-delete middleware when available
When issuing `delete` commands that would require three or more
individual deletes, check whether the cluster supports bulk deletes
and use that if it's available.

Additionally, a new option is added to the `delete` command:

  * --prefix <prefix>

    Delete all objects that start with <prefix>. This is similar to the
    --prefix option for the `list` command.

Example:

$ swift delete c --prefix obj_prefix/

    ...will delete from container "c" all objects whose name begins with
    "obj_prefix/", such as "obj_prefix/foo" and "obj_prefix/bar".

Change-Id: I6b9504848d6ef562cf4f570bbcd17db4e3da8264
2016-01-12 15:40:57 -08:00
Jenkins
6ed6c3343f Merge "Retry file uploads via SwiftService" 2016-01-12 13:00:17 +00:00
Jenkins
c9ce80c460 Merge "Fix upload to pseudo-dir passed by <container> arg" 2016-01-11 23:58:41 +00:00
Tim Burke
5050027610 _RetryBody doesn't need to take explicit etag/content-length
Also, don't try to do int(None) for chunk-encoded responses (like DLOs
that are longer than a single container listing).

Change-Id: Ibacd75d5ee46135d62388786903c895fda8ed3ba
2016-01-11 15:36:37 -08:00
Tim Burke
d4157ce5b5 Retry file uploads via SwiftService
When we introduced LengthWrapper, we neglected to make it resettable. As
a result, upload failures result in errors like:

    put_object(...) failure and no ability to reset contents for reupload.

Now, LengthWrappers will be resettable if their _readable has seek/tell.

Related-Change: I6c8bc1366dfb591a26d934a30cd21c9e6b9a04ce
Change-Id: I21f43f06e8c78b24d1fc081efedf2687942e042f
2016-01-11 11:12:13 -08:00
Stuart McLaren
4af623bcf1 Retry download of object body
Currently the swift client retries establishing a connection to the server
(by default up to 5 times).  However, when downloading an object, once
the connection has been established and the inital headers have been
returned, no attempt is made to retry.

So, for example, if 99MB of a 100MB object have been downloaded and the
connection is then lost, the download will fail.  This patch changes the
behaviour to re-establish the connection and fetch the remaining bytes
using the 'Range' header to offset.

Data retry is not yet supported if the original request is for a subset
of the object data (ie uses the 'Range' header), or if resp_chunk_size
has not been set.

The object's etag is checked using If-Match to make sure the object data
hasn't changed since the start of the download.

Change-Id: Iab47f10081ff39f6d344dbc2479cbc3bfd1c5b29
2016-01-08 17:12:02 +00:00
Jenkins
d1e3109588 Merge "Replace assertEqual(arg, None) with assertIsNone(arg)" 2016-01-06 09:19:43 +00:00
Jenkins
633a491538 Merge "Add functional test for object PUT with raw iterator" 2016-01-06 04:01:02 +00:00
Jenkins
39676743bb Merge "Fixed few misspellings in comments" 2016-01-06 03:03:56 +00:00
Jenkins
81003b8d99 Merge "Wrap raw iterators to ensure we send entire contents to server" 2016-01-06 00:06:04 +00:00
Ondřej Nový
21a841a003 Fixed few misspellings in comments
Change-Id: I29d891e2dc900eb93e703f77f4e56f68710a8955
2016-01-05 20:28:47 +01:00
Alistair Coles
ab34609050 Add functional test for object PUT with raw iterator
Adds a functional test to verify change made in [1]

[1] change id I19579ed7a0181ac3f488433e7c1839f7f7a040b8

Change-Id: I45dbf66edab645e6339e67906aee5faa4fb7efbd
2016-01-05 18:25:19 +00:00
James Nzomo
2c6f367035 Fix upload to pseudo-dir passed by <container> arg
This fix makes it possible to upload objects to pseudo-folders by
passing the upload paths via <container> arg regardless of whether the
container or folder path exist or not.

Change-Id: I575e58aa12adcf71cdaa70d025a0ea5c63f46903
Closes-Bug: #1478210
Partial-Bug: #1432734
Related-Bug: #1432734
2016-01-04 22:48:07 +03:00
Christian Schwede
109e8f519f Fix debug and info option parsing
The debug and info options need to be set before a subcommand method is called,
otherwise they are simply ignored. This is kind of irritating - other options
(for example -U, -A, -K) are usable after a positional command.

This patch fixes this, and commands like these are no longer ignoring --debug or --info:

 swift stat --debug
 swift list container --info

Co-Authored-By: Alistair Coles <alistair.coles@hpe.com>

Change-Id: Ib19b05deef7a015881f1eed4a3946025e16bf922
2015-12-30 14:22:01 -08:00
Tim Burke
39b1a31d8a Wrap raw iterators to ensure we send entire contents to server
Currently, if you attempt to stream an upload from an iterator, as in

    def data():
        yield 'foo'
        yield ''
        yield 'bar'
    conn.put_object('c', 'o', data())

... requests will faithfully emit a zero-length chunk, ending the
transfer. Swift will then close the connection, possibly (if Connection:
keep-alive was set) after attempting to parse the next chunk as a new
request.

Now, Swift will receive all of the bytes from the iterable, and any
zero-byte chunks will be ignored.

This will be fixed in requests [1], but not until an eventual 3.0.0
release.

[1] https://github.com/kennethreitz/requests/pull/2631

Change-Id: I19579ed7a0181ac3f488433e7c1839f7f7a040b8
2015-12-30 11:56:36 -08:00
Tim Burke
62bfe10f58 Fix some typos
Change-Id: Iaf7f30a7ae0c2ac76fc5cdcee31ea74c08ce601e
2015-12-30 11:01:33 -08:00
SaiKiran
6da38adb8d Replace assertEqual(arg, None) with assertIsNone(arg)
In python-swiftclient some test cases using asserEqual(arg, None)
instead of assertIsNone(arg).assertIsNone method provides clear error message.

Change-Id: I4d673ede0965408344325c9c234c5c4b1ae4146a
Closes-Bug: #1527556
2015-12-30 17:25:30 +05:30
Jenkins
5e13c3e845 Merge "Stop passing attr to keystoneclient when there's no filter_value" 2015-12-22 11:15:27 +00:00
Stuart McLaren
0103465fcb Test 'string' behaviour of get_object
Add a unit test to test the 'string' like behaviour of
get_object when it is called without resp_chunk_size set.

Co-Authored-By: Clay Gerrard <clay.gerrard@gmail.com>
Change-Id: I496032a76036141d027c30b076c810b34bc6bef0
2015-12-15 17:15:27 +00:00
Tim Burke
2345ae54f1 Stop passing attr to keystoneclient when there's no filter_value
It was dropping warnings like "UserWarning: Providing attr without
filter_value to get_urls() is deprecated as of the 1.7.0 release and may
be removed in the 2.0.0 release. Either both should be provided or
neither should be provided."

Change-Id: Iead0bcf36b4a46bf465a55a33a21fd7f14f0ac40
2015-12-07 10:42:15 -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
Jenkins
50978ddf63 Merge "Centralize header parsing" 2015-11-12 02:53:20 +00:00
Peter Lisák
3e1a457db0 Add content-type in list of container content
Change-Id: Ie0787d5ffbee0a7d2429cb285fa6ecdf722e4ae1
2015-11-11 12:21:40 +01:00
Jenkins
ad5656020c Merge "Add tests and param definitions for headers parameter" 2015-11-04 01:11:37 +00:00
Lisak, Peter
df1f4f3e39 swiftclient content-type header
According to help `swift upload -h` you can add a customized request header 'Content-Type'.
But actually it is ignored (cleared and default is used) if subcommand is upload.

Subcommand post works as expected in help.

Bug fix: Use 'Content-Type' from the customized request headers also if
uploading.

Change-Id: If0d1354b6214b909527341078fe1769aa6587457
2015-10-22 08:54:13 +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
Alistair Coles
328d6a8d45 Add tests and param definitions for headers parameter
Cleanups for change I35c3b266b3c733f6b1629de4c683ea7d40128032

Add missing param definitions to client get_container
and head_object docstrings.

For consistency, add headers parameter to the Connection class
head_object and head_container wrapper methods.

Add tests to verify that the headers parameter of Connection
get_container, head_container and head_object methods is passed to the
module functions.

Change-Id: Ib40d5b626b2793840727c58cffbf725bea55651f
2015-09-23 12:21:45 +01:00
Alistair Coles
43b2c6bfe5 Make more assertions in client unit tests
Some tests rely on the fake connection checking expected request
parameters, but that assumes that the fake ocnnection is even called,
which is not being checked. Add more explicit assertions that requests
are in fact made.

Change-Id: Id1c48235d7d97fd1b0feec6c19ed59a87bebdf89
2015-09-23 09:55:10 +01:00
Tim Burke
305cd6253f Actually make assertions when testing get_account and get_container
Change-Id: Ibb1301b00d1bc99ec089ead02f944aa94972120a
2015-09-22 12:14:18 -07:00
Mahati
7cb99d3157 Add headers parameter
Headers parameter is required when passing client key for encryption.
It is missing for get_container and head_object.

Change-Id: I35c3b266b3c733f6b1629de4c683ea7d40128032
2015-09-16 21:55:56 +05:30
Alistair Coles
1841bd6010 Initialise delete_object mock before it is called
Attempt to fix the linked bug by initialising the mock instance for
Connection.delete_object before calling the SwiftService upload
method, so that the delete_object mock already exists before the
delete_segments jobs that run in multiple threads call it.  Otherwise
there is a risk that the delete_segment job threads could race while
creating either the delete_object mock or the
delete_object.return_value mock, resulting in each thread getting a
different instance. That would explain the intermittent test failures
reported in the bug.

Change-Id: Ia82697c093529076b0bbcc6bccd577afdf0839e1
Partial-Bug: #1480223
2015-09-08 10:22:32 +01:00
Charles Hsu
ee8c1bab98 Convert http response(byte string) to string in python3.
Avoid a TypeError exception in python3.

Change-Id: I4039e3f2a88b5f681288b5ca8dd5c63c13b7764f
Closes-bug: #1457012
2015-09-06 00:24:30 +08:00
Zack M. Davis
52d39bebc1 absolute expiry option for tempURL generation
The `tempurl` subcommand's second positional argument is called
`seconds` and has heretofore interpreted as the number of seconds for
which the tempURL should be valid, counting from the moment of running
the command. This is indeed a common, if not the most common,
use-case. But some users, occasionally, might want to generate a tempURL
that expires at some particular ("absolute") time, rather than a
particular amount of time relative to the moment of happening to run the
command. (One might make an analogy to the way in which Swift's expiring
object support supports an `X-Delete-At` header in addition to
`X-Delete-After`—and it's the former that must be regarded as
ontologically prior.) Thus, this commit adds an `--absolute` optional
argument to the `tempurl` subcommand; if present, the `seconds` argument
will be interpreted as a Unix timestamp of when the tempURL should be
expire, rather than a duration for which the tempURL should be valid
starting from "now".

Change-Id: If9ded96f2799800958d5063127f3de812f50ef06
2015-09-04 14:57:30 -07:00
Jenkins
93666bb84a Merge "Log and report trace on service operation fails" 2015-09-04 01:46:18 +00:00
Tim Burke
ce569f4651 Centralize header parsing
All response headers are now exposed as unicode objects. Any
url-encoding is interpretted as UTF-8; if that causes decoding to fail,
the url-encoded form is returned.

As a result, deleting DLOs with unicode characters will no longer raise
UnicodeEncodeErrors under Python 2.

Related-Bug: #1431866
Change-Id: Idb111c5bf3ac1f5ccfa724b3f4ede8f37d5bfac4
2015-09-03 13:46:03 -07:00
Jenkins
996f672955 Merge "Cleanup and improve tests for download" 2015-09-03 07:43:56 +00:00
Jenkins
e0ce24dd43 Merge "Stop Connection class modifying os_options parameter" 2015-09-03 01:18:10 +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
Jenkins
e52df5d8a5 Merge "Reduce memory usage for download/delete and add --no-shuffle option to st_download" 2015-08-28 00:48:52 +00:00
Alistair Coles
4b310083df Stop Connection class modifying os_options parameter
When a caller passes an os_options dict to the Connection class
constructor, the constructor may modify the os_options dict,
which can surprise the caller if they re-use the os_options
dict. Specifically the os_options tenant_name and object_storage_url
may be modified, and the changed values would then leak through to a
subsequent Connection constructed using the same os_options dict.

This fix simply constructs a new dict from the supplied os_options.
The patch also adds a test that covers this and also verifies that
a preauth_url passed as a keyword arg to Connection() will take
precedence over any object_storage_url in an os_options parameter.

Closes-Bug: 1488070
Change-Id: Ic6b5cf3ac68c505de155619f2610be9529e15432
2015-08-25 09:47:09 +01:00
Jenkins
b4b9254bc3 Merge "Add minimal working service token support." 2015-08-25 02:02:51 +00:00
Stuart McLaren
1789c2654d Add minimal working service token support.
Add client changes to allow accessing alternative
reseller_prefixes via a service token.

ie client changes for this server side spec:
 https://review.openstack.org/#/c/105228

We assume that the service storage url has been passed in
as a preauthurl.

We rely on get_auth preserving this url.

Change-Id: I1cfda178f0b6c8add46cfebd6bf38440caae2036
2015-08-24 10:54:15 +01:00