92 Commits

Author SHA1 Message Date
Zhi Yan Liu
867e4cae27 Normalize glanceclient requested service url
Some proxy or gateway softwares, e.g. jumpgate [0], use url-pattern
based approach to match which hanlding logic needs to be triggered for
particular service calling when it received a http(s) call as a
middleman. The change fixed an issue which caused glanceclient send out
the request to a dis-normal url, which contains duplicated "/".

The change removed a wrong and duplicated code snippet from curl logging
function as well.

[0] http://goo.gl/yt52X1

Change-Id: Ic8b3920e11d400771ead7f9c44b615f10b4a5cef
Signed-off-by: Zhi Yan Liu <zhiyanl@cn.ibm.com>
2014-08-07 13:04:25 +08:00
Matt Riedemann
68c1d1fbc6 Don't stream non-binary requests
Setting stream=True with requests can lead to issues
with not closing the connection so the urllib3 connection
pool is not freed up, so only set stream=True if making
a request with application/octet-stream content-type.

See the body-content-workflow and keep-alive sections
in the requests docs here for more information:

http://docs.python-requests.org/en/latest/user/advanced/

Note that commit dbb242b changed the response body_iter
code to potentially return a six.StringIO object rather
than the old ResponseBodyIterator class and since the
images client code is not converting the body_iter into
a dict using json.loads, we have to do that directly
in the _request method where the body_iter is
constructed.

Co-authored-by: Flavio Percoco <fpercoco@redhat.com>

Change-Id: I86572b69c4511f933c9676108190271874346302
Partial-Bug: #1341777
2014-07-16 02:14:07 -07:00
AmalaBasha
dbb242b776 Replace old httpclient with requests
This review implements blueprint python-request and replaces the old
http client implementation in favor of a new one based on
python-requests.

Major changes:
* raw_request and json_request removed since everything is now being
  handled by the same method "_request"
* New methods that match HTTP's methods were added:
    - get
    - put
    - post
    - head
    - patch
    - delete
* Content-Type is now being "inferred" based on the data being sent:
    - if it is file-like object it chunks the request
    - if it is a python type not instance of basestring then it'll try
      to serialize it to json
    - Every other case will keep the incoming content-type and will send
      the data as is.
* Glanceclient's HTTPSConnection implementation will be used if
  no-compression flag is set to True.

Co-Author:  Flavio Percoco<flaper87@gmail.com>
Change-Id: I09f70eee3e2777f52ce040296015d41649c2586a
2014-07-10 13:22:05 +05:30
Jenkins
d613adc434 Merge "Add profiling support to glanceclinet" 2014-07-08 20:53:00 +00:00
Boris Pavlovic
e305dad557 Add profiling support to glanceclinet
To be able to create profiling traces for Glance, client should be
able to send special HTTP header that contains trace info.
This patch is as well important to be able to make cross project
traces. (Typical case nova calls glance via python client, if
profiler is initialized in nova, glance client will add extra
header, that will be parsed by special osprofiler middleware in glance
api)
Don't worry no security issue here, trace information is signed by HMAC
key that is setted in api-paste.ini. So only person that knows HMAC key
is able to send proper header.

Change-Id: Ib13084fbe9b33c2f3dee165f7d6c778546cce6ca
2014-07-06 12:53:47 +04:00
Jenkins
195384223f Merge "Fix CA certificate handling" 2014-06-30 08:52:31 +00:00
Stuart McLaren
6626f38cda Fix CA certificate handling
If --os-cacert was passed to the cli the following error was
triggered: "cafile must be None or a byte string". This is
because 'load_verify_locations' requires a byte string to
be passed in.

We fix this by explicitly converting the argument to a byte
string.

We do this in 'VerifiedHTTPSConnection' rather than sooner, eg
during arg handling, as it will no longer be required should we
move to a different http library (eg requests).

Fixes bug 1301849.

Change-Id: I9014f5d040cae9f0b6f03d8f13de8419597560cb
2014-06-25 13:45:46 +00:00
Jenkins
e6579f43cc Merge "Reuse class Manager from common code" 2014-06-18 19:46:02 +00:00
Michael Still
dec9c9f352 Change a debug line to prevent UnicodeDecodeError issue
This debug line is causing tracebacks in the n-cpu logs for
tempest runs. Its because the logged data is sometimes unicode:

Traceback (most recent call last):
  File "/usr/lib/python2.7/logging/__init__.py", line 846, in emit
    msg = self.format(record)
  File "/opt/stack/new/nova/nova/openstack/common/log.py", line 710, in format
    return logging.StreamHandler.format(self, record)
  File "/usr/lib/python2.7/logging/__init__.py", line 723, in format
    return fmt.format(record)
  File "/opt/stack/new/nova/nova/openstack/common/log.py", line 674, in format
    return logging.Formatter.format(self, record)
  File "/usr/lib/python2.7/logging/__init__.py", line 467, in format
    s = self._fmt % record.__dict__
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1234: ordinal not in range(128)
Logged from file http.py, line 153

The change used correct encoding error handling policy for the log
which may includes non-ascii char.

Closes-bug: 1320655
Change-Id: I97f5f14b9beddcceb7fbd371062caf5a38a62a20
2014-06-18 23:01:25 +08:00
Andrey Kurilin
d54faad042 Reuse class Manager from common code
Class `Managers` from `glanceclient.common.base` module is similar to
class `apiclient:ManagerWithFind` from common code.

In this patch:
- class glanceclient.common.base:Managers replaced by
apiclient:ManagerWithFind
- module glanceclient.common.base marked as 'deprecated'

Related to bp common-client-library-2

Change-Id: I41da4a9188e97ca2c07b6234fc2ac0a877553d3f
2014-06-12 14:42:46 +03:00
Jenkins
08aaa468d1 Merge "Remove auth token from http logging" 2014-06-04 18:36:51 +00:00
Jenkins
803eed6083 Merge "Finalize Python3 support" 2014-05-28 16:57:34 +00:00
Tom Leaman
6149e1db31 Remove auth token from http logging
This redacts the X-Auth-Token header value from the logs by replacing
it with '***'.

Change-Id: I6b80cc94d42a44f9db801de78fa23218e6eca0ee
2014-05-27 15:09:06 +00:00
Frederic Lepied
628c541a69 Finalize Python3 support
Set the environment variable PYTHONHASHSEED to 0 to have
predictive tests under Python 3.

Change-Id: Ia15a9383e0f20bd0e4572e9f9b9772f1704dff86
2014-05-20 16:42:10 +02:00
Christian Berendt
afcf3a5611 fixed typos found by RETF rules
rules are avaialble at https://en.wikipedia.org/wiki/Wikipedia:AutoWikiBrowser/Typos

Change-Id: I70245e5ddf342762eb76d8e2e74b6363767726ef
2014-05-05 10:55:02 +02:00
Davanum Srinivas
078819cf9e Fix for invalid literal ValueError parsing ipv6 url(s)
Switch to using network_utils for splitting the URL. The code
in oslo-incubator supports ipv6 urls

Change-Id: I76be6173b97eb000319d30b4e9232a5a7c4a5aba
Closes-Bug: #1298137
2014-04-02 21:38:20 -04:00
Edward Hope-Morley
4a41358cea Add support for image size in v2 api upload
Some backend stores e.g. RBD, will fail if told to create an
image without a valid size (RBD will fail to write to a zero-size
image). Here we add support to allow the image size to be provided
when doing an upload. The result is that the upload content-length
will be set if available either from checking the supplied file
object or as provided by user.

Closes-Bug: 1220197
Change-Id: Ia1f2ea5680a139750d931591949b3e0058148b4b
2014-02-03 11:10:50 +00:00
Jenkins
f9c7e3d1cd Merge "server 500 should not be a client error" 2014-01-22 15:59:56 +00:00
Sean Dague
8e146ca500 server 500 should not be a client error
the client should not log a server 50x response at ERROR level.
It already throws an exception, so the caller can care about what
it wants to do with this. This error will show up regularly in
nova that succeed, and there is no way to disable this message,
which isn't an error from Nova's perspective without turning off
*all* the logs.

Set this to debug instead, because from a caller perspective that's
what you want out of this.

Change-Id: I6d0efb53d1e81adf309f7fa580ec5a8073a811c5
2014-01-19 20:02:42 -05:00
Victor Morales
29674c3f48 It was removed urllib, urllib2 & urlparse modules
Those modules have been combined in python 3. Therefore,
implementing the six module helps to have support to both versions.

Change-Id: I164a0f19790ff066d16d0cf4f0daa6f1097c848e
Closes-Bug: #1267181
2014-01-18 22:17:57 -06:00
Yassine Lamgarchal
02b00b6226 Python 3: use six.iteritems and six.string_types
six.iteritems() replaces dictionary.iteritems() on Python 2 and
dictionary.items() on Python 3.

six.string_types replaces basestring() in Python 2 and str
in Python 3.

Change-Id: Ia18510d167df35caec83626718010228e2140bc0
2014-01-13 12:15:15 +01:00
Yassine Lamgarchal
440d155558 Python3: use six.StringIO rather than StringIO.StringIO
It’s an alias for StringIO.StringIO in Python 2 and
io.StringIO in Python 3.

Change-Id: I1c2f1412c586d5d8e0aa866a28232747056e0ca7
2014-01-10 17:17:43 +01:00
Le Tian Ren
2ed01afac9 Fix glanceclient http.py string formatting error
* Fix "TypeError: not all arguments converted during string formatting"

* Add a UT case to cover the path where the bug is in

Change-Id: I91a137c5c3a9a3cc603804bef5eaea14ae281c08
Closes-Bug: #1265730
2014-01-07 16:09:01 +08:00
Jenkins
14b74573f1 Merge "Fix and enable gating on H306" 2013-12-23 05:10:08 +00:00
Dirk Mueller
9f255a9b49 Fix and enable gating on H306
H306 - module imports should be in alphabetical order

Change-Id: I1f8fc25b0e6ca23c21c90bda420f42a45141c2e2
2013-12-16 15:28:05 +01:00
Dominik Heidler
097ca3d53f SSL: Handle wildcards in Subject Alternative Names
Closes-Bug: #1259528

Change-Id: Iedc2b98d47f1f9433a4cfd77e07f7f86bae806c1
2013-12-11 10:27:20 +01:00
Jenkins
5d658bf5a8 Merge "python3: xrange no longer exists" 2013-11-26 13:35:28 +00:00
Jenkins
9a649d46ea Merge "Replace OpenStack LLC with OpenStack Foundation" 2013-11-15 06:33:28 +00:00
Jenkins
12a1d719b2 Merge "Fix python 3.x related Hacking warnings" 2013-11-12 04:38:33 +00:00
Chuck Short
518cb2508d python3: use six.moves for httplib imports
This adds six to the requirements.txt file in order to make
some HTTP-related imports work across Python 2's httplib and Python 3's
http.client modules. Tests were updated, including one change to the
location of HTTPConnection - moving it from being accessed where it was
imported rather than its canonical location inside of
six.moves.http_client.

Change-Id: Ibc4932b37dfdf195cd5091066914513af1876955
Signed-off-by: Chuck Short <chuck.short@canonical.com>
2013-10-16 10:00:56 -04:00
Chuck Short
7a80d6de39 python3: xrange no longer exists
range now behaves like xrange did in Python 2.

http://docs.python.org/3.1/whatsnew/3.0.html

Change-Id: I71bef224fb6b0e972373a024f8b86355b5970827
Signed-off-by: Chuck Short <chuck.short@canonical.com>
2013-10-15 11:34:20 -04:00
Jenkins
cd11833cff Merge "Fix regression bug after removing posixpath in http.py" 2013-10-09 17:46:01 +00:00
Yang Yu
a0715e966d Fix regression bug after removing posixpath in http.py
After removing posixpath.normpath(url) in http.py, the code has a
regression bug that the url like 'http://example.com:80/test' can
not work. The code urlparse.urljoin() can not work as '%s%s' %
(self.endpoint_path, url).

Fixes bug #1230032

Change-Id: Ie7266fc3a067b92dfeed169086b4bf6a87dedbd6
2013-09-28 21:47:09 -05:00
Russell Bryant
50266eec2b Fix getting header in redirect processing
The code for processing an HTTP redirect included an incorrect method of
getting the Location header from an HTTPResponse.  It needs to use the
getheader() method on the response, instead.  This patch fixes that and
includes a unit test that covers this code path.

Change-Id: I0952fabad581b020dee07bdc4007b55b47c906aa
Closes-Bug: #1231524
2013-09-26 11:45:06 -04:00
Russell Bryant
4718635811 Fix default value for a header
This code specified None as the default value, but it would raise an
exception if that was ever returned.  An empty string causes the code to
work as intended.

This came up while I was writing a unit test for another bug fix.

Change-Id: I658bb8a9b5124f281988fb60b645182ea0ccf99f
Related-bug: #1231524
2013-09-26 11:45:05 -04:00
ZhiQiang Fan
2517203975 Replace OpenStack LLC with OpenStack Foundation
Change-Id: I38dcbcf1a6c8efe540fcf5f29e782cb3826e583d
Fixes-Bug: #1214176
2013-09-20 04:05:51 +08:00
Dirk Mueller
69fa91b432 Fix python 3.x related Hacking warnings
Convert print operator usages to print functions.
Fix one instance of outdated "except x,y:" syntactical construct.
Remove usages of local() in string formatting alongway.

Change-Id: Id0673a9183a6ea6bd9bf3f5c6d8e7c5f114ebf01
2013-08-26 14:25:23 +02:00
Jenkins
835638fd8a Merge "Don't use posixpath for URLs" 2013-08-22 21:12:47 +00:00
Brian Waldon
683e40fd31 Allow single-wildcard SSL common name matching
Fix bug 1212463

Change-Id: I168601fd9847497c2261c77ce6c856bca187c6c8
2013-08-21 17:57:38 +00:00
mouad benchchaoui
1d7da740b2 Show a pretty progressbar when uploading and downloading an image.
Add a new module that contain generic wrapper for file and iterator, which
are used to wrap image to upload and the request body iterator in upload and
download cases repectively, to show and advance a pretty progress bar when this
laters are consumed, The progress bar is triggered by adding a --progress command
line argument to commands: image-create, image-download or image-update.

Change-Id: I2ba42fd0c58f4fa087adb568ec3f08246cae3759
bug fix: LP#1112309
blueprint: progressbar-when-uploading
2013-08-08 15:40:15 +02:00
Justin Santa Barbara
a30981e7f0 Don't use posixpath for URLs
Use URL functions instead.

Fixes bug #1208618

Change-Id: I27bb29a6422200a1a522c50335e5d93d495ec429
2013-08-05 14:42:19 -07:00
Jenkins
8d7411d78b Merge "HTTPS response issues" 2013-07-24 22:11:08 +00:00
Jenkins
49a1207266 Merge "Fix SSL certificate CNAME checking" 2013-07-22 21:50:07 +00:00
David Peraza
5d90740f33 HTTPS response issues
Fixes bug 1179392

glanceclient.common.http.HTTPClient.get_connection_kwargs method
explicitly sets the timeout to be a float, while struc.pack is
still using LL as the format string which means 2 Long Integers.
Setting format string to fL which mean a float followed by Long
Integer.

Also, Bad file descriptor error is caused by socket being closed
to soon. Added a close() implementation to VerifiedHTTPSConnection
which will remove reference to socket before returning call to
base HTTPConnection.close(). This will avoid socket to be closed
before response body is read. Socket will close when response
close is called.

Change-Id: I3a973da3b962c7572ae0f61f6996bdd1f0048339
2013-07-22 15:33:38 +00:00
iccha.sethi
95810ef1d2 Pass all identity headers received to glance
There is an upcoming patch in nova which passes identity
headers to glance client. We want to ensure that these get
passed to glance, which in turn with help the no auth
option in glance.

Resolves bug 1200761

Change-Id: Ifbef582aa4e64a2e7a46db43a9cc6cf8c3531dbd
2013-07-15 14:20:37 +00:00
Thomas Leaman
822cd64c07 Fix SSL certificate CNAME checking
Currently, accessing a host via ip address will pass SSL verification;
the CNAME is not checked as intended as part of verify_callback.

'preverify_ok is True' will always return false (int/bool comparison).
preverify_ok will be 1 if preverification has passed.

Fixes bug 1192229

Change-Id: Ib651548ab4289295a9b92ee039b2aff2d08aba5f
2013-07-15 08:50:17 +00:00
Dirk Mueller
62579fbb21 Start using Pyflakes and Hacking
Instead of globally ignoring pyflakes and
hacking warnings, only blacklist those that trigger
very frequently so far, in order to clean them
up in followup commits. Fix and start gating
on the rest already.

Change-Id: Ied7c7250061e3bf379e8286e8ce3b9e4af817faf
2013-06-22 16:00:26 +02:00
Kevin McDonald
d8a537c7fe Removes extra slash on endpoints without a path
Change-Id: I5ce54117c5ac276fb9629c71eb16db88e078c947
Fixes: bug #1179984
2013-06-19 15:49:05 +00:00
Flaper Fesp
7818387d4a Replace utils.ensure_(str|unicode) with strutils.safe(decode|encode)
Glanceclient implemented both functions before they landed into oslo.
Since both functions are already in oslo, it is now possible to pull
them in.

There's a small difference between glance's implementation and oslo's,
that is the later does not convert non-str objects - int, bool - to str
before trying to decode / encode them. This patch takes care of that
where necessary, more precisely, while encoding headers before doing a
new request.

Fixes bug: #1172253

Change-Id: I9a0dca31140bae28d8ec6aede515c5bb852b701b
2013-06-04 00:42:32 +02:00
Andy McCrae
a3223b9972 Fix inconsistent --debug messages on image-update
image-update --debug message no longer adds '-d "None"' to the curl command that
is output. This keeps the curl output consistent with the client
request.

Fixes bug #1172702

Change-Id: I34ceeb6f4a67c753ca3a805ec11240a99ce38ec4
2013-04-27 13:48:57 +01:00