From: Accela Zhao Date: Sat, 16 Jan 2016 06:43:29 +0000 (-0800) Subject: Disallow transferring volume in consistency group X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=780c6003a1f70e3ccaa46ffe35cfa268fb22732d;p=openstack-build%2Fcinder-build.git Disallow transferring volume in consistency group Currently, transferring a volume in a consistency group would success. But consistency group is not designed to span multiple tenants. If the accepted volume is attached to an instance, and the original user try to delete the CG, it would fail and could not find the attachment. This patch fixes it by adding a check in transfer API accept. It raises InvalidVolume exception if the volume being transferred belongs to a consistency group. Change-Id: I597d32a301a1ded87ba711de6168995b5f62c4d8 Closes-bug: #1499584 --- diff --git a/cinder/tests/unit/test_volume_transfer.py b/cinder/tests/unit/test_volume_transfer.py index af378bfcb..4345b5039 100644 --- a/cinder/tests/unit/test_volume_transfer.py +++ b/cinder/tests/unit/test_volume_transfer.py @@ -116,6 +116,22 @@ class VolumeTransferTestCase(test.TestCase): mock_notify.assert_has_calls(calls) self.assertEqual(3, mock_notify.call_count) + @mock.patch('cinder.volume.utils.notify_about_volume_usage') + def test_transfer_accept_volume_in_consistencygroup(self, mock_notify): + svc = self.start_service('volume', host='test_host') + self.addCleanup(svc.stop) + tx_api = transfer_api.API() + consistencygroup = utils.create_consistencygroup(self.ctxt) + volume = utils.create_volume(self.ctxt, + updated_at=self.updated_at, + consistencygroup_id= + consistencygroup.id) + transfer = tx_api.create(self.ctxt, volume.id, 'Description') + + self.assertRaises(exception.InvalidVolume, + tx_api.accept, + self.ctxt, transfer['id'], transfer['auth_key']) + @mock.patch.object(QUOTAS, "reserve") @mock.patch.object(QUOTAS, "add_volume_type_opts") @mock.patch('cinder.volume.utils.notify_about_volume_usage') diff --git a/cinder/transfer/api.py b/cinder/transfer/api.py index 1bac73527..e59635c96 100644 --- a/cinder/transfer/api.py +++ b/cinder/transfer/api.py @@ -161,6 +161,12 @@ class API(base.Base): volume_id = transfer['volume_id'] vol_ref = self.db.volume_get(context.elevated(), volume_id) + if vol_ref['consistencygroup_id']: + msg = _("Volume %s must not be part of a consistency " + "group.") % vol_ref['id'] + LOG.error(msg) + raise exception.InvalidVolume(reason=msg) + volume_utils.notify_about_volume_usage(context, vol_ref, "transfer.accept.start")