125 Commits

Author SHA1 Message Date
wangxiyuan
b48ff98e16 Fix exception message in Http.py
In common.http.py, the exception RequestTimeout has
wrong message.This patch fixed it.

Change-Id: Ie8ff188b9c82ce424cb8177278f36e4d1275b306
2015-07-14 09:01:12 +08:00
Cindy Pallares
997c12d3ab Import only modules and update tox.ini
As stated in the OpenStack Hacking Guidelines, it is prefered
that only modules should be imported.

Also updated tox.ini to ignore opestack/common among others.

Change-Id: I2f0a603c31052eadee581c11880c0ec6bd392829
2015-06-17 10:56:37 -05:00
Jamie Lennox
5ce9c7dc96 Make glanceclient accept a session object
To make this work we create a different HTTPClient that extends the
basic keystoneclient Adapter. The Adapter is a standard set of
parameters that all clients should know how to use like region_name and
user_agent. We extend this with the glance specific response
manipulation like loading and sending iterables.

Implements: bp session-objects
Change-Id: Ie8eb4bbf7d1a037099a6d4b272cab70525fbfc85
2015-06-11 13:11:56 +00:00
Jenkins
60e7beb28b Merge "Change oslo.utils to oslo_utils" 2015-02-06 12:44:17 +00:00
Jenkins
0272106717 Merge "Close streamed requests explicitly" 2015-02-06 12:16:46 +00:00
Louis Taylor
e99e0c8690 Change oslo.utils to oslo_utils
The oslo.utils libraries are moving away from namespace packages.

This requires oslo.utils>=1.2.0

bp drop-namespace-packages

Change-Id: I803df61e91eabb96329d859aef6bea03530fb84f
2015-02-05 22:27:16 +00:00
Ian Cordasco
db743e3635 Ignore NoneType when encoding headers
Some generated header values may in fact be None. Trying to encode None
causes the client to fail with an exception and cannot be worked around
by the user.

Change-Id: I638b1fba0ef9a07d726445d8c2cdd774140f5b83
Closes-bug: 1415935
2015-02-03 13:22:44 -06:00
Louis Taylor
878bdcbdbc Remove openstack.common.importutils
This module now lives in oslo.utils, so import it from there.

Change-Id: I41fa4897fc820596fb010336044ff4c493017d5a
2015-01-28 02:12:18 +00:00
Louis Taylor
b818826420 Remove openstack.common.strutils
This module now lives in oslo.utils, so import it from there instead.

Co-Authored-By: Ian Cordasco <ian.cordasco@rackspace.com>
Change-Id: Ib35dc840992433542490670781badd9529ec8947
2015-01-27 19:22:42 +00:00
Ian Cordasco
f2107512ee Close streamed requests explicitly
If we don't explicitly close a response after streaming its download,
then we can run into HTTPConnectionPool full warnings. It also will hurt
performance if we have to continuously create new sockets for new
responses. Calling close will return the connection to the pool so it
can be reused. Note this is only necessary when streaming a response. If
we don't stream it, then requests will return the connection to the pool
for us.

Change-Id: I803bd4dd0e769c233501d5e5ff07a19705fbe233
Closes-bug: 1341777
2015-01-15 17:20:57 -06:00
Jamie Lennox
62df6c669f Handle HTTP byte returns in python 3
The returns from requests' response.content is a bytes type. Under
python 3 this fails in error handling and string conversion. The
response.text variable should be used to treat a response body as a
string.

Closes-Bug: #1407531
Change-Id: Ifd588b5f6820ef21beb186d88d0b3f1a267695aa
2015-01-14 12:32:07 +10:00
Jenkins
dac71b4be9 Merge "Curl statements to include globoff for IPv6 URLs" 2015-01-08 14:58:41 +00:00
Sabari Kumar Murugesan
e3600ad7be Fix broken-pipe seen in glance-api
When file size is an exact multiple of chunk_size, glance client
is processing EOF in image-data as a chunk and sends to
glance-api. The server treats this as the end of chunked 
transmission and sends a http response.

When the actual last chunk is sent by the 'requests' library, the
server sends a 400 response and tracebacks with broken pipe
as the client has already closed the socket.

Closes-Bug: #1342080
Change-Id: Icdbff838450db1c252ddc919a230a7d3ca16765f
2014-12-22 19:57:46 +00:00
Flavio Percoco
5080d10099 Send identity_headers through the wire
Change I09f70eee3e2777f52ce040296015d41649c2586a, introduced a bug where
the identity_headers are not added to the request headers anymore
causing the former to be completely ignored and useless.

This patch fixes that issue by restoring the previous code. A new test
has been added to avoid regressions.

Closes-bug: #1394965
Change-Id: I1b1633636448398cf3f41217f1d671b43ebd9946
2014-11-25 10:01:39 +00:00
sridhargaddam
465c5cef8d Curl statements to include globoff for IPv6 URLs
python-glanceclient displays curl statements for debugging/troubleshooting
purposes. For IPv6 URLs, curl requires --globoff to be passed in the
arguments. Since glanceclient does not use curl directly, this patch
displays the curl commands with globoff option which works for both
IPv4 and IPv6 URLs.
Fix adapted from python-novaclient Ib7099e8e3bbc15f29bbaa1db37ef21e78a74e7bc

Closes-Bug: #1228744
Change-Id: Ie02c4e75ca1ab995102aa55bbff39b2161218b2d
2014-11-24 06:55:43 +00:00
Jenkins
46bfeb4f2c Merge "Don't set X-Auth-Token key in http session header if no token provided" 2014-11-20 09:53:49 +00:00
Jenkins
695dbc910d Merge "Don't replace the https handler in the poolmanager" 2014-11-05 19:06:11 +00:00
Matt Riedemann
8c159a2eb4 Don't set X-Auth-Token key in http session header if no token provided
Commit f980fc549247fa2deb87dfacebc6d8d13ccd45d1 changed how the
X-Auth-Token header was scrubbed when logging the request, but
effectively made the value required which can lead to an AttributeError
if the value for the header is None.

The value can be None if you're using Nova but don't have Nova
configured with auth_strategy='keystone' (see
nova.image.glance._create_glance_client for details).

This patch simply checks if the auth_token is set in the http client
object and if not, it doesn't set the X-Auth-Token key in the session
header.

Closes-Bug: #1381295

Change-Id: Ie285d5253df28a9f0f964147a53c99ceaa919c5c
2014-10-30 18:07:50 +08:00
Flavio Percoco
052904ba32 Don't replace the https handler in the poolmanager
In order to keep the support for `--ssl-nocompression` it was decided to
overwrite the https HTTPAdapter in `requests` poolmanager. Although this
seemed to work correctly, it was causing some issues when using
glanceclient from other services that rely on requests and that were
also configured to use TLS.

THis patch changes implements a different strategy by using
`glance+https` as the scheme to use when `no-compression` is requested.

Closes-bug: #1350251
Closes-bug: #1347150
Closes-bug: #1362766

Change-Id: Ib25237ba821ee20a561a163b79402d1375ebed0b
2014-10-30 09:06:02 +01:00
Jenkins
498bdffa66 Merge "Remove network_utils" 2014-10-09 10:13:45 +00:00
Jenkins
64eb97ace0 Merge "Default to system CA bundle if no CA certificate is provided" 2014-10-08 13:12:41 +00:00
Oleksii Chuprykov
5f4966df68 Remove network_utils
Use oslo.utils instead

Change-Id: I4830b13794db5570e7dde4a897a7396065028e37
2014-10-03 16:26:29 +03:00
Jenkins
83808076a1 Merge "Downgrade log message for http request failures" 2014-09-17 07:56:44 +00:00
Jenkins
49feed7cba Merge "Update how tokens are redacted" 2014-09-16 14:33:54 +00:00
Travis Tripp
f980fc5492 Update how tokens are redacted
Using SHA-1 to match how Nova and Swift redact their tokens.
Was discussed in the below thread:

http://lists.openstack.org/pipermail/openstack-dev/2014-September/045802.html

Here's what nova went with: https://review.openstack.org/#/c/99511/
swift seem to be following suit: https://review.openstack.org/#/c/99632/

Change-Id: I3045d6d9d2a13770f4022dbbd474b34eb1032f6e
Closes-bug: 1329301
2014-09-15 16:28:34 -06:00
Matt Riedemann
ba19a534b7 Handle UnicodeDecodeError in log_http_response
Similar to commit dec9c9f35 and log_curl_request,
this ignores decoding errors when logging response
headers by passing errors='ignore' to safe_encode.

Change-Id: Ic915a7d8334e9473f300c9db670a3a8f5cda8976
Closes-Bug: #1369756
2014-09-15 14:57:58 -07:00
Pawel Koniszewski
16077d91dd Catch new urllib3 exception: ProtocolError
The new version of requests (2.4.0) has updated underlying urllib3
to version 1.9. Unfortunately urllib3 introduced new exception
ProtocolError. Because of that unit tests in glance are failing:
ProtocolError: ('Connection aborted.', gaierror(-2, 'Name or service not known'))

To solve this problem new urllib3 exception is caught in the same place
that the old one was. Unfortunately both exception are still in use so
I couldn't remove the old one.

Change-Id: I55eef98e734c59b9b627f182768a633b2b701e43
Closes-Bug: #1364893
2014-09-03 23:44:39 +08:00
Rob Crittenden
929a72e76f Default to system CA bundle if no CA certificate is provided
If no CA certificate is provided to be used for validation then
fall back to the system-wide CA bundle as presented by
python-requests.

Change-Id: I05206a868150d4b62b6f1b833310eb9b86b7c4f8
Closes-bug: #1362179
2014-09-02 20:43:47 -04:00
Louis Taylor
6dda6f306f Fix error when logging http response with python 3
Python 3 changed the semantics of dict.items() [0], which now returns a
iterable 'view' instead of a list of tuples. This has the repercussion
that you can no longer check for membership of a key using:

    key in dict.items()

This patch simply replaces that check with a test for the key existing
in the dict itself, rather than the items.

[0] http://legacy.python.org/dev/peps/pep-3106/

Closes-Bug: 1359880

Change-Id: I7c59b0432725b660c9fa7270cde2e07bf3ea77db
2014-08-26 18:23:23 +00:00
Jenkins
43d9440e83 Merge "Enable osprofiler interface in glanceclient shell" 2014-08-20 00:50:26 +00:00
Stuart McLaren
d6498b602f Ensure server's SSL cert is validated
A bug was introduced which meant that the server SSL certificate was
not being verified. Here we make sure that it is checked (unless
the --insecure flag is used).

Helps guard against man-in-the-middle attack.

Change-Id: I08f30bf3906b6580c871729311343fa8eefda91b
Closes-bug: #1357430
2014-08-19 11:59:49 +00:00
Zhi Yan Liu
9a53c1fdcb Enable osprofiler interface in glanceclient shell
To help end user uses profiling by glanceclient CLI directly, the
change added '--profile <HMAC_KEY>' argument to the shell.

This change also fixed a function regression, it was used to pass
necessary trace info to glance server via http header:
dbb242b776 (diff-740dd7d9149f46fe4c01ef0ab7eb3bfbL196)

In addition:
1. If client app want to enable profiling feature for glanceclient
object, please see: http://paste.openstack.org/show/85722/
2. Afer adding more trace point into Client object, as fundamental
requirement of osprofiler, what we need to notice caller is providing
correct messaging notifier in the context code.

The relevant change for glance server is ready at:
I45a19f5eb5304c2b78a9e12cbc0744941a807304

DocImpact

Change-Id: If42b69b2695a5f88536ecbc2c1b3592d9dbd880a
Signed-off-by: Zhi Yan Liu <lzy.dev@gmail.com>
2014-08-19 03:20:22 +04:00
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
Chris Yeoh
cda8c4d6cf Downgrade log message for http request failures
Downgrades the log message when an http request fails from error
to debug. The logging level changed in the http.py upgrade in
I09f70eee3e2777f52ce040296015d41649c2586a which effectively reverted
a similar fix commited in I6d0efb53d1e81adf309f7fa580ec5a8073a811c5.

We don't want to log at ERROR level because we already have an
exception raised and the caller can handle it if wants
to. However this error will appear regularly in the Nova logs
under normal behavior (say a client specifies an image which does
not exist) and there is no way of disabling only the glanceclient
error log. This results in a lot of noise in the nova log file.

Change-Id: Iec13bff439073a79cb24e9b22fd43603ae4e61b7
2014-08-01 16:15:15 +09:30
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