"heat stack-create" doesn't return the error message from server

Change-Id: Icef10df6547e5830abb17edf5ed8c622b3b021b5
Fixes: bug #1163335
This commit is contained in:
Simon Pasquier
2013-04-02 17:04:16 +02:00
parent 8eaba00143
commit 9354f84e59
2 changed files with 20 additions and 6 deletions

View File

@@ -160,7 +160,7 @@ class HTTPClient(object):
self.log_http_response(resp, body_str)
if 400 <= resp.status < 600:
raise exc.from_response(resp, body_iter)
raise exc.from_response(resp, body_str)
elif resp.status in (301, 302, 305):
# Redirected. Reissue the request to the new location.
location = resp.getheader('location', None)
@@ -175,7 +175,7 @@ class HTTPClient(object):
raise exc.InvalidEndpoint(message=message)
return self._http_request(location, method, **kwargs)
elif resp.status == 300:
raise exc.from_response(resp, body_iter)
raise exc.from_response(resp, body_str)
return resp, body_str
@@ -187,10 +187,10 @@ class HTTPClient(object):
if 'body' in kwargs:
kwargs['body'] = json.dumps(kwargs['body'])
resp, body_iter = self._http_request(url, method, **kwargs)
resp, body_str = self._http_request(url, method, **kwargs)
if 'application/json' in resp.getheader('content-type', None):
body = ''.join([chunk for chunk in body_iter])
body = body_str
try:
body = json.loads(body)
except ValueError:

View File

@@ -183,7 +183,14 @@ class HttpClientTest(unittest.TestCase):
# Replay, create client, assert
self.m.ReplayAll()
client = http.HTTPClient('http://example.com:8004')
self.assertRaises(exc.HTTPNotFound, client.json_request, 'GET', '')
try:
client.json_request('GET', '')
self.fail('No exception raised')
except exc.HTTPNotFound as e:
# Assert that the raised exception can be converted to string
self.assertNotEqual(e.message, None)
except:
raise
self.m.VerifyAll()
def test_http_300_json_request(self):
@@ -200,7 +207,14 @@ class HttpClientTest(unittest.TestCase):
# Replay, create client, assert
self.m.ReplayAll()
client = http.HTTPClient('http://example.com:8004')
self.assertRaises(exc.HTTPMultipleChoices, client.json_request, 'GET', '')
try:
client.json_request('GET', '')
self.fail('No exception raised')
except exc.HTTPMultipleChoices as e:
# Assert that the raised exception can be converted to string
self.assertNotEqual(e.message, None)
except:
raise
self.m.VerifyAll()
#def test_https_json_request(self):