Catch OverQuota in volume create function
Volume API may raise OverQuota exception to nova API layer, so nova volume API should catch it and raise HTTPForbidden just like other API. according to new rule on the footnote[1] of following doc https://github.com/openstack/nova/blob/master/doc/source/api_microversion_dev.rst no microversion will be used for this change. Closes-Bug: 1444559 Change-Id: Ia782ab9d9a31d37854606f7be82582de6d7bc374
This commit is contained in:
parent
936b0127a8
commit
08611e2f7f
@ -180,7 +180,8 @@ class VolumeController(wsgi.Controller):
|
||||
)
|
||||
except exception.InvalidInput as err:
|
||||
raise exc.HTTPBadRequest(explanation=err.format_message())
|
||||
|
||||
except exception.OverQuota as err:
|
||||
raise exc.HTTPForbidden(explanation=err.format_message())
|
||||
# TODO(vish): Instance should be None at db layer instead of
|
||||
# trying to lazy load, but for now we turn it into
|
||||
# a dict to avoid an error.
|
||||
|
@ -131,7 +131,7 @@ class VolumeController(wsgi.Controller):
|
||||
res = [entity_maker(context, vol) for vol in limited_list]
|
||||
return {'volumes': res}
|
||||
|
||||
@extensions.expected_errors((400, 404))
|
||||
@extensions.expected_errors((400, 403, 404))
|
||||
@validation.schema(volumes_schema.create)
|
||||
def create(self, req, body):
|
||||
"""Creates a new volume."""
|
||||
@ -171,6 +171,8 @@ class VolumeController(wsgi.Controller):
|
||||
)
|
||||
except exception.InvalidInput as err:
|
||||
raise exc.HTTPBadRequest(explanation=err.format_message())
|
||||
except exception.OverQuota as err:
|
||||
raise exc.HTTPForbidden(explanation=err.format_message())
|
||||
|
||||
# TODO(vish): Instance should be None at db layer instead of
|
||||
# trying to lazy load, but for now we turn it into
|
||||
|
@ -269,10 +269,10 @@ class VolumeApiTestV21(test.NoDBTestCase):
|
||||
self.assertEqual(resp_dict['volume']['availabilityZone'],
|
||||
vol['availability_zone'])
|
||||
|
||||
def test_volume_create_bad(self):
|
||||
def _test_volume_create_bad(self, cinder_exc, api_exc):
|
||||
def fake_volume_create(self, context, size, name, description,
|
||||
snapshot, **param):
|
||||
raise exception.InvalidInput(reason="bad request data")
|
||||
raise cinder_exc
|
||||
|
||||
self.stubs.Set(cinder.API, "create", fake_volume_create)
|
||||
|
||||
@ -283,7 +283,7 @@ class VolumeApiTestV21(test.NoDBTestCase):
|
||||
body = {"volume": vol}
|
||||
|
||||
req = fakes.HTTPRequest.blank(self.url_prefix + '/os-volumes')
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.assertRaises(api_exc,
|
||||
volumes.VolumeController().create, req, body=body)
|
||||
|
||||
@mock.patch.object(cinder.API, 'get_snapshot')
|
||||
@ -297,6 +297,14 @@ class VolumeApiTestV21(test.NoDBTestCase):
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
volumes.VolumeController().create, req, body=body)
|
||||
|
||||
def test_volume_create_bad_input(self):
|
||||
self._test_volume_create_bad(exception.InvalidInput(reason='fake'),
|
||||
webob.exc.HTTPBadRequest)
|
||||
|
||||
def test_volume_create_bad_quota(self):
|
||||
self._test_volume_create_bad(exception.OverQuota(overs='fake'),
|
||||
webob.exc.HTTPForbidden)
|
||||
|
||||
def test_volume_index(self):
|
||||
req = fakes.HTTPRequest.blank(self.url_prefix + '/os-volumes')
|
||||
resp = req.get_response(self.app)
|
||||
|
Loading…
Reference in New Issue
Block a user