Change Invalid exception to a specified exception
Compute API will call function https://github.com/openstack/nova/blob/master/nova/compute/api.py#L544 this in turn will call https://github.com/openstack/nova/blob/master/nova/image/api.py#L91 which will call https://github.com/openstack/nova/blob/master/nova/image/glance.py#L290 then finally https://github.com/openstack/nova/blob/master/nova/image/glance.py#L621 may raise exception.Invalid so nova need to catch that exception and handle it, instead of using Invalid exception to catch unexpected exception, use a new exception for this kind of error case and catch it at API layer. Change-Id: Ia6ec5c561706c75e06b356993f8bc722109ed9e7 Related-bug: 1483645
This commit is contained in:
parent
78a4302896
commit
4c34d7c328
|
@ -627,6 +627,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,
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
|
@ -618,7 +618,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
|
||||
|
||||
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in New Issue