示例#1
0
def _fetch(context, image_href, path, force_raw=False):
    """Fetch image and convert to raw format if needed."""
    path_tmp = "%s.part" % path
    images.fetch(context, image_href, path_tmp, force_raw=False)
    # Notes(yjiang5): If glance can provide the virtual size information,
    # then we can firstly clean cache and then invoke images.fetch().
    if force_raw:
        if images.force_raw_will_convert(image_href, path_tmp):
            required_space = images.converted_size(path_tmp, estimate=False)
            directory = os.path.dirname(path_tmp)
            try:
                _clean_up_caches(directory, required_space)
            except exception.InsufficientDiskSpace:

                # try again with an estimated raw size instead of the full size
                required_space = images.converted_size(path_tmp, estimate=True)
                try:
                    _clean_up_caches(directory, required_space)
                except exception.InsufficientDiskSpace:
                    LOG.warning(
                        'Not enough space for estimated image size. '
                        'Consider lowering '
                        '[DEFAULT]raw_image_growth_factor=%s',
                        CONF.raw_image_growth_factor)
                    raise

        images.image_to_raw(image_href, path, path_tmp)
    else:
        os.rename(path_tmp, path)
示例#2
0
def _fetch_to_raw(context, image_href, path, image_service=None):
    """Fetch image and convert to raw format if needed."""
    path_tmp = "%s.part" % path
    images.fetch(context, image_href, path_tmp, image_service)
    required_space = images.converted_size(path_tmp)
    directory = os.path.dirname(path_tmp)
    _clean_up_caches(directory, required_space)
    images.image_to_raw(image_href, path, path_tmp)
def _fetch_to_raw(context, image_href, path, image_service=None):
    """Fetch image and convert to raw format if needed."""
    path_tmp = "%s.part" % path
    images.fetch(context, image_href, path_tmp, image_service)
    required_space = images.converted_size(path_tmp)
    directory = os.path.dirname(path_tmp)
    _clean_up_caches(directory, required_space)
    images.image_to_raw(image_href, path, path_tmp)
示例#4
0
    def test_image_to_raw_already_raw_format(self, qemu_img_info_mock, rename_mock):
        info = self.FakeImgInfo()
        info.file_format = "raw"
        info.backing_file = None
        qemu_img_info_mock.return_value = info

        images.image_to_raw("image_href", "path", "path_tmp")

        qemu_img_info_mock.assert_called_once_with("path_tmp")
        rename_mock.assert_called_once_with("path_tmp", "path")
示例#5
0
    def test_image_to_raw_already_raw_format(self, qemu_img_info_mock,
                                             rename_mock):
        info = self.FakeImgInfo()
        info.file_format = 'raw'
        info.backing_file = None
        qemu_img_info_mock.return_value = info

        images.image_to_raw('image_href', 'path', 'path_tmp')

        qemu_img_info_mock.assert_called_once_with('path_tmp')
        rename_mock.assert_called_once_with('path_tmp', 'path')
示例#6
0
    def test_image_to_raw_already_raw_format(self, qemu_img_info_mock,
                                             rename_mock):
        info = self.FakeImgInfo()
        info.file_format = 'raw'
        info.backing_file = None
        qemu_img_info_mock.return_value = info

        images.image_to_raw('image_href', 'path', 'path_tmp')

        qemu_img_info_mock.assert_called_once_with('path_tmp')
        rename_mock.assert_called_once_with('path_tmp', 'path')
示例#7
0
def _fetch(context, image_href, path, force_raw=False):
    """Fetch image and convert to raw format if needed."""
    path_tmp = "%s.part" % path
    images.fetch(context, image_href, path_tmp, force_raw=False)
    # Notes(yjiang5): If glance can provide the virtual size information,
    # then we can firstly clean cache and then invoke images.fetch().
    if force_raw:
        required_space = images.converted_size(path_tmp)
        directory = os.path.dirname(path_tmp)
        _clean_up_caches(directory, required_space)
        images.image_to_raw(image_href, path, path_tmp)
    else:
        os.rename(path_tmp, path)
示例#8
0
def _fetch(context, image_href, path, force_raw=False):
    """Fetch image and convert to raw format if needed."""
    path_tmp = "%s.part" % path
    images.fetch(context, image_href, path_tmp, force_raw=False)
    # Notes(yjiang5): If glance can provide the virtual size information,
    # then we can firstly clean cache and then invoke images.fetch().
    if force_raw:
        required_space = images.converted_size(path_tmp)
        directory = os.path.dirname(path_tmp)
        _clean_up_caches(directory, required_space)
        images.image_to_raw(image_href, path, path_tmp)
    else:
        os.rename(path_tmp, path)
示例#9
0
    def test_image_to_raw(self, qemu_img_info_mock, convert_image_mock, unlink_mock, rename_mock):
        CONF.set_override("force_raw_images", True)
        info = self.FakeImgInfo()
        info.file_format = "fmt"
        info.backing_file = None
        qemu_img_info_mock.return_value = info

        def convert_side_effect(source, dest, out_format):
            info.file_format = "raw"

        convert_image_mock.side_effect = convert_side_effect

        images.image_to_raw("image_href", "path", "path_tmp")

        qemu_img_info_mock.assert_has_calls([mock.call("path_tmp"), mock.call("path.converted")])
        convert_image_mock.assert_called_once_with("path_tmp", "path.converted", "raw")
        unlink_mock.assert_called_once_with("path_tmp")
        rename_mock.assert_called_once_with("path.converted", "path")
示例#10
0
    def test_image_to_raw(self, qemu_img_info_mock, convert_image_mock,
                          unlink_mock, rename_mock):
        CONF.set_override('force_raw_images', True)
        info = self.FakeImgInfo()
        info.file_format = 'fmt'
        info.backing_file = None
        qemu_img_info_mock.return_value = info

        def convert_side_effect(source, dest, out_format):
            info.file_format = 'raw'
        convert_image_mock.side_effect = convert_side_effect

        images.image_to_raw('image_href', 'path', 'path_tmp')

        qemu_img_info_mock.assert_has_calls([mock.call('path_tmp'),
                                             mock.call('path.converted')])
        convert_image_mock.assert_called_once_with('path_tmp',
                                                   'path.converted', 'raw')
        unlink_mock.assert_called_once_with('path_tmp')
        rename_mock.assert_called_once_with('path.converted', 'path')