From: Cian O'Driscoll Date: Thu, 30 May 2013 13:00:54 +0000 (+0000) Subject: Return 404 from delete of extra spec if not found X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=de84fd7b1539893bf48ed8b36db1bfdeaf05d7a9;p=openstack-build%2Fcinder-build.git 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 --- diff --git a/cinder/api/contrib/types_extra_specs.py b/cinder/api/contrib/types_extra_specs.py index 7377f5245..c95e9f22b 100644 --- a/cinder/api/contrib/types_extra_specs.py +++ b/cinder/api/contrib/types_extra_specs.py @@ -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', diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 8c4fc2504..e0188378f 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -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, diff --git a/cinder/tests/api/contrib/test_types_extra_specs.py b/cinder/tests/api/contrib/test_types_extra_specs.py index 7b5b46931..36ff9f6d1 100644 --- a/cinder/tests/api/contrib/test_types_extra_specs.py +++ b/cinder/tests/api/contrib/test_types_extra_specs.py @@ -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',