86 Commits

Author SHA1 Message Date
Tristan Cacqueray
fa20e7f685 Makes use of requests.Session
This allows better connection pooling and may improve performances.

Change-Id: I69e986b7387dd3ac281731b8355a3eec34a537f8
2014-04-16 16:00:17 +00:00
Victor Stinner
155053ea61 Fix swiftclient.client.quote() for Python 3
On Python 3, urllib.parse.quote() accepts bytes and str (unicode) types and
always return str (unicode).

Add also more tests with non-ASCII characters.

Change-Id: I8e0f19da7240e874392327d0da074ed4abb7d213
2014-04-07 10:30:18 +02:00
Jenkins
98e36e9438 Merge "don't use mutable defaults in kwargs" 2014-04-01 15:21:22 +00:00
Jenkins
cda26a32c1 Merge "set user-agent header" 2014-04-01 15:21:20 +00:00
Jenkins
296d3ed4ce Merge "Decode HTTP responses, fixes bug #1282861" 2014-04-01 14:08:34 +00:00
Jenkins
21db1bf836 Merge "Python 3: Get compatible types from six" 2014-03-30 19:48:34 +00:00
John Dickinson
1f0dd002db don't use mutable defaults in kwargs
Change-Id: I3ae71259ccc49a5d8a852388784c3dfd577df50a
2014-03-30 10:29:36 -07:00
John Dickinson
4f3d6e7f3a set user-agent header
Change-Id: Ia67807667b4b5177d83cce9fcf16d98dc5024fbc
2014-03-30 10:29:07 -07:00
Victor Stinner
12f86fdcc5 Python 3: Get compatible types from six
* Replace unicode with six.text_type
* Replace basestring with six.string_types
* The long type doesn't exist in Python 3 anymore: replace 1L with long(1) and
  only test this type with Python 2
* Fix quote(): quote the URL if the string is a byte string. Use "bytes" type
  instead of "str" to be Python 3 compatible.

Change-Id: I1df5aa85e4e7d07191fb5c654d52fc4bd8b9f440
2014-03-28 15:48:50 +00:00
Victor Stinner
e3b7ecd2bb Python 3: Fix module names in import
Use six.moves to fix imports on Python 3.

Change-Id: I35b9405690e9f0607b24d79aa7c00830df954c41
2014-03-28 15:04:14 +00:00
Victor Stinner
701faf0d16 Replace dict.iteritems() with dict.items()
dict.iteritems() has been removed in Python 3. In Python 2, dict.items()
creates a temporary list, but Samuel Merritt wrote:

"The size of the data is small enough that we don't need to worry about the
memory consumption; it's all just HTTP headers."

Change-Id: Iac427b8bbd032e4a1efb2bdc84a3968217eb6ddf
2014-03-27 12:21:25 +01:00
groqez
bffdadee57 Decode HTTP responses, fixes bug #1282861
By default, the HTTPConnection class expose the raw.read urllib3
function which doesn't do any decoding on the http response.
We can fix this by passing decode_content=True to raw.read().

Change-Id: I7d42d31ae516705d1bde2769e642931308116c7a
2014-03-18 19:47:02 +01:00
Jenkins
41f5763b2b Merge "TCP port is appended two time in ClientException" 2014-03-12 02:13:18 +00:00
Fabien Boucher
2e1a5b7e28 TCP port is appended two time in ClientException
urlparse netloc contains the TCP port if presents.
There is no need to provide conn.port when building
CLientException.

Change-Id: Id3e4fa8c4f4ab2ad693b0e8702ab69ed7c291830
2014-03-06 22:04:28 +01:00
Clay Gerrard
3d35a3e989 Add LengthWrapper in put_object to honor content_length param
Closes-Bug:#1284360

Change-Id: Iec63a3fde77bb8195bfe46c764403b367999ff43
2014-02-25 01:12:51 -08:00
Jenkins
f4e057923c Merge "Remove useless statement" 2014-02-19 23:17:10 +00:00
Fabien Boucher
b5b440d9b6 Remove useless statement
Change-Id: Ide74b417ede6a4976c33fc835d366ed472033fd0
2014-02-19 14:09:50 +01:00
Tristan Cacqueray
380e830874 Remove multipart/form-data file upload
The requests 'files' parameter adds this 'Content-Type: multipart/form-data'
HTTP header and the whole multipart body data get stored with the object.
This also create a memory hog issue because files are loaded in memory before
being actually sent. This patch removes this behavior and restores what was
done before, ie: direct uploading.

This patches also fixes an issue in requests, when used with glance
CooperativeReader it mis-calculates content-length leading to chunked encoding
for raw upload.

Change-Id: Ie5b0a1078bedd33f09c6157f48b5f88116c589fa
Closes-Bug: #1280072
Closes-Bug: #1280275
2014-02-14 16:51:20 +01:00
John Dickinson
79f189a593 Fix --insecure option on auth
Change-Id: Ibe76d98d6075b84cbdb370b48f3498ab848142ad
2014-02-13 23:37:08 -08:00
Jenkins
19d7e1812a Merge "Port to python-requests" 2014-02-14 00:41:39 +00:00
Tristan Cacqueray
b182112719 Port to python-requests
Currently, httplib implementation does not support SSL certificate
verification. This patch fixes this. Note that ssl compression parameter
and 100-continue thing is still missing from requests, though those are
lower priority.

Requests now takes care of:
* proxy configuration (get_environ_proxies),
* chunked encoding (with data generator),
* bulk uploading (with files dictionary),
* SSL certificate verification (with 'insecure' and 'cacert' parameter).

This patch have been tested with requests 1.1.0 (CentOS 6) and requests
2.2.1 (current version).

Change-Id: Ib5de962f4102d57c71ad85fd81a615362ef175dc
Closes-Bug: #1199783
DocImpact
SecurityImpact
2014-02-12 13:21:26 +01:00
Sergio Cazzolato
d387c61daa changed things because reasons
Dictionaries added in texts to improve readability in case there
are 2 params

Change-Id: I064cceeaa56b232504c6f0b6c215c9c5dbb7fcef
2014-02-06 17:31:32 -08:00
Jenkins
feb514a207 Merge "Add capabilities option" 2014-01-31 08:55:27 +00:00
Fabien Boucher
533c9c5ba1 Add capabilities option
This patch adds a capabilities option on swiftclient.
This option uses the new /info endpoint to request the
remote capabilities and nicely display it.

Change-Id: Ie34b454511d5527e402e66e1fdb72120f427f2fd
2014-01-17 10:26:34 +01:00
John Dickinson
5187fd313f retry on ratelimit
Added a retry_on_ratelimit parameter to the Connection
class so that ratelimited requests can be retried.

DocImpact

Change-Id: I2817a7ea0ed2d69a7659e80111fbd2c91a75d530
2013-12-23 13:53:18 -08:00
Jenkins
0ae2b58f2d Merge "Enable usage of proxies defined in environment (http(s)_proxy)." 2013-12-14 09:37:38 +00:00
Jenkins
38ae02928d Merge "Fixes python-swiftclient debugging message" 2013-12-12 08:48:58 +00:00
Davide Guerri
716b4e722c Enable usage of proxies defined in environment (http(s)_proxy).
As far as proxies usage is concerned, keystone-client API and swift-client API behave differently because the former uses python Request library while the latter uses raw httplib. As a result, Keystone authentication honors environment variables http_proxy, https_proxy and no_proxy while Swift doesn't.

This patch, which code is mainly borrowed from Python Requests, makes Swift
data connections and Swift authentication connections behaving homogeneously.

Change-Id: Ic8a0089c35c458d7ed96e572e22429014298fe4c
2013-12-10 12:12:28 +00:00
Jenkins
1f3ab4b41a Merge "Skip sniffing and reseting if retry is disabled" 2013-12-10 00:19:00 +00:00
Jenkins
b0f794800c Merge "Don't crash when header is value of None" 2013-12-07 10:12:08 +00:00
Chmouel Boudjnah
983988093f Don't crash when header is value of None
Before commit 7d88d14d (http://git.io/hhJWdQ) swifclient used to accept
header value with the type None :

{'Headers': None}

It would just be happy with it with those None headers and not process
them, reinstate the old behavior.

Closes-Bug: 1256441
Change-Id: Ic7f80c38ef2ce9ef1687ed0d6d65521f2e754905
2013-12-06 13:28:01 +01:00
Jenkins
e100fd28ab Merge "Fix download bandwidth for swift command." 2013-12-03 01:30:48 +00:00
Jenkins
dbc6686b5e Merge "Add close to swiftclient.client.Connection" 2013-11-29 22:01:24 +00:00
jola-mirecka
9b7e24c449 Fix download bandwidth for swift command.
We noticed a difference in download bandwidth while using
authentication details and pre-auth information for download.
Download using authentication details included authentication
time into the download bandwidth at each call of the function.
This time should have been excluded from download bandwidth.

This patch set is adding a timer variable to the client library.
That allows to accurately measure and store the time of each action.
Then while printing the download bandwith in the swift command
authentication time is excluded from bandwidth.

Change-Id: I63df9023e169f637f120ae9e25dac9c90a4e75a0
Fixes: bug #1197443
2013-11-28 13:02:54 -05:00
Alex Gaynor
ff6ba367fa Replaced two references to Cloud Files with Swift
Change-Id: I721f2b25a255a829c625b34928b066df3cd3e632
2013-11-01 11:40:44 -07:00
Feng Liu
9fe79a4aac Add close to swiftclient.client.Connection
Change-Id: I2f5fa9c46886607a9ba99e8915ea84ac4975d004
2013-10-23 11:31:10 +08:00
Leah Klearman
b682935055 enhance swiftclient logging
* log to debug for successes and info for errors
* remove dead code, neither body or raw_body are sent in kwargs
* include resp.reason and response headers in logging
* remove trailing \n in logging. users who want them can set logging.basicConfig(format=FORMAT)
* add --info option to swift cli

Change-Id: If07af46cb377f3f3d70f6c4284037241d360a8b7
2013-10-17 16:05:36 -07:00
Florent Flament
c81a9edd1f Fixes python-swiftclient debugging message
Appends the container's name to the URL displayed, to be used to
replay the queries with curl.

Replaying the curl commands displayed by "swift --debug list
<container>" now works properly.

Example:
$ swift --debug list test-container
...
DEBUG:swiftclient:REQ: curl -i http://10.0.48.134:8080/v1/AUTH_6c554b8dd3d74e44878eddb92caf8687/test-container?format=json -X GET -H ...
...

Change-Id: I7ec33d185fedc44a529c016d38f841fde39d20d0
Closes-Bug: #1238612
2013-10-11 14:06:35 +02:00
Yuan Zhou
dbdbaa0321 Skip sniffing and reseting if retry is disabled
Bypass sniffing entirely if retries has been disabled.

Fix bug #1216981

Change-Id: I593bdc56ca139af5a7f2ca2783ef2de2a96c94fb
Signed-off-by: Yuan Zhou <yuan.zhou@intel.com>
2013-09-29 21:37:07 +08:00
Clay Gerrard
ec14619ef0 Add a NullHandler when setting up library logging
I was gunna write a test, but mocking ImportErrors is a PITA, so I decided to
just get my tox py26 working instead.  Tests seem to fail/pass as expected
without/with the inline NullHanlder.

Closes-Bug: 1212861

Change-Id: I20207374a77ee9969ab201c3a57e4caf40c02a61
2013-08-17 00:27:24 -07:00
Jenkins
c626c2a87e Merge "Added headers argument support to get_object()" 2013-08-02 19:23:23 +00:00
Stanislav Vitkovskiy
d34f126148 Added headers argument support to get_object()
With this change conditional and range GETs are possible, as
documented in official API guide:
http://docs.openstack.org/api/openstack-object-storage/1.0/content/retrieve-object.html

Change-Id: Ib2ed1c21e8d3f1ed79c0b7e542ee022ee535835c
2013-07-29 22:53:13 +10:00
Darrell Bishop
9198e95468 Move multi-threading code to a library.
This patch extracts the multi-threading code from bin/swift into
swiftclient/multithreading and adds tests.  In particular, this new way
of doing it (with context managers) will prevent non-daemonic threads
from wedging the process when unexpected exceptions happen.

I enabled reporting of which lines, specifically, are not covered by
unit tests (added -m option to "coverage report" in .unittests).

This patch includes a drive-by fix for uploading a segmented file with
--use-slo when that object already exists.  A key of "name" was used
instead of "path", raising KeyError.

There's also another drive-by fix for uploading segmented objects with
--use-slo.  Commit 874e0e4427b80e1b15b74a1557b73ba9d61443ca regressed
this by removing the capturing of thread-worker results in
QueueFunctionThread.run().  This patch restores that functionality and
the feature (uploading SLO objects).

Change-Id: I0b4f677e4a734e83d1a25088d9a74f7d46384e53
2013-07-28 22:08:17 -07:00
Jenkins
8ffaa0a4ce Merge "Refuse carriage return in header value" 2013-07-23 00:09:47 +00:00
Hemanth Makkapati
2f84a4e76b Added log statements in swift client
Added log statements in swiftclient/client.py:_retry where exceptions
are being raised.

Fixes bug# 1202229

Change-Id: I727537177849d08bb9603aa884152bdebc62fb85
2013-07-17 15:11:15 +00:00
Samuel Merritt
07d13b5262 Update docstring for swiftclient.Connection.__init__
There were two undocumented parameters in there, one introduced
recently in 6411fd3, and the other some time before.

Change-Id: I3a7d59e1c272b382b035b88ba5495bc1c57a3154
2013-07-12 17:26:45 -07:00
Kun Huang
7d88d14def Refuse carriage return in header value
See bug #1188896.
Comparing with Curl and Django, they both refuse carriage returns in
header values, so the request() method on the HTTP(S)Connection instance
returned by swiftclient.client.http_connection() will raise an
InvalidHeadersException if any of the headers to be sent contain a
newline.

Drive-by fix for a couple of header values which were integers instead
of strings (Content-Length getting set to zero).

Fixes bug #1188896

Change-Id: Ic6afdb92882284f843aacb06d20f682ddcb47151
2013-07-12 15:18:49 -07:00
Mike Widman
6411fd3846 Adds max-backoff for retries in Connection.
The max-backoff concept prevents the backoff used in _retry to double infinitely (which in turn causes wait times of an hour or more between retries).

As per review, changed code to use min instead.

Fixes: bug #1183542

Change-Id: Ic084f54069b7fa7a33604741487045c5e697ff06
2013-07-12 14:53:30 -07:00
Darrell Bishop
1d4d51b218 Allow storage url override for both auth vers.
When --os-storage-url is specified on the command-line to bin/swift, it
will override the used storage URL regardless of authentication for both
authentication version 1 and version 2.  This can be used to bypass a
load-balancer to hit a specific proxy server for testing/debugging
purposes.

Within the client library, this feature is accessed by passing the
desired storage URL into swiftclient.client.Conection.__init__() via the
os_options keyword argument.  For example:

  conn = Connection(auth_url, user, key, os_options={
    'object_storage_url': 'http://overridden.storage.url/AUTH_foo'})

This patch also adds a dependency on mock>=0.8.0, which is the same as
openstack/swift.

Change-Id: Id2a36ed6abffd65e7762b6beea5bbfc6c036e848
2013-07-05 14:12:59 -05:00
Mark Seger
3f66a8ae6b add optional 'response_dict' parameters to many calls into which they'll
return a dictionary of the response status, reason and headers

Change-Id: I35f8824537f0484362dd6646c91789fac02fa075
2013-06-20 11:51:08 +00:00