Revert "Display neutron api error message more precisely"

This reverts commit 23f4aa8832.

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:
Qiming Teng 2016-11-14 09:35:10 +00:00
parent 23f4aa8832
commit ebe322dcd3
3 changed files with 1 additions and 51 deletions

View File

@ -70,18 +70,8 @@ def map_exceptions(func):
url=e.url, method=e.method,
http_status=e.http_status, cause=e)
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(
message=message, details=details,
message=e.message, details=e.details,
response=e.response, request_id=e.request_id,
url=e.url, method=e.method,
http_status=e.http_status, cause=e)

View File

@ -12,7 +12,6 @@
import uuid
from openstack import exceptions
from openstack.network.v2 import router
from openstack.tests.functional import base
@ -55,20 +54,3 @@ class TestRouter(base.BaseFunctionalTest):
def test_update(self):
sot = self.conn.network.update_router(self.ID, name=self.UPDATE_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)

View File

@ -82,28 +82,6 @@ class TestSession(testtools.TestCase):
self.assertEqual(ksa_exc.http_status, os_exc.http_status)
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):
ksa_exc = _exceptions.ClientException()
func = mock.Mock(side_effect=ksa_exc)