]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Return 404 from delete of extra spec if not found
authorCian O'Driscoll <cian@hp.com>
Thu, 30 May 2013 13:00:54 +0000 (13:00 +0000)
committerCian O'Driscoll <cian@hp.com>
Thu, 30 May 2013 13:14:59 +0000 (13:14 +0000)
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

cinder/api/contrib/types_extra_specs.py
cinder/db/sqlalchemy/api.py
cinder/tests/api/contrib/test_types_extra_specs.py

index 7377f5245d71f5608194c88d2f952f5845d306ec..c95e9f22b0c355842cc6160e929647272ffb8764 100644 (file)
@@ -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',
index 8c4fc25044d5c9c165e7d33298e176c96f0cd07f..e0188378f1071255a4864f3c10af75dc76c94930 100644 (file)
@@ -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,
index 7b5b46931ef7cbe212dc5aca2ae83e16378c443d..36ff9f6d17f7d41fa6aa83bb3ea1bd35635453ad 100644 (file)
@@ -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',