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/tests/lib/fake_http.py b/tempest/tests/lib/fake_http.py
index eda202d..397c856 100644
--- a/tempest/tests/lib/fake_http.py
+++ b/tempest/tests/lib/fake_http.py
@@ -14,8 +14,6 @@
import copy
-import httplib2
-
class fake_httplib2(object):
@@ -25,7 +23,7 @@
def request(self, uri, method="GET", body=None, headers=None,
redirections=5, connection_type=None):
if not self.return_type:
- fake_headers = httplib2.Response(headers)
+ fake_headers = fake_http_response(headers)
return_obj = {
'uri': uri,
'method': method,
@@ -37,20 +35,20 @@
body = body or "fake_body"
header_info = {
'content-type': 'text/plain',
- 'status': str(self.return_type),
'content-length': len(body)
}
- resp_header = httplib2.Response(header_info)
+ resp_header = fake_http_response(header_info,
+ status=self.return_type)
return (resp_header, body)
else:
msg = "unsupported return type %s" % self.return_type
raise TypeError(msg)
-class fake_httplib(object):
+class fake_http_response(dict):
def __init__(self, headers, body=None,
version=1.0, status=200, reason="Ok"):
- """Fake httplib implementation
+ """Initialization of fake HTTP Response
:param headers: dict representing HTTP response headers
:param body: file-like object
@@ -60,10 +58,15 @@
"""
self.body = body
self.status = status
+ self['status'] = str(self.status)
self.reason = reason
self.version = version
self.headers = headers
+ if headers:
+ for key, value in headers.items():
+ self[key.lower()] = value
+
def getheaders(self):
return copy.deepcopy(self.headers).items()