Get rid of httplib2, use urllib3 instead
httplib2 has been abandonned by its author [1] and is less going
to be updated and maintained than urllib3. So, let's replace httplib2
with urllib3.
Note that this patch mostly rework the unit tests.
I removed the files `tempest.tests.fake_identity` and
`tempest.tests.fake_http` to use their `tempest.tests.lib` counterpart.
Also, I tried to "encapsulated" HTTP calls and use
`tempest/lib/common/http.py` everywhere so that we only import
urllib3 once. This makes us not so dependent on a specific HTTP
library.
[1] http://bitworking.org/news/2016/03/an_update_on_httplib2
Change-Id: Id469e78afdb69a404144568a454d98d20a924231
diff --git a/tempest/lib/common/http.py b/tempest/lib/common/http.py
index b3793bc..dffc5f9 100644
--- a/tempest/lib/common/http.py
+++ b/tempest/lib/common/http.py
@@ -1,5 +1,4 @@
-# Copyright 2013 OpenStack Foundation
-# Copyright 2013 Citrix Systems, Inc.
+# Copyright 2016 OpenStack Foundation
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -14,12 +13,43 @@
# License for the specific language governing permissions and limitations
# under the License.
-import httplib2
+import urllib3
-class ClosingHttp(httplib2.Http):
- def request(self, *args, **kwargs):
+class ClosingHttp(urllib3.poolmanager.PoolManager):
+ def __init__(self, disable_ssl_certificate_validation=False,
+ ca_certs=None):
+ kwargs = {}
+
+ if disable_ssl_certificate_validation:
+ urllib3.disable_warnings()
+ kwargs['cert_reqs'] = 'CERT_NONE'
+
+ if ca_certs:
+ kwargs['cert_reqs'] = 'CERT_REQUIRED'
+ kwargs['ca_certs'] = ca_certs
+
+ super(ClosingHttp, self).__init__(**kwargs)
+
+ def request(self, url, method, *args, **kwargs):
+
+ class Response(dict):
+ def __init__(self, info):
+ for key, value in info.getheaders().items():
+ self[key.lower()] = value
+ self.status = info.status
+ self['status'] = str(self.status)
+ self.reason = info.reason
+ self.version = info.version
+ self['content-location'] = url
+
original_headers = kwargs.get('headers', {})
new_headers = dict(original_headers, connection='close')
new_kwargs = dict(kwargs, headers=new_headers)
- return super(ClosingHttp, self).request(*args, **new_kwargs)
+
+ # Follow up to 5 redirections. Don't raise an exception if
+ # it's exceeded but return the HTTP 3XX response instead.
+ retry = urllib3.util.Retry(raise_on_redirect=False, redirect=5)
+ r = super(ClosingHttp, self).request(method, url, retries=retry,
+ *args, **new_kwargs)
+ return Response(r), r.data