Catch exception.OverQuota when create image for volume backed instance
When create image for a volume backed instance, nova will create snapshots for all volumes attached to the instance in Cinder, and if quota exceed in Cinder, HTTP 500 will raise, we should capture this error and raise 403. Change-Id: Ic62478e22a7477cfaefac3e63c383082d66bd635 Closes-Bug: #1689284
This commit is contained in:
parent
2350dab129
commit
29c8ae3cd9
|
@ -1016,6 +1016,8 @@ class ServersController(wsgi.Controller):
|
|||
'createImage', id)
|
||||
except exception.Invalid as err:
|
||||
raise exc.HTTPBadRequest(explanation=err.format_message())
|
||||
except exception.OverQuota as e:
|
||||
raise exc.HTTPForbidden(explanation=e.format_message())
|
||||
|
||||
# Starting with microversion 2.45 we return a response body containing
|
||||
# the snapshot image id without the Location header.
|
||||
|
|
|
@ -928,7 +928,8 @@ class ServerActionsControllerTestV21(test.TestCase):
|
|||
self.controller._action_create_image, self.req,
|
||||
FAKE_UUID, body=body)
|
||||
|
||||
def _do_test_create_volume_backed_image(self, extra_properties):
|
||||
def _do_test_create_volume_backed_image(
|
||||
self, extra_properties, mock_vol_create_side_effect=None):
|
||||
|
||||
def _fake_id(x):
|
||||
return '%s-%s-%s-%s' % (x * 8, x * 4, x * 4, x * 12)
|
||||
|
@ -991,6 +992,9 @@ class ServerActionsControllerTestV21(test.TestCase):
|
|||
return_value=snapshot),
|
||||
) as (mock_quiesce, mock_vol_get, mock_vol_create):
|
||||
|
||||
if mock_vol_create_side_effect:
|
||||
mock_vol_create.side_effect = mock_vol_create_side_effect
|
||||
|
||||
response = self.controller._action_create_image(self.req,
|
||||
FAKE_UUID, body=body)
|
||||
|
||||
|
@ -1029,6 +1033,13 @@ class ServerActionsControllerTestV21(test.TestCase):
|
|||
self._do_test_create_volume_backed_image(dict(ImageType='Gold',
|
||||
ImageVersion='2.0'))
|
||||
|
||||
def test_create_volume_backed_image_cinder_over_quota(self):
|
||||
self.assertRaises(
|
||||
webob.exc.HTTPForbidden,
|
||||
self._do_test_create_volume_backed_image, {},
|
||||
mock_vol_create_side_effect=exception.OverQuota(
|
||||
overs='snapshot'))
|
||||
|
||||
def _test_create_volume_backed_image_with_metadata_from_volume(
|
||||
self, extra_metadata=None):
|
||||
|
||||
|
|
Loading…
Reference in New Issue