Skip to content

Commit

Permalink
Return 404 from delete of extra spec if not found
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cianodriscoll committed May 30, 2013
1 parent 301d72c commit de84fd7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cinder/api/contrib/types_extra_specs.py
Expand Up @@ -134,7 +134,12 @@ def delete(self, req, type_id, id):
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',
Expand Down
2 changes: 2 additions & 0 deletions cinder/db/sqlalchemy/api.py
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions cinder/tests/api/contrib/test_types_extra_specs.py
Expand Up @@ -21,6 +21,7 @@
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
Expand All @@ -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",
Expand Down Expand Up @@ -121,6 +126,14 @@ def test_delete(self):
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',
Expand Down

0 comments on commit de84fd7

Please sign in to comment.