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
This commit is contained in:
Accela Zhao 2016-01-15 22:43:29 -08:00
parent 05b07b1c41
commit 780c6003a1
2 changed files with 22 additions and 0 deletions

View 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')

View 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")