]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Disallow transferring volume in consistency group
authorAccela Zhao <accelazh@gmail.com>
Sat, 16 Jan 2016 06:43:29 +0000 (22:43 -0800)
committerAccela Zhao <accelazh@gmail.com>
Sat, 16 Jan 2016 06:52:21 +0000 (22:52 -0800)
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

cinder/tests/unit/test_volume_transfer.py
cinder/transfer/api.py

index af378bfcb3f9045979b5a843df31b8fc2d14fc91..4345b50395a11f2349663d22ed882f3f2e2a99dc 100644 (file)
@@ -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')
index 1bac7352734a9662147ae23dfd6e31b83661b4b9..e59635c9696d197d1d61cb1b110ada4827aec1b5 100644 (file)
@@ -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")