Return 404 from delete of extra spec if not found
API service now returns a 404 if the volume type that the user is trying to delete doesn't exist. Fixed Bug 1090306. Change-Id: I3c1d4fdac1c2492f532ab4dbfd5c7aaf0ffa6fa4
This commit is contained in:
parent
301d72cfae
commit
de84fd7b15
@ -134,7 +134,12 @@ class VolumeTypeExtraSpecsController(wsgi.Controller):
|
||||
context = req.environ['cinder.context']
|
||||
self._check_type(context, type_id)
|
||||
authorize(context)
|
||||
db.volume_type_extra_specs_delete(context, type_id, id)
|
||||
|
||||
try:
|
||||
db.volume_type_extra_specs_delete(context, type_id, id)
|
||||
except exception.VolumeTypeExtraSpecsNotFound as error:
|
||||
raise webob.exc.HTTPNotFound(explanation=unicode(error))
|
||||
|
||||
notifier_info = dict(type_id=type_id, id=id)
|
||||
notifier_api.notify(context, 'volumeTypeExtraSpecs',
|
||||
'volume_type_extra_specs.delete',
|
||||
|
@ -1575,6 +1575,8 @@ def volume_type_extra_specs_get(context, volume_type_id):
|
||||
|
||||
@require_context
|
||||
def volume_type_extra_specs_delete(context, volume_type_id, key):
|
||||
session = get_session()
|
||||
volume_type_extra_specs_get_item(context, volume_type_id, key, session)
|
||||
_volume_type_extra_specs_query(context, volume_type_id).\
|
||||
filter_by(key=key).\
|
||||
update({'deleted': True,
|
||||
|
@ -21,6 +21,7 @@ from lxml import etree
|
||||
import webob
|
||||
|
||||
from cinder.api.contrib import types_extra_specs
|
||||
from cinder import exception
|
||||
from cinder.openstack.common.notifier import api as notifier_api
|
||||
from cinder.openstack.common.notifier import test_notifier
|
||||
from cinder import test
|
||||
@ -45,6 +46,10 @@ def delete_volume_type_extra_specs(context, volume_type_id, key):
|
||||
pass
|
||||
|
||||
|
||||
def delete_volume_type_extra_specs_not_found(context, volume_type_id, key):
|
||||
raise exception.VolumeTypeExtraSpecsNotFound("Not Found")
|
||||
|
||||
|
||||
def stub_volume_type_extra_specs():
|
||||
specs = {
|
||||
"key1": "value1",
|
||||
@ -121,6 +126,14 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
|
||||
self.controller.delete(req, 1, 'key5')
|
||||
self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
|
||||
|
||||
def test_delete_not_found(self):
|
||||
self.stubs.Set(cinder.db, 'volume_type_extra_specs_delete',
|
||||
delete_volume_type_extra_specs_not_found)
|
||||
|
||||
req = fakes.HTTPRequest.blank(self.api_path + '/key6')
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete,
|
||||
req, 1, 'key6')
|
||||
|
||||
def test_create(self):
|
||||
self.stubs.Set(cinder.db,
|
||||
'volume_type_extra_specs_update_or_create',
|
||||
|
Loading…
Reference in New Issue
Block a user