From ebe322dcd3ea9278c65d359ce5dc8720f66d368c Mon Sep 17 00:00:00 2001 From: Qiming Teng Date: Mon, 14 Nov 2016 09:35:10 +0000 Subject: [PATCH] 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 --- openstack/session.py | 12 +--------- .../functional/network/v2/test_router.py | 18 --------------- openstack/tests/unit/test_session.py | 22 ------------------- 3 files changed, 1 insertion(+), 51 deletions(-) diff --git a/openstack/session.py b/openstack/session.py index 8a5fc6633..5b087fcf3 100644 --- a/openstack/session.py +++ b/openstack/session.py @@ -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) diff --git a/openstack/tests/functional/network/v2/test_router.py b/openstack/tests/functional/network/v2/test_router.py index 8e8a64ea0..1102c5da1 100644 --- a/openstack/tests/functional/network/v2/test_router.py +++ b/openstack/tests/functional/network/v2/test_router.py @@ -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) diff --git a/openstack/tests/unit/test_session.py b/openstack/tests/unit/test_session.py index d36194d17..a1f8ebc85 100644 --- a/openstack/tests/unit/test_session.py +++ b/openstack/tests/unit/test_session.py @@ -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)