'Test function of _copy_volume_data.'

@mock.patch.object(utils, 'brick_get_connector_properties')
@mock.patch.object(cinder.volume.manager.VolumeManager, '_attach_volume')
@mock.patch.object(cinder.volume.manager.VolumeManager, '_detach_volume')
@mock.patch.object(volutils, 'copy_volume')
@mock.patch.object(volume_rpcapi.VolumeAPI, 'get_capabilities')
@mock.patch.object(cinder.volume.volume_types, 'volume_types_encryption_changed')
@ddt.data(False, True)
def test_copy_volume_data_mgr(self, encryption_changed, mock_encryption_changed, mock_get_capabilities, mock_copy, mock_detach, mock_attach, mock_get_connector):

    src_vol = tests_utils.create_volume(self.context, size=1, host=CONF.host)
    dest_vol = tests_utils.create_volume(self.context, size=1, host=CONF.host)
    mock_get_connector.return_value = {}
    mock_encryption_changed.return_value = encryption_changed
    self.volume.driver._throttle = mock.MagicMock()
    attach_expected = [mock.call(self.context, dest_vol, {}, remote=False, attach_encryptor=encryption_changed), mock.call(self.context, src_vol, {}, remote=False, attach_encryptor=encryption_changed)]
    detach_expected = [mock.call(self.context, {'device': {'path': 'bar'}}, dest_vol, {}, force=True, remote=False, attach_encryptor=encryption_changed), mock.call(self.context, {'device': {'path': 'foo'}}, src_vol, {}, force=True, remote=False, attach_encryptor=encryption_changed)]
    attach_volume_returns = [{'device': {'path': 'bar'}}, {'device': {'path': 'foo'}}]
    mock_attach.side_effect = attach_volume_returns
    mock_get_capabilities.return_value = {}
    self.volume._copy_volume_data(self.context, src_vol, dest_vol)
    self.assertEqual(attach_expected, mock_attach.mock_calls)
    mock_copy.assert_called_with('foo', 'bar', 1024, '1M', sparse=False)
    self.assertEqual(detach_expected, mock_detach.mock_calls)
    mock_attach.reset_mock()
    mock_detach.reset_mock()
    mock_attach.side_effect = attach_volume_returns
    mock_get_capabilities.return_value = {'sparse_copy_volume': True}
    self.volume._copy_volume_data(self.context, src_vol, dest_vol)
    self.assertEqual(attach_expected, mock_attach.mock_calls)
    mock_copy.assert_called_with('foo', 'bar', 1024, '1M', sparse=True)
    self.assertEqual(detach_expected, mock_detach.mock_calls)
    db.volume_destroy(self.context, src_vol['id'])
    db.volume_destroy(self.context, dest_vol['id'])
