26 Commits

Author SHA1 Message Date
Jenkins
5ce1de9da4 Merge "https: Prevent leaking sockets for some operations" 2015-03-04 08:38:19 +00:00
Jenkins
db0179f5c4 Merge "Register our own ConnectionPool without globals" 2015-02-26 21:29:06 +00:00
Stuart McLaren
ef9fd9fca0 https: Prevent leaking sockets for some operations
Other OpenStack services which instantiate a 'https' glanceclient using
ssl_compression=False and insecure=False (eg Nova, Cinder) are leaking
sockets due to glanceclient not closing the connection to the Glance
server.

This could happen for a sub-set of calls, eg 'show', 'delete', 'update'.

netstat -nopd would show the sockets would hang around forever:

... 127.0.0.1:9292          ESTABLISHED 9552/python      off (0.00/0/0)

urllib's ConnectionPool relies on the garbage collector to tear down
sockets which are no longer in use. The 'verify_callback' function used to
validate SSL certs was holding a reference to the VerifiedHTTPSConnection
instance which prevented the sockets being torn down.

Change-Id: Idb3e68151c48ed623ab89d05d88ea48465429838
Closes-bug: 1423165
2015-02-18 12:31:24 +00:00
Ian Cordasco
7ee96cbe39 Register our own ConnectionPool without globals
Currently, on systems like Fedora and Debian, it is possible to import
urllib3 as well as requests.packages.urllib3. They functionally point to
the same code but sys.modules considers them to be separate items. When
downstream packagers unvendor urllib3 from requests, they also change
all the imports inside of the package. So if the code imports urllib3
from requests.packages.urllib3 and modifies globals in a submodule, that
will not be visible to requests since it has been rewritten to use
urllib3 (not requests.packages.urllib3). By handling this logic
ourselves, we can issue a release until upstream packages and requests
can fix this and cut a new release.

Change-Id: Ic77ce8a06d9d148a899b4b8695990fca8fdaefc5
Closes-bug: 1396550
2015-02-06 13:49:13 -06:00
James Page
b96f613026 Update HTTPS certificate handling for pep-0476
This pep (included in python 2.7.9) changes the behaviour of SSL
certificate chain handling to be more py3 like.

Include required new exception behaviour in the list of
exceptions to translate under py2.

https://github.com/python/peps/blob/master/pep-0476.txt

Closes-Bug: 1404227

Change-Id: I7da1a13d1ec861a07fd96684d0431508a214a2c8
2014-12-19 13:01:32 +00: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
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
ChangBo Guo(gcb)
1db17aaad9 Enable F841
F841 detects local variable is assigned to but never used.
This commit fixes the violations and enables F841 in gate.

Change-Id: Ic4dcac2733dfe334009327ac17aa3952cafaa63a
2014-07-09 14:10:23 +08: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
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
Jenkins
ae2b5d046a Merge "Fix the parameter order of assertEqual in glanceclient test" 2014-04-21 09:12:09 +00:00
Eiichi Aikawa
3576b1bdcb Fix the parameter order of assertEqual in glanceclient test
On assertEqual, the order of parameters should be (expected, observed).
But, some part of glanceclient test were written with invalid order.
This patch fixes this problem.

Change-Id: I7722fdce766ce3cc5bc9944dc72d7d0af0b09f69
Partially-bug: #1277104
2014-02-25 16:18:19 +09:00
Alex Gaynor
d465d60867 Replace file with open, which is Python 3 compatible
Change-Id: I471ae9b372f88a508d4654b1a18c6da90397a828
2014-02-13 06:59:18 -08:00
Shane Wang
0cda69f6a5 Fix misspellings in python-glanceclient
Fix misspellings detected by:
* pip install misspellings
* git ls-files | grep -v locale | misspellings -f -

Change-Id: I504521e702c675640ab3869c608fa96edd2477b4
Closes-Bug: #1257295
2014-02-07 13:31:58 +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
ZhiQiang Fan
2517203975 Replace OpenStack LLC with OpenStack Foundation
Change-Id: I38dcbcf1a6c8efe540fcf5f29e782cb3826e583d
Fixes-Bug: #1214176
2013-09-20 04:05:51 +08: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
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
Tatyana Leontovich
0995045f2a Improve unit tests for python-glanceclient.glanceclient.common.http
Add several tests for glanceclient.common.http module

Fixes: bug #1149445
Change-Id: I6a47c64e11cefea276163777dcd559316fc8e0ad
2013-04-04 15:06:57 +03:00
Monty Taylor
1d461a6496 Use testtools instead of unittest.
Part of blueprint grizzly-testtools

Change-Id: Ie914fd8f59cddb1a480566ec4eff908bfb51921c
2013-01-02 15:20:36 -08:00
Dean Troyer
4781da7007 Support --os-cacert
* Rename --ca-file to --os-cacert (--ca-file deprecated for
  backward compatibility)
* Add cacert to keystoneclient initialization to verify the
  keystone server certificate

This aligns glanceclient with keystoneclient for option naming
and the use of TLS for the keystone auth connection.  It does not
change the use of TLS/SSL for the glance connection.

Change-Id: If8b05655aea5f3c62612d77bf947dd790f77eddf
2012-12-11 14:46:33 -08:00
Stuart McLaren
7a5946fd87 Verify that host matches certificate
When using https verify that the Common Name (CN) or
the Subject Alternative Name listed in the server's
certificate match the host we are connected to.

Addresses LP bug 1079692.

Change-Id: I24ea1511a2cbdb7c34ce72ac704d7b5e7d57cec2
2012-11-20 09:56:00 +00:00
Stuart McLaren
556082cd66 Implement blueprint ssl-connect-rework
Use pyOpenSSL for HTTPS connections.

This allows:

* Neater loading of system CA files
* Optional disabling of SSL compression

The performance gain from disabling SSL compression is significant
in cases where the image being uploaded/downloaded is in an already
compressed format (eg qcow2).

Related to bp ssl-connect-rework.

Change-Id: I0568b6c95c5fc7b8eafdbd0284e24c453660a55a
2012-10-08 13:51:41 +00:00