From: ling-yun Date: Mon, 20 Jan 2014 10:48:43 +0000 (+0800) Subject: Delete volume transfer in volume_destroy function X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=19d8040d61d453ec3916d74c628189ca0b54ac59;p=openstack-build%2Fcinder-build.git Delete volume transfer in volume_destroy function 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 --- diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 792514dbc..e882124df 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -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 diff --git a/cinder/tests/test_volume_transfer.py b/cinder/tests/test_volume_transfer.py index c794a49eb..55713bd71 100644 --- a/cinder/tests/test_volume_transfer.py +++ b/cinder/tests/test_volume_transfer.py @@ -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'])