]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Delete volume transfer in volume_destroy function
authorling-yun <zengyunling@huawei.com>
Mon, 20 Jan 2014 10:48:43 +0000 (18:48 +0800)
committerling-yun <zengyunling@huawei.com>
Fri, 24 Jan 2014 12:52:53 +0000 (20:52 +0800)
Doing volume force delete operation on volume-A will change volume-A's
status to 'deleted', so all related data about volume-A should be deleted.
Now current version's volume_destroy function doesn't delete related data
of volume transfer. If there is volume transfer about volume-A, first do
force delete operation on volume A, and thus the volume-A's transfer data
would be residual. So remove the related data of volume transfer in
volume_destroy function.

Change-Id: Id80a6e0cc061fccb02af60706244be043abdd72d
Closes-Bug: #1270785

cinder/db/sqlalchemy/api.py
cinder/tests/test_volume_transfer.py

index 792514dbce95672185a0c24da0b2f3ef54d27ab7..e882124df8a0f827ee0bcbf9a53bc66694b345ba 100644 (file)
@@ -1098,6 +1098,11 @@ def volume_destroy(context, volume_id):
             update({'deleted': True,
                     'deleted_at': now,
                     'updated_at': literal_column('updated_at')})
+        model_query(context, models.Transfer, session=session).\
+            filter_by(volume_id=volume_id).\
+            update({'deleted': True,
+                    'deleted_at': now,
+                    'updated_at': literal_column('updated_at')})
 
 
 @require_admin_context
index c794a49eb8d44c43c3327b342b6955bdce7b0111..55713bd71d69554a0c4fa0cf954c0aa1d42c4ed0 100644 (file)
@@ -118,3 +118,20 @@ class VolumeTransferTestCase(test.TestCase):
 
         ts = tx_api.get_all(nctxt)
         self.assertEqual(len(ts), 0, 'Unexpected transfers listed.')
+
+    def test_delete_transfer_with_deleted_volume(self):
+        #create a volume
+        volume = utils.create_volume(self.ctxt, id='1',
+                                     updated_at=self.updated_at)
+        #create a transfer
+        tx_api = transfer_api.API()
+        transfer = tx_api.create(self.ctxt, volume['id'], 'Description')
+        t = tx_api.get(self.ctxt, transfer['id'])
+        self.assertEqual(t['id'], transfer['id'], 'Unexpected transfer id')
+        #force delete volume
+        db.volume_destroy(context.get_admin_context(), volume['id'])
+        #Make sure transfer has been deleted.
+        self.assertRaises(exception.TransferNotFound,
+                          tx_api.get,
+                          self.ctxt,
+                          transfer['id'])