Revert "Display neutron api error message more precisely"
This reverts commit 23f4aa883244098f121c244e897c417410a8544f. This patch is problematic, it is breaking cases that are not Neutron related. The problem is that when there are HttpError thrown, we cannot guarantee that the body contains a valid JSON, the .response.json line is wrong. Need to rework it. Change-Id: Ie513c0869bb253680dfe3a08b1c5f09c2d4783a5
This commit is contained in:
parent
23f4aa8832
commit
ebe322dcd3
@ -70,18 +70,8 @@ def map_exceptions(func):
|
|||||||
url=e.url, method=e.method,
|
url=e.url, method=e.method,
|
||||||
http_status=e.http_status, cause=e)
|
http_status=e.http_status, cause=e)
|
||||||
else:
|
else:
|
||||||
message = e.message
|
|
||||||
details = e.details
|
|
||||||
|
|
||||||
if e.response is not None:
|
|
||||||
body = e.response.json()
|
|
||||||
if 'NeutronError' in body:
|
|
||||||
err_dict = body['NeutronError']
|
|
||||||
message = err_dict.get('message') or message
|
|
||||||
details = err_dict.get('detail') or details
|
|
||||||
|
|
||||||
raise exceptions.HttpException(
|
raise exceptions.HttpException(
|
||||||
message=message, details=details,
|
message=e.message, details=e.details,
|
||||||
response=e.response, request_id=e.request_id,
|
response=e.response, request_id=e.request_id,
|
||||||
url=e.url, method=e.method,
|
url=e.url, method=e.method,
|
||||||
http_status=e.http_status, cause=e)
|
http_status=e.http_status, cause=e)
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from openstack import exceptions
|
|
||||||
from openstack.network.v2 import router
|
from openstack.network.v2 import router
|
||||||
from openstack.tests.functional import base
|
from openstack.tests.functional import base
|
||||||
|
|
||||||
@ -55,20 +54,3 @@ class TestRouter(base.BaseFunctionalTest):
|
|||||||
def test_update(self):
|
def test_update(self):
|
||||||
sot = self.conn.network.update_router(self.ID, name=self.UPDATE_NAME)
|
sot = self.conn.network.update_router(self.ID, name=self.UPDATE_NAME)
|
||||||
self.assertEqual(self.UPDATE_NAME, sot.name)
|
self.assertEqual(self.UPDATE_NAME, sot.name)
|
||||||
|
|
||||||
def test_error(self):
|
|
||||||
destination = "10.10.10.0/24"
|
|
||||||
nexthop = "192.168.0.13"
|
|
||||||
message = "Invalid input for routes. Reason: Invalid data format " \
|
|
||||||
"for hostroute: '{u'destination': u'%s', " \
|
|
||||||
"u'nexthop': u'%s'}'." % (destination, nexthop)
|
|
||||||
|
|
||||||
with self.assertRaises(exceptions.HttpException) as cm:
|
|
||||||
routes = {
|
|
||||||
"destination": destination,
|
|
||||||
"nexthop": nexthop,
|
|
||||||
}
|
|
||||||
|
|
||||||
self.conn.network.update_router(self.ID, routes=routes)
|
|
||||||
|
|
||||||
self.assertEqual(message, cm.exception.message)
|
|
||||||
|
@ -82,28 +82,6 @@ class TestSession(testtools.TestCase):
|
|||||||
self.assertEqual(ksa_exc.http_status, os_exc.http_status)
|
self.assertEqual(ksa_exc.http_status, os_exc.http_status)
|
||||||
self.assertEqual(ksa_exc, os_exc.cause)
|
self.assertEqual(ksa_exc, os_exc.cause)
|
||||||
|
|
||||||
def test_map_exceptions_neutron_exception(self):
|
|
||||||
fake_response = mock.Mock()
|
|
||||||
message = "neutron error message"
|
|
||||||
detail = "neutron detailed message"
|
|
||||||
body = {
|
|
||||||
"NeutronError": {
|
|
||||||
"message": message,
|
|
||||||
"detail": detail,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fake_response.json = mock.Mock(return_value=body)
|
|
||||||
|
|
||||||
ksa_exc = _exceptions.HttpError(response=fake_response)
|
|
||||||
func = mock.Mock(side_effect=ksa_exc)
|
|
||||||
|
|
||||||
os_exc = self.assertRaises(
|
|
||||||
exceptions.HttpException, session.map_exceptions(func))
|
|
||||||
|
|
||||||
self.assertEqual(message, os_exc.message)
|
|
||||||
self.assertEqual(detail, os_exc.details)
|
|
||||||
|
|
||||||
def test_map_exceptions_sdk_exception_1(self):
|
def test_map_exceptions_sdk_exception_1(self):
|
||||||
ksa_exc = _exceptions.ClientException()
|
ksa_exc = _exceptions.ClientException()
|
||||||
func = mock.Mock(side_effect=ksa_exc)
|
func = mock.Mock(side_effect=ksa_exc)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user