File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -70,8 +70,18 @@ def map_exceptions_wrapper(*args, **kwargs):
7070 url = e .url , method = e .method ,
7171 http_status = e .http_status , cause = e )
7272 else :
73+ message = e .message
74+ details = e .details
75+
76+ if e .response is not None :
77+ body = e .response .json ()
78+ if 'NeutronError' in body :
79+ err_dict = body ['NeutronError' ]
80+ message = err_dict .get ('message' ) or message
81+ details = err_dict .get ('detail' ) or details
82+
7383 raise exceptions .HttpException (
74- message = e . message , details = e . details ,
84+ message = message , details = details ,
7585 response = e .response , request_id = e .request_id ,
7686 url = e .url , method = e .method ,
7787 http_status = e .http_status , cause = e )
Original file line number Diff line number Diff line change 1212
1313import uuid
1414
15+ from openstack import exceptions
1516from openstack .network .v2 import router
1617from openstack .tests .functional import base
1718
@@ -54,3 +55,20 @@ def test_list(self):
5455 def test_update (self ):
5556 sot = self .conn .network .update_router (self .ID , name = self .UPDATE_NAME )
5657 self .assertEqual (self .UPDATE_NAME , sot .name )
58+
59+ def test_error (self ):
60+ destination = "10.10.10.0/24"
61+ nexthop = "192.168.0.13"
62+ message = "Invalid input for routes. Reason: Invalid data format " \
63+ "for hostroute: '{u'destination': u'%s', " \
64+ "u'nexthop': u'%s'}'." % (destination , nexthop )
65+
66+ with self .assertRaises (exceptions .HttpException ) as cm :
67+ routes = {
68+ "destination" : destination ,
69+ "nexthop" : nexthop ,
70+ }
71+
72+ self .conn .network .update_router (self .ID , routes = routes )
73+
74+ self .assertEqual (message , cm .exception .message )
Original file line number Diff line number Diff line change @@ -82,6 +82,28 @@ def test_map_exceptions_http_exception(self):
8282 self .assertEqual (ksa_exc .http_status , os_exc .http_status )
8383 self .assertEqual (ksa_exc , os_exc .cause )
8484
85+ def test_map_exceptions_neutron_exception (self ):
86+ fake_response = mock .Mock ()
87+ message = "neutron error message"
88+ detail = "neutron detailed message"
89+ body = {
90+ "NeutronError" : {
91+ "message" : message ,
92+ "detail" : detail ,
93+ }
94+ }
95+
96+ fake_response .json = mock .Mock (return_value = body )
97+
98+ ksa_exc = _exceptions .HttpError (response = fake_response )
99+ func = mock .Mock (side_effect = ksa_exc )
100+
101+ os_exc = self .assertRaises (
102+ exceptions .HttpException , session .map_exceptions (func ))
103+
104+ self .assertEqual (message , os_exc .message )
105+ self .assertEqual (detail , os_exc .details )
106+
85107 def test_map_exceptions_sdk_exception_1 (self ):
86108 ksa_exc = _exceptions .ClientException ()
87109 func = mock .Mock (side_effect = ksa_exc )
You can’t perform that action at this time.
0 commit comments