]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Send proper exception info as expected by the neutron client
authorOleg Bondarev <obondarev@mirantis.com>
Thu, 19 Sep 2013 11:07:23 +0000 (15:07 +0400)
committerOleg Bondarev <obondarev@mirantis.com>
Thu, 19 Sep 2013 13:32:30 +0000 (17:32 +0400)
The python neutron client for the V2 API expects the neutron API
to send information back such as the type and detail of the exception
in the body of the message

Change-Id: I9486d757258c4be72799c41102babe1f7923121c
Closes-bug: #1226400

neutron/api/v2/resource.py
neutron/tests/unit/test_api_v2.py
neutron/tests/unit/test_api_v2_resource.py
neutron/tests/unit/test_db_plugin.py

index 0066846aabc65e7c15a3dc4d2fdc5379842650db..8a69b555775bb9cc7cb8950690bc2e1c542ce8a8 100644 (file)
@@ -86,7 +86,10 @@ def Resource(controller, faults=None, deserializers=None, serializers=None):
                 netaddr.AddrFormatError) as e:
             LOG.exception(_('%s failed'), action)
             e = translate(e, language)
-            body = serializer.serialize({'NeutronError': e})
+            # following structure is expected by python-neutronclient
+            err_data = {'type': e.__class__.__name__,
+                        'message': e, 'detail': ''}
+            body = serializer.serialize({'NeutronError': err_data})
             kwargs = {'body': body, 'content_type': content_type}
             for fault in faults:
                 if isinstance(e, fault):
index 012822e0d6ac17661a0cbde673706fb72b24212c..3268bbac18ce92b4671d553849b6cb96930cc881 100644 (file)
@@ -1315,7 +1315,7 @@ class QuotaTest(APIv2TestBase):
         instance.get_networks_count.assert_called_with(mock.ANY,
                                                        filters=mock.ANY)
         self.assertIn("Quota exceeded for resources",
-                      res.json['NeutronError'])
+                      res.json['NeutronError']['message'])
 
     def test_create_network_quota_no_counts(self):
         cfg.CONF.set_override('quota_network', 1, group='QUOTAS')
@@ -1332,7 +1332,7 @@ class QuotaTest(APIv2TestBase):
         instance.get_networks_count.assert_called_with(mock.ANY,
                                                        filters=mock.ANY)
         self.assertIn("Quota exceeded for resources",
-                      res.json['NeutronError'])
+                      res.json['NeutronError']['message'])
 
     def test_create_network_quota_without_limit(self):
         cfg.CONF.set_override('quota_network', -1, group='QUOTAS')
index 3ada9cf646513e3d3c67e568f2d6265ae407ce16..564a01c4ce0a810f8557a01b1beba306c3416b24 100644 (file)
@@ -129,7 +129,11 @@ class ResourceTestCase(base.BaseTestCase):
 
         class TestException(q_exc.NeutronException):
             message = msg
-        expected_res = {'body': {'NeutronError': msg}}
+        expected_res = {'body': {
+            'NeutronError': {
+                'type': 'TestException',
+                'message': msg,
+                'detail': ''}}}
         controller = mock.MagicMock()
         controller.test.side_effect = TestException()
 
@@ -147,7 +151,11 @@ class ResourceTestCase(base.BaseTestCase):
 
         class TestException(q_exc.NeutronException):
             message = msg
-        expected_res = {'body': {'NeutronError': msg}}
+        expected_res = {'body': {
+            'NeutronError': {
+                'type': 'TestException',
+                'message': msg,
+                'detail': ''}}}
         controller = mock.MagicMock()
         controller.test.side_effect = TestException()
 
@@ -187,7 +195,11 @@ class ResourceTestCase(base.BaseTestCase):
 
         class TestException(q_exc.NeutronException):
             message = msg
-        expected_res = {'body': {'NeutronError': msg}}
+        expected_res = {'body': {
+            'NeutronError': {
+                'type': 'TestException',
+                'message': msg,
+                'detail': ''}}}
         controller = mock.MagicMock()
         controller.test.side_effect = TestException()
 
@@ -207,7 +219,11 @@ class ResourceTestCase(base.BaseTestCase):
 
         class TestException(q_exc.NeutronException):
             message = msg
-        expected_res = {'body': {'NeutronError': msg}}
+        expected_res = {'body': {
+            'NeutronError': {
+                'type': 'TestException',
+                'message': msg,
+                'detail': ''}}}
         controller = mock.MagicMock()
         controller.test.side_effect = TestException()
 
index 9d7da0621e12f71fffdba6352ecc1c79c33fc8f8..002f283886c87180c6d5a8ea804f57cd60ad140b 100644 (file)
@@ -1162,7 +1162,7 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s
             res = self._create_port(self.fmt, id)
             data = self.deserialize(self.fmt, res)
             msg = str(q_exc.IpAddressGenerationFailure(net_id=id))
-            self.assertEqual(data['NeutronError'], msg)
+            self.assertEqual(data['NeutronError']['message'], msg)
             self.assertEqual(res.status_int, webob.exc.HTTPConflict.code)
 
     def test_update_port_update_ip(self):
@@ -2477,7 +2477,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
                 data = self.deserialize(self.fmt, res)
                 self.assertEqual(res.status_int, webob.exc.HTTPConflict.code)
                 msg = str(q_exc.SubnetInUse(subnet_id=id))
-                self.assertEqual(data['NeutronError'], msg)
+                self.assertEqual(data['NeutronError']['message'], msg)
 
     def test_delete_network(self):
         gateway_ip = '10.0.0.1'