# License for the specific language governing permissions and limitations
# under the License.
-import urlparse
-import httplib
import hashlib
+import requests
from heat.openstack.common import gettextutils
creds_json = json.dumps(creds)
headers = {'Content-Type': 'application/json'}
- # Disable 'has no x member' pylint error
- # for httplib and urlparse
- # pylint: disable-msg=E1101
-
keystone_ec2_uri = self._conf_get_keystone_ec2_uri()
logger.info('Authenticating with %s' % keystone_ec2_uri)
- o = urlparse.urlparse(keystone_ec2_uri)
- if o.scheme == 'http':
- conn = httplib.HTTPConnection(o.netloc)
- else:
- conn = httplib.HTTPSConnection(o.netloc)
- conn.request('POST', o.path, body=creds_json, headers=headers)
- response = conn.getresponse().read()
- conn.close()
-
- # NOTE(vish): We could save a call to keystone by
- # having keystone return token, tenant,
- # user, and roles from this call.
-
- result = json.loads(response)
+ response = requests.post(keystone_ec2_uri, data=creds_json,
+ headers=headers)
+ result = response.json()
try:
token_id = result['access']['token']['id']
tenant = result['access']['token']['tenant']['name']
from heat.tests.common import HeatTestCase
-import mox
-import httplib
+import requests
import json
from oslo.config import cfg
def _stub_http_connection(self, headers={}, params={}, response=None):
class DummyHTTPResponse(object):
- resp = response
+ text = response
- def read(self):
- return self.resp
+ def json(self):
+ return json.loads(self.text)
- self.m.StubOutWithMock(httplib.HTTPConnection, '__init__')
- httplib.HTTPConnection.__init__(mox.IgnoreArg()).AndReturn(None)
-
- self.m.StubOutWithMock(httplib.HTTPConnection, 'request')
+ self.m.StubOutWithMock(requests, 'post')
body_hash = ('e3b0c44298fc1c149afbf4c8996fb9'
'2427ae41e4649b934ca495991b7852b855')
req_creds = json.dumps({"ec2Credentials":
"path": "/v1",
"body_hash": body_hash}})
req_headers = {'Content-Type': 'application/json'}
- req_path = '/v2.0/ec2tokens'
- httplib.HTTPConnection.request('POST', req_path,
- body=req_creds,
- headers=req_headers).AndReturn(None)
-
- self.m.StubOutWithMock(httplib.HTTPConnection, 'getresponse')
- httplib.HTTPConnection.getresponse().AndReturn(DummyHTTPResponse())
-
- self.m.StubOutWithMock(httplib.HTTPConnection, 'close')
- httplib.HTTPConnection.close().AndReturn(None)
+ req_url = 'http://123:5000/v2.0/ec2tokens'
+ requests.post(req_url, data=req_creds,
+ headers=req_headers).AndReturn(DummyHTTPResponse())
def test_call_ok(self):
dummy_conf = {'auth_uri': 'http://123:5000/v2.0'}