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
This commit is contained in:
@@ -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.'
|
_STATEINVALID_EXPL = 'Unable to update port state with specified value.'
|
||||||
_PORTINUSE_EXPL = 'A resource is currently attached to the logical port'
|
_PORTINUSE_EXPL = 'A resource is currently attached to the logical port'
|
||||||
_ALREADYATTACHED_EXPL = 'The resource is already attached to another port'
|
_ALREADYATTACHED_EXPL = 'The resource is already attached to another port'
|
||||||
|
_NOTIMPLEMENTED_EXPL = 'Not implemented'
|
||||||
|
|
||||||
|
|
||||||
class QuantumHTTPError(webob.exc.HTTPClientError):
|
class QuantumHTTPError(webob.exc.HTTPClientError):
|
||||||
@@ -60,6 +61,11 @@ class QuantumHTTPError(webob.exc.HTTPClientError):
|
|||||||
'code': 440,
|
'code': 440,
|
||||||
'title': 'alreadyAttached',
|
'title': 'alreadyAttached',
|
||||||
'explanation': _ALREADYATTACHED_EXPL
|
'explanation': _ALREADYATTACHED_EXPL
|
||||||
|
},
|
||||||
|
exceptions.NotImplementedError: {
|
||||||
|
'code': 501,
|
||||||
|
'title': 'notImplemented',
|
||||||
|
'explanation': _NOTIMPLEMENTED_EXPL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ EXCEPTIONS = {
|
|||||||
430: exceptions.PortNotFound,
|
430: exceptions.PortNotFound,
|
||||||
431: exceptions.StateInvalid,
|
431: exceptions.StateInvalid,
|
||||||
432: exceptions.PortInUseClient,
|
432: exceptions.PortInUseClient,
|
||||||
440: exceptions.AlreadyAttachedClient}
|
440: exceptions.AlreadyAttachedClient,
|
||||||
|
501: exceptions.NotImplementedError}
|
||||||
AUTH_TOKEN_HEADER = "X-Auth-Token"
|
AUTH_TOKEN_HEADER = "X-Auth-Token"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -159,6 +159,10 @@ class MissingArgumentError(Error):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class NotImplementedError(Error):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def wrap_exception(f):
|
def wrap_exception(f):
|
||||||
def _wrap(*args, **kw):
|
def _wrap(*args, **kw):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -20,10 +20,13 @@ import routes
|
|||||||
import unittest
|
import unittest
|
||||||
from quantum.tests.unit import BaseTest
|
from quantum.tests.unit import BaseTest
|
||||||
from webtest import TestApp
|
from webtest import TestApp
|
||||||
|
from webtest import AppError
|
||||||
|
|
||||||
|
|
||||||
from quantum import wsgi
|
from quantum import wsgi
|
||||||
|
from quantum.api import faults
|
||||||
from quantum.common import config
|
from quantum.common import config
|
||||||
|
from quantum.common import exceptions
|
||||||
from quantum.common import extensions
|
from quantum.common import extensions
|
||||||
import sys
|
import sys
|
||||||
print sys.path
|
print sys.path
|
||||||
@@ -63,12 +66,34 @@ class ResourceExtensionTest(unittest.TestCase):
|
|||||||
def show(self, request, id):
|
def show(self, request, id):
|
||||||
return {'data': {'id': 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):
|
def custom_member_action(self, request, id):
|
||||||
return {'member_action': 'value'}
|
return {'member_action': 'value'}
|
||||||
|
|
||||||
def custom_collection_action(self, request, **kwargs):
|
def custom_collection_action(self, request, **kwargs):
|
||||||
return {'collection': 'value'}
|
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):
|
def test_resource_can_be_added_as_extension(self):
|
||||||
res_ext = extensions.ResourceExtension('tweedles',
|
res_ext = extensions.ResourceExtension('tweedles',
|
||||||
self.ResourceExtensionController())
|
self.ResourceExtensionController())
|
||||||
|
|||||||
Reference in New Issue
Block a user