'Test function of create_volume_from_image.
Test cases call this function to create a volume from image, caller
can choose whether to fake out copy_image_to_volume and clone_image,
after calling this, test cases should check status of the volume.'

@mock.patch('cinder.image.image_utils.TemporaryImages.fetch')
@mock.patch('cinder.volume.flows.manager.create_volume.CreateVolumeFromSpecTask._clone_image_volume')
def _create_volume_from_image(self, mock_clone_image_volume, mock_fetch_img, fakeout_copy_image_to_volume=False, fakeout_clone_image=False, clone_image_volume=False):

    def fake_local_path(volume):
        return dst_path
    def fake_copy_image_to_volume(context, volume, image_service, image_id):
        pass
    def fake_fetch_to_raw(ctx, image_service, image_id, path, blocksize, size=None, throttle=None):
        pass
    def fake_clone_image(ctx, volume_ref, image_location, image_meta, image_service):
        return ({'provider_location': None}, True)
    (dst_fd, dst_path) = tempfile.mkstemp()
    os.close(dst_fd)
    self.mock_object(self.volume.driver, 'local_path', fake_local_path)
    if fakeout_clone_image:
        self.mock_object(self.volume.driver, 'clone_image', fake_clone_image)
    self.mock_object(image_utils, 'fetch_to_raw', fake_fetch_to_raw)
    if fakeout_copy_image_to_volume:
        self.mock_object(self.volume.driver, 'copy_image_to_volume', fake_copy_image_to_volume)
    mock_clone_image_volume.return_value = ({}, clone_image_volume)
    mock_fetch_img.return_value = mock.MagicMock(spec=tests_utils.get_file_spec())
    image_id = 'c905cedb-7281-47e4-8a62-f26bc5fc4c77'
    volume = tests_utils.create_volume(self.context, **self.volume_params)
    try:
        request_spec = {'volume_properties': self.volume_params, 'image_id': image_id, 'image_size': 1}
        self.volume.create_volume(self.context, volume, request_spec)
    finally:
        os.unlink(dst_path)
        volume = objects.Volume.get_by_id(self.context, volume.id)
    return volume
