]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add support for dealing with 501 errors (notimplemented)
authorBrad Hall <brad@nicira.com>
Tue, 24 Jan 2012 19:12:55 +0000 (11:12 -0800)
committerBrad Hall <brad@nicira.com>
Tue, 24 Jan 2012 20:47:08 +0000 (12:47 -0800)
This allows us to return NotImplemented() from an extension if the plugin
doesn't support a given function.

Change-Id: I73c6dec959aea7b2bde1378222b62e6fc82a5d43

quantum/api/faults.py
quantum/client/__init__.py
quantum/common/exceptions.py
quantum/tests/unit/test_extensions.py

index 2483d0440992b5c120b57fb215858fa8246e6e44..8ca15f30056dcedb15d1c270f25d1cb1ebbd2971 100644 (file)
@@ -26,6 +26,7 @@ _PORTNOTFOUND_EXPL = 'Unable to find a port with the specified identifier.'
 _STATEINVALID_EXPL = 'Unable to update port state with specified value.'
 _PORTINUSE_EXPL = 'A resource is currently attached to the logical port'
 _ALREADYATTACHED_EXPL = 'The resource is already attached to another port'
+_NOTIMPLEMENTED_EXPL = 'Not implemented'
 
 
 class QuantumHTTPError(webob.exc.HTTPClientError):
@@ -60,6 +61,11 @@ class QuantumHTTPError(webob.exc.HTTPClientError):
                 'code': 440,
                 'title': 'alreadyAttached',
                 'explanation': _ALREADYATTACHED_EXPL
+            },
+            exceptions.NotImplementedError: {
+                'code': 501,
+                'title': 'notImplemented',
+                'explanation': _NOTIMPLEMENTED_EXPL
             }
     }
 
index 6f02126385e9b9b7aa340687b4198e4cac12c652..3427d255da34ec2236f48edee64e65fbd8d9315d 100644 (file)
@@ -33,7 +33,8 @@ EXCEPTIONS = {
     430: exceptions.PortNotFound,
     431: exceptions.StateInvalid,
     432: exceptions.PortInUseClient,
-    440: exceptions.AlreadyAttachedClient}
+    440: exceptions.AlreadyAttachedClient,
+    501: exceptions.NotImplementedError}
 AUTH_TOKEN_HEADER = "X-Auth-Token"
 
 
index 097543501f9dc06a8c21ad23ae36f10d48213cd7..2171ede7dd3377fa0482e08788e72558414df247 100644 (file)
@@ -159,6 +159,10 @@ class MissingArgumentError(Error):
     pass
 
 
+class NotImplementedError(Error):
+    pass
+
+
 def wrap_exception(f):
     def _wrap(*args, **kw):
         try:
index 532409ed04da519749cfde1d18a093fa4bf51703..2eaaeb93823f8eed2bb30de28fc0073c86eb81f3 100644 (file)
@@ -20,10 +20,13 @@ import routes
 import unittest
 from quantum.tests.unit import BaseTest
 from webtest import TestApp
+from webtest import AppError
 
 
 from quantum import wsgi
+from quantum.api import faults
 from quantum.common import config
+from quantum.common import exceptions
 from quantum.common import extensions
 import sys
 print sys.path
@@ -63,12 +66,34 @@ class ResourceExtensionTest(unittest.TestCase):
         def show(self, request, id):
             return {'data': {'id': id}}
 
+        def notimplemented_function(self, request, id):
+            return faults.QuantumHTTPError(
+                exceptions.NotImplementedError("notimplemented_function"))
+
         def custom_member_action(self, request, id):
             return {'member_action': 'value'}
 
         def custom_collection_action(self, request, **kwargs):
             return {'collection': 'value'}
 
+    def test_exceptions_notimplemented(self):
+        controller = self.ResourceExtensionController()
+        member = {'notimplemented_function': "GET"}
+        res_ext = extensions.ResourceExtension('tweedles', controller,
+                                               member_actions=member)
+        test_app = setup_extensions_test_app(SimpleExtensionManager(res_ext))
+
+        # Ideally we would check for a 501 code here but webtest doesn't take
+        # anything that is below 200 or above 400 so we can't actually check
+        # it.  It thows AppError instead.
+        try:
+            response = \
+                test_app.get("/tweedles/some_id/notimplemented_function")
+            # Shouldn't be reached
+            self.assertTrue(False)
+        except AppError:
+            pass
+
     def test_resource_can_be_added_as_extension(self):
         res_ext = extensions.ResourceExtension('tweedles',
                                             self.ResourceExtensionController())