Merge "Change Invalid exception to a specified exception"

This commit is contained in:
Jenkins 2015-11-19 14:54:53 +00:00 committed by Gerrit Code Review
commit 0e9b0ce2ab
4 changed files with 16 additions and 1 deletions

View File

@ -626,6 +626,7 @@ class ServersController(wsgi.Controller):
msg = "UnicodeError: %s" % error
raise exc.HTTPBadRequest(explanation=msg)
except (exception.ImageNotActive,
exception.ImageBadRequest,
exception.FlavorDiskTooSmall,
exception.FlavorMemoryTooSmall,
exception.InvalidMetadata,

View File

@ -557,6 +557,11 @@ class ImageUnacceptable(Invalid):
msg_fmt = _("Image %(image_id)s is unacceptable: %(reason)s")
class ImageBadRequest(Invalid):
msg_fmt = _("Request of image %(image_id)s got BadRequest response: "
"%(response)s")
class InstanceUnacceptable(Invalid):
msg_fmt = _("Instance %(instance_id)s is unacceptable: %(reason)s")

View File

@ -640,7 +640,8 @@ def _translate_image_exception(image_id, exc_value):
if isinstance(exc_value, glanceclient.exc.NotFound):
return exception.ImageNotFound(image_id=image_id)
if isinstance(exc_value, glanceclient.exc.BadRequest):
return exception.Invalid(six.text_type(exc_value))
return exception.ImageBadRequest(image_id=image_id,
response=six.text_type(exc_value))
return exc_value

View File

@ -2983,6 +2983,14 @@ class ServersControllerCreateTest(test.TestCase):
self.controller.create,
self.req, body=self.body)
@mock.patch.object(compute_api.API, 'create',
side_effect=exception.ImageBadRequest(
image_id='dummy', response='dummy'))
def test_create_instance_raise_image_bad_request(self, mock_create):
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.create,
self.req, body=self.body)
@mock.patch.object(compute_api.API, 'create')
def test_create_instance_invalid_personality(self, mock_create):
codec = 'utf8'