]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Change Resource.__call__() to not leak internal errors.
authorGuilherme Salgado <gsalgado@gmail.com>
Wed, 2 May 2012 11:36:56 +0000 (08:36 -0300)
committerGuilherme Salgado <gsalgado@gmail.com>
Wed, 9 May 2012 18:28:27 +0000 (15:28 -0300)
That method now catches any non-expected errors raised by the controller's
action method and turn them into an HTTPServerError. Fixes bug 980033.

Change-Id: I7f71c029fae0e27a799f11de0802bde1003683e2

TESTING
quantum/api/faults.py
quantum/tests/unit/_test_api.py
quantum/wsgi.py
run_tests.py [changed mode: 0644->0755]
tools/pip-requires
tools/test-requires

diff --git a/TESTING b/TESTING
index 2b433d7eb28f9edb329a784e30b52c714153147e..7c16f374f8bd684343c31ee4c947cfae97bbeba4 100644 (file)
--- a/TESTING
+++ b/TESTING
@@ -27,6 +27,15 @@ Running tests
     After running all of the tests, run_test.sh will report any pep8 errors
     found in the tree.
 
+Running individual tests
+
+    Individual tests can be run using run_tests.py, you just need to pass
+    the dot-separated path to the module you want as an argument to it.
+    For example, the following would run only the APITestV11 tests from
+    quantum/tests/unit/test_api.py:
+
+      $ ./run_tests.sh quantum.tests.unit.test_api:APITestV11
+
 Adding more tests
 
     Quantum is a pretty new code base at this point and there is plenty of
index 3ad04e5f41415e82ac675dbf858779fb2d4108fd..a9e373fcb711a255a006efffb3681da5e21530e2 100644 (file)
@@ -55,7 +55,7 @@ def fault_body_function_v10(wrapped_exc):
 
 def fault_body_function_v11(wrapped_exc):
     """ This function creates the contents of the body for a fault
-    response for Quantum API v1.0.
+    response for Quantum API v1.1.
 
     :param wrapped_exc: Exception thrown by the Quantum service
     :type wrapped_exc: quantum.common.exceptions.QuantumException
index 0ef5fa3da38a9da8f21eaa8b145726217ce0008c..5d27fb8662c7c8df4d2d33800ed00e7010d1713c 100644 (file)
 #    @author: Salvatore Orlando, Citrix Systems
 
 import logging
-import unittest
+import unittest2 as unittest
 
+import mock
+
+from quantum.api.api_common import APIFaultWrapper
+from quantum.api.networks import Controller
 from quantum.common.test_lib import test_config
 from quantum.common import utils
 from quantum.db import api as db
@@ -1187,3 +1191,21 @@ class BaseAPIOperationsTest(AbstractAPITest):
 
     def test_multitenancy_json(self):
         self._test_multitenancy('json')
+
+    def test_internal_error(self):
+        """Check that internal errors do not leak.
+
+        Any internal, unexpected error should be turned into a 500 response
+        without any traces of the original exception.
+        """
+        orig_exception_msg = "An exception with a traceback"
+
+        @APIFaultWrapper()
+        def raise_exception(self, *args, **kwargs):
+            raise Exception(orig_exception_msg)
+
+        list_network_req = testlib.network_list_request(self.tenant_id, "json")
+        with mock.patch.object(Controller, 'index', new=raise_exception):
+            list_network_res = list_network_req.get_response(self.api)
+        self.assertEqual(list_network_res.status_int, 500)
+        self.assertNotIn(orig_exception_msg, list_network_res.body)
index 4028250048cda98b953c2d29de5bc3246f189499..6dd50861404a5abf56ce1cff2b498c88911a1f3c 100644 (file)
@@ -752,6 +752,12 @@ class Resource(Application):
             action_result = Fault(ex,
                                   self._xmlns,
                                   self._fault_body_function)
+        except Exception:
+            LOG.exception("Internal error")
+            # Do not include the traceback to avoid returning it to clients.
+            action_result = Fault(webob.exc.HTTPServerError(),
+                                  self._xmlns,
+                                  self._fault_body_function)
 
         if isinstance(action_result, dict) or action_result is None:
             response = self.serializer.serialize(action_result,
old mode 100644 (file)
new mode 100755 (executable)
index 43be661c2e5a34f29ee453d65e1b95b5434e8771..cbb9f18316f60b2654113d87841fd78f57c2b3bf 100644 (file)
@@ -3,7 +3,6 @@ PasteDeploy==1.5.0
 Routes>=1.12.3
 eventlet>=0.9.12
 lxml
-mox==0.5.3
 python-gflags==1.3
 sqlalchemy
 webob==1.0.8
index e0f0058b3f17e27230974fbd3ebf559510af03bf..8426f998d5f26b659a6e2787ba762440fb08774d 100644 (file)
@@ -2,9 +2,11 @@ distribute>=0.6.24
 
 coverage
 mock>=0.7.1
+mox==0.5.3
 nose
 nosexcover
 openstack.nose_plugin
 pep8==0.6.1
 sphinx>=1.1.2
+unittest2
 webtest