Merge "Fix handling of Novaclient exceptions"

This commit is contained in:
Jenkins 2016-01-07 16:47:42 +00:00 committed by Gerrit Code Review
commit 0a4eb03858
2 changed files with 51 additions and 1 deletions
manila
compute
tests/compute

@ -149,15 +149,20 @@ def translate_server_exception(method):
Note: keeps its traceback intact.
"""
@six.wraps(method)
def wrapper(self, ctx, instance_id, *args, **kwargs):
try:
res = method(self, ctx, instance_id, *args, **kwargs)
return res
except nova_exception.ClientException as e:
if isinstance(e, nova_exception.NotFound):
raise exception.InstanceNotFound(instance_id=instance_id)
elif isinstance(e, nova_exception.BadRequest):
raise exception.InvalidInput(reason=six.text_type(e))
return res
else:
raise exception.ManilaException(e)
return wrapper

@ -86,6 +86,51 @@ class FakeNovaClient(object):
self.fixed_ips = self.FixedIPs()
@nova.translate_server_exception
def decorated_by_translate_server_exception(self, context, instance_id, exc):
if exc:
raise exc(instance_id)
else:
return 'OK'
@ddt.ddt
class TranslateServerExceptionTestCase(test.TestCase):
def test_translate_server_exception(self):
result = decorated_by_translate_server_exception(
'foo_self', 'foo_ctxt', 'foo_instance_id', None)
self.assertEqual('OK', result)
def test_translate_server_exception_not_found(self):
self.assertRaises(
exception.InstanceNotFound,
decorated_by_translate_server_exception,
'foo_self', 'foo_ctxt', 'foo_instance_id', nova_exception.NotFound)
def test_translate_server_exception_bad_request(self):
self.assertRaises(
exception.InvalidInput,
decorated_by_translate_server_exception,
'foo_self', 'foo_ctxt', 'foo_instance_id',
nova_exception.BadRequest)
@ddt.data(
nova_exception.HTTPNotImplemented,
nova_exception.RetryAfterException,
nova_exception.Unauthorized,
nova_exception.Forbidden,
nova_exception.MethodNotAllowed,
nova_exception.OverLimit,
nova_exception.RateLimit,
)
def test_translate_server_exception_other_exception(self, exc):
self.assertRaises(
exception.ManilaException,
decorated_by_translate_server_exception,
'foo_self', 'foo_ctxt', 'foo_instance_id', exc)
@ddt.ddt
class NovaApiTestCase(test.TestCase):
def setUp(self):