diff --git a/cinder/tests/unit/test_volume_transfer.py b/cinder/tests/unit/test_volume_transfer.py index af378bfcb3f..4345b50395a 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 1bac7352734..e59635c9696 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")