Пример #1
0
    def fetch_image_into_cache(self, image_id):
        ctx = context.RequestContext(is_admin=True, show_deleted=True)

        try:
            image_repo = self.gateway.get_repo(ctx)
            image = image_repo.get(image_id)
        except exception.NotFound:
            LOG.warning(_LW("Image '%s' not found"), image_id)
            return False

        if image.status != 'active':
            LOG.warn(_LW("Image '%s' is not active. Not caching.") % image_id)
            return False

        for loc in image.locations:
            if CONF.enabled_backends:
                image_data, image_size = glance_store.get(loc['url'],
                                                          None,
                                                          context=ctx)
            else:
                image_data, image_size = glance_store.get_from_backend(
                    loc['url'], context=ctx)

            LOG.debug("Caching image '%s'", image_id)
            cache_tee_iter = self.cache.cache_tee_iter(image_id, image_data,
                                                       image.checksum)
            # Image is tee'd into cache and checksum verified
            # as we iterate
            list(cache_tee_iter)
            return True
Пример #2
0
    def test_import_to_fs(self):
        import_fs = import_flow._ImportToFS(self.task.task_id,
                                            self.task_type,
                                            self.task_repo,
                                            'http://example.com/image.qcow2')

        with mock.patch.object(script_utils, 'get_image_data_iter') as dmock:
            content = b"test"
            dmock.return_value = [content]

            with mock.patch.object(putils, 'trycmd') as tmock:
                tmock.return_value = (json.dumps({
                    'format': 'qcow2',
                }), None)

                image_id = UUID1
                path = import_fs.execute(image_id)
                reader, size = glance_store.get_from_backend(path)
                self.assertEqual(4, size)
                self.assertEqual(content, b"".join(reader))

                image_path = os.path.join(self.work_dir, image_id)
                tmp_image_path = os.path.join(self.work_dir, image_path)
                self.assertTrue(os.path.exists(tmp_image_path))
                self._assert_qemu_process_limits(tmock)
Пример #3
0
    def test_import_to_fs(self):
        import_fs = import_flow._ImportToFS(self.task.task_id,
                                            self.task_type,
                                            self.task_repo,
                                            'http://example.com/image.qcow2')

        with mock.patch.object(script_utils, 'get_image_data_iter') as dmock:
            content = b"test"
            dmock.return_value = [content]

            with mock.patch.object(putils, 'trycmd') as tmock:
                tmock.return_value = (json.dumps({
                    'format': 'qcow2',
                }), None)

                image_id = UUID1
                path = import_fs.execute(image_id)
                reader, size = glance_store.get_from_backend(path)
                self.assertEqual(4, size)
                self.assertEqual(content, b"".join(reader))

                image_path = os.path.join(self.work_dir, image_id)
                tmp_image_path = os.path.join(self.work_dir, image_path)
                self.assertTrue(os.path.exists(tmp_image_path))
                self._assert_qemu_process_limits(tmock)
Пример #4
0
    def test_import_to_fs(self):
        import_fs = import_flow._ImportToFS(self.task.task_id, self.task_type,
                                            self.task_repo,
                                            'http://example.com/image.qcow2')

        with mock.patch.object(script_utils, 'get_image_data_iter') as dmock:
            dmock.return_value = "test"

            image_id = UUID1
            path = import_fs.execute(image_id)
            reader, size = glance_store.get_from_backend(path)
            self.assertEqual(4, size)
            self.assertEqual(dmock.return_value, "".join(reader))

            image_path = os.path.join(self.work_dir, image_id)
            tmp_image_path = os.path.join(self.work_dir, image_path)
            self.assertTrue(os.path.exists(tmp_image_path))
Пример #5
0
    def test_import_to_fs(self):
        import_fs = import_flow._ImportToFS(
            self.task.task_id, self.task_type, self.task_repo, "http://example.com/image.qcow2"
        )

        with mock.patch.object(script_utils, "get_image_data_iter") as dmock:
            dmock.return_value = "test"

            image_id = UUID1
            path = import_fs.execute(image_id)
            reader, size = glance_store.get_from_backend(path)
            self.assertEqual(4, size)
            self.assertEqual(dmock.return_value, "".join(reader))

            image_path = os.path.join(self.work_dir, image_id)
            tmp_image_path = os.path.join(self.work_dir, image_path)
            self.assertTrue(os.path.exists(tmp_image_path))
Пример #6
0
    def fetch_image_into_cache(self, image_id):
        ctx = context.RequestContext(is_admin=True, show_deleted=True)

        try:
            image_meta = registry.get_image_metadata(ctx, image_id)
            if image_meta['status'] != 'active':
                LOG.warn(_LW("Image '%s' is not active. Not caching.") %
                         image_id)
                return False

        except exception.NotFound:
            LOG.warn(_LW("No metadata found for image '%s'") % image_id)
            return False

        location = image_meta['location']
        image_data, image_size = glance_store.get_from_backend(location,
                                                               context=ctx)
        LOG.debug("Caching image '%s'", image_id)
        cache_tee_iter = self.cache.cache_tee_iter(image_id, image_data,
                                                   image_meta['checksum'])
        # Image is tee'd into cache and checksum verified
        # as we iterate
        list(cache_tee_iter)
        return True
Пример #7
0
    def fetch_image_into_cache(self, image_id):
        ctx = context.RequestContext(is_admin=True, show_deleted=True)

        try:
            image_meta = registry.get_image_metadata(ctx, image_id)
            if image_meta['status'] != 'active':
                LOG.warn(
                    _LW("Image '%s' is not active. Not caching.") % image_id)
                return False

        except exception.NotFound:
            LOG.warn(_LW("No metadata found for image '%s'") % image_id)
            return False

        location = image_meta['location']
        image_data, image_size = glance_store.get_from_backend(location,
                                                               context=ctx)
        LOG.debug("Caching image '%s'", image_id)
        cache_tee_iter = self.cache.cache_tee_iter(image_id, image_data,
                                                   image_meta['checksum'])
        # Image is tee'd into cache and checksum verified
        # as we iterate
        list(cache_tee_iter)
        return True