'Upload a qcow2 image file which has to be converted to raw first.'

def test_copy_volume_to_image_qcow2_image(self):

    drv = self._driver
    volume = self._simple_volume()
    volume_path = ('%s/%s' % (self.TEST_MNT_POINT, volume['name']))
    image_meta = {'id': '10958016-e196-42e3-9e7f-5d8927ae3099'}
    with mock.patch.object(drv, 'get_active_image_from_info') as mock_get_active_image_from_info:
        with mock.patch.object(drv, '_local_volume_dir') as mock_local_volume_dir:
            with mock.patch.object(image_utils, 'qemu_img_info') as mock_qemu_img_info:
                with mock.patch.object(image_utils, 'convert_image') as mock_convert_image:
                    with mock.patch.object(image_utils, 'upload_volume') as mock_upload_volume:
                        with mock.patch.object(image_utils, 'create_temporary_file') as mock_create_temporary_file:
                            mock_get_active_image_from_info.return_value = volume['name']
                            mock_local_volume_dir.return_value = self.TEST_MNT_POINT
                            mock_create_temporary_file.return_value = self.TEST_TMP_FILE
                            qemu_img_output = ('image:    %s\n                                                file    format:    qcow2\n                                                virtual    size:    1.0G    (1073741824    bytes)\n                                                disk    size:    173K\n                                                ' % volume['name'])
                            img_info = imageutils.QemuImgInfo(qemu_img_output)
                            mock_qemu_img_info.return_value = img_info
                            upload_path = self.TEST_TMP_FILE
                            drv.copy_volume_to_image(mock.ANY, volume, mock.ANY, image_meta)
                            mock_get_active_image_from_info.assert_called_once_with(volume)
                            mock_local_volume_dir.assert_called_with(volume)
                            mock_qemu_img_info.assert_called_once_with(volume_path, run_as_root=False)
                            mock_convert_image.assert_called_once_with(volume_path, upload_path, 'raw', run_as_root=False)
                            mock_upload_volume.assert_called_once_with(mock.ANY, mock.ANY, mock.ANY, upload_path, run_as_root=False)
                            self.assertTrue(mock_create_temporary_file.called)
