]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Return 404 if volume type encryption is not found
authorRakesh H S <rh-s@hp.com>
Tue, 23 Jun 2015 14:06:24 +0000 (19:36 +0530)
committerRakesh H S <rh-s@hp.com>
Wed, 1 Jul 2015 02:51:18 +0000 (08:21 +0530)
This commit adds a check for volume type encryption existence before
marking it as deleted. If it isn't present call returns 404 error
code so that it can be handled properly in services that use the
REST API (like Heat).

APIImpact
HTTP 404 will be returned if volume type encryption is not found.

Change-Id: I3107b8df0121de1ebe9e812ef7a842d09500e030
Closes-Bug: #1468751

cinder/api/contrib/volume_type_encryption.py
cinder/db/sqlalchemy/api.py
cinder/tests/unit/api/contrib/test_volume_type_encryption.py
cinder/tests/unit/test_db_api.py

index 26dd9d1a5060e62606227c72be8fd4be697b46af..288169a61e033146910388980e1b0a654527bb87 100644 (file)
@@ -188,7 +188,10 @@ class VolumeTypeEncryptionController(wsgi.Controller):
             expl = _('Cannot delete encryption specs. Volume type in use.')
             raise webob.exc.HTTPBadRequest(explanation=expl)
         else:
-            db.volume_type_encryption_delete(context, type_id)
+            try:
+                db.volume_type_encryption_delete(context, type_id)
+            except exception.VolumeTypeEncryptionNotFound as ex:
+                raise webob.exc.HTTPNotFound(explanation=ex.msg)
 
         return webob.Response(status_int=202)
 
index 7dc908013b286d9724a354474c2bcc914f059493..7f2dd33b3fdb477f4b4b152a598b3dc48fc86335 100644 (file)
@@ -2946,6 +2946,9 @@ def volume_type_encryption_delete(context, volume_type_id):
     with session.begin():
         encryption = volume_type_encryption_get(context, volume_type_id,
                                                 session)
+        if not encryption:
+            raise exception.VolumeTypeEncryptionNotFound(
+                type_id=volume_type_id)
         encryption.update({'deleted': True,
                            'deleted_at': timeutils.utcnow(),
                            'updated_at': literal_column('updated_at')})
index 036a93b9d8042bbc772e8aa30f4a85fe3925b8e2..dd29802d0e7bcb1531b52c00aab592ad4cfa5d05 100644 (file)
@@ -475,6 +475,27 @@ class VolumeTypeEncryptionTest(test.TestCase):
 
         db.volume_type_destroy(context.get_admin_context(), volume_type['id'])
 
+    def test_delete_with_no_encryption(self):
+        volume_type = self._default_volume_type
+        # create an volume type
+        db.volume_type_create(context.get_admin_context(), volume_type)
+
+        # without creating encryption type, try to delete
+        # and check if 404 is raised.
+        res = self._get_response(volume_type, req_method='DELETE',
+                                 req_headers='application/json',
+                                 url='/v2/fake/types/%s/encryption/provider')
+        self.assertEqual(404, res.status_code)
+        expected = {
+            "itemNotFound": {
+                "message": "Volume type encryption for type "
+                           "fake_type_id does not exist.",
+                "code": 404
+            }
+        }
+        self.assertEqual(expected, json.loads(res.body))
+        db.volume_type_destroy(context.get_admin_context(), volume_type['id'])
+
     def test_update_item(self):
         volume_type = self._default_volume_type
 
index 1688759cda3e66f30d92baa8f9d49821faa0ced7..6acd4ab79ce3e452fb993096cb71181570130fa0 100644 (file)
@@ -1207,7 +1207,7 @@ class DBAPIEncryptionTestCase(BaseTest):
             self._assertEqualObjects(encryption, encryption_get,
                                      self._ignored_keys)
 
-    def test_volume_type_update_with_no_create(self):
+    def test_volume_type_encryption_update_with_no_create(self):
         self.assertRaises(exception.VolumeTypeEncryptionNotFound,
                           db.volume_type_encryption_update,
                           self.ctxt,
@@ -1234,6 +1234,12 @@ class DBAPIEncryptionTestCase(BaseTest):
                                           encryption['volume_type_id'])
         self.assertIsNone(encryption_get)
 
+    def test_volume_type_encryption_delete_no_create(self):
+        self.assertRaises(exception.VolumeTypeEncryptionNotFound,
+                          db.volume_type_encryption_delete,
+                          self.ctxt,
+                          'fake_no_create_type')
+
     def test_volume_encryption_get(self):
         # normal volume -- metadata should be None
         volume = db.volume_create(self.ctxt, {})