From: Brad Hall Date: Tue, 24 Jan 2012 19:12:55 +0000 (-0800) Subject: Add support for dealing with 501 errors (notimplemented) X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=975d5a996bcf3e28c572e1c34274c4eab04b46e6;p=openstack-build%2Fneutron-build.git Add support for dealing with 501 errors (notimplemented) This allows us to return NotImplemented() from an extension if the plugin doesn't support a given function. Change-Id: I73c6dec959aea7b2bde1378222b62e6fc82a5d43 --- diff --git a/quantum/api/faults.py b/quantum/api/faults.py index 2483d0440..8ca15f300 100644 --- a/quantum/api/faults.py +++ b/quantum/api/faults.py @@ -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 } } diff --git a/quantum/client/__init__.py b/quantum/client/__init__.py index 6f0212638..3427d255d 100644 --- a/quantum/client/__init__.py +++ b/quantum/client/__init__.py @@ -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" diff --git a/quantum/common/exceptions.py b/quantum/common/exceptions.py index 097543501..2171ede7d 100644 --- a/quantum/common/exceptions.py +++ b/quantum/common/exceptions.py @@ -159,6 +159,10 @@ class MissingArgumentError(Error): pass +class NotImplementedError(Error): + pass + + def wrap_exception(f): def _wrap(*args, **kw): try: diff --git a/quantum/tests/unit/test_extensions.py b/quantum/tests/unit/test_extensions.py index 532409ed0..2eaaeb938 100644 --- a/quantum/tests/unit/test_extensions.py +++ b/quantum/tests/unit/test_extensions.py @@ -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())