588 Commits

Author SHA1 Message Date
Tim Burke
fd5579a154 Check responses when retrying bodies
Previously, if a Range request came back 200 OK (rather than 206 Partial
Content), we would mangle the response body. This could happen if there
was a middleware that would silently drop Range headers, for example.

Now, if the response does not include a Content-Range header, we will
log a warning and seek to our previous position in the stream. If the
Content-Range header has an unexpected value, we will raise an exception.

Change-Id: I94d4536cc1489968d45a2b6ba7edd70c85800275
2016-05-04 15:21:26 -07: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
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
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
hgangwx
ab65eef4ce Wrong usage of "an"
Wrong usage of "an" in the messages:
"the optional os_options paramater includes an non-empty"
"We are allowing to have an tenant_name argument"

Should be:
"the optional os_options paramater includes a non-empty"
"We are allowing to have a tenant_name argument"

Totally 2 occurrences in python-swiftclient base code.

Change-Id: I2f2f7e07432fedfee5ccb418d9505250b3fed597
2015-12-30 14:27:29 +08:00
Jenkins
5e13c3e845 Merge "Stop passing attr to keystoneclient when there's no filter_value" 2015-12-22 11:15:27 +00:00
Jenkins
3f1c304e3b Merge "Test 'string' behaviour of get_object" 2015-12-16 00:49:09 +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
Jenkins
b558f0b143 Merge "Deprecated tox -downloadcache option removed" 2015-12-15 09:13:09 +00:00
Jenkins
6cdf470e18 Merge "Delete python bytecode before every test run" 2015-12-15 03:25:23 +00:00
shu-mutou
6bb97044c2 Delete python bytecode before every test run
Because python creates pyc|pyo files and __pycache__
directories during tox runs, certain changes in the tree,
like deletes of files, or switching branches, can create
spurious errors.

Change-Id: Ibaac514521bab11bbf552e0310d1203230c0d984
Closes-Bug: #1368661
2015-12-14 13:59:22 +09:00
Ondřej Nový
7c78c7bc2e Deprecated tox -downloadcache option removed
Caching is enabled by default from pip version 6.0

More info:
https://testrun.org/tox/latest/config.html#confval-downloadcache=path
https://pip.pypa.io/en/stable/reference/pip_install/#caching

Change-Id: I95015c79049633ed97714d6de8dd8f231bd15a03
2015-12-11 21:26:38 +01:00
Jenkins
4d9b1e760d Merge "Remove py26 support" 2015-12-10 20:29:16 +00:00
Jenkins
423ede01c4 Merge "New API documentation for python-swiftclient" 2015-12-10 20:28:52 +00:00
John Dickinson
bf07a69e0e fix release version
Change-Id: I0237adbcbd6249bab12ab1624b78b537511fc971
2.7.0
2015-12-07 14:55:30 -08: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
John Dickinson
2d6e96d2f9 authors and changelog update for 2.6.1 release
Change-Id: Icefe2f62c2d2d41c5ee9764c51b0ae4ce1d9b3f3
2015-12-03 15:45:39 -08:00
ricolin
cffdc9d357 Remove py26 support
As of mitaka, the infra team won't have the resources available to
reasonably test py26, also the oslo team is dropping py26 support
from their libraries. sine we rely on oslo for a lot of our work,
and depend on infra for our CI, we should drop py26 support too.
Closes-Bug: 1519510
Depends-On: I37116731db11449d0c374a6a83a3a43789a19d5f

Change-Id: I776847ce77dfe82880f34d0b7804514e5aed3f8d
2015-12-02 15:09:44 +00:00
Jenkins
a564eb0e4c Merge "Unification of manpages and docstrings" 2015-12-01 13:03:05 +00:00
Jenkins
20731f4687 Merge "improve readme contents" 2015-12-01 02:13:17 +00:00
Jenkins
e675e1e938 Merge "Suppress iso8601 logging from --debug output" 2015-12-01 00:31:54 +00: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
Alistair Coles
562f386e93 Update mailmap
Change-Id: I0531928b531694008520298bea7d37b73216787e
2015-11-24 16:31:44 +00:00
Jenkins
2b42fefdbf Merge "Add py35 to default tox environments" 2015-11-23 18:46:45 +00:00
ricolin
7f304337a0 improve readme contents
Add more information in README.rst

Change-Id: I9fb9bea648fb1d1e26b0db4b590f72ffc85b7a33
2015-11-19 16:26:14 +08:00
Peter Lisák
3b1f4fda72 Unification of manpages and docstrings
* adding missing options
* unification of help

Change-Id: I2365e66433b63de8fd4da205611d9c1bf3bb6730
2015-11-13 17:32:12 +01: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
Jenkins
1c649cc0d8 Merge "enable autodocumentation for utils module; docstring fixes" 2015-10-29 06:09:46 +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
Tim Burke
1b0567b6c7 Add py35 to default tox environments
Change-Id: Ib10eab87b791da561b82c9522ba2686d24966c2d
2015-10-01 12:31:12 -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
Jenkins
c90547b5d4 Merge "Add headers parameter" 2015-09-22 11:43:28 +00:00
Monty Taylor
ccc3aa49ee Change ignore-errors to ignore_errors
Needed for coverage 4.0

Change-Id: I2789541f67d6adbdc8454183753832488fe2bbe2
2015-09-21 14:54:40 +00: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
Qiu Yu
f65641c44d Suppress iso8601 logging from --debug output
This change silences logging from iso8601 when --debug option set

Change-Id: Ib8b8423012d43ef78d7138609fa98f40d46e7d4b
Closes-bug: #1324470
2015-09-12 03:10:15 +08:00
Zack M. Davis
6b3638ecec enable autodocumentation for utils module; docstring fixes
This commit adds the utils module to those for which Sphinx
automatically generates documentation from docstrings. (Many of the
functions here may be of little interest to users, but
`generate_temp_url`, at least, definitely deserves to be in the
documentation; in this way, this commit can be seen as a spiritual
companion to ca70dd9e.)

Also, a few markup errors and perceived infelicities in existing
docstrings are amended.

Change-Id: I8c66a23cb359d7dd9302a16459fad9825fedb690
2015-09-10 15:19:26 -07:00
Jenkins
26d29f5ce0 Merge "make ClientException.http_status default to None rather than 0" 2015-09-10 21:47:43 +00:00