def setUp(self): super(TestImagePrefetcher, self).setUp() self.cache_dir = self.useFixture(fixtures.TempDir()).path self.config(image_cache_dir=self.cache_dir, image_cache_driver='xattr', image_cache_max_size=5 * units.Ki) self.prefetcher = prefetcher.Prefetcher()
def run_cache_prefetcher(): if not CONF.paste_deploy.flavor == 'keystone+cachemanagement': LOG.debug('Cache not enabled, skipping prefetching images in cache!!!') return # NOTE(abhishekk): Importing the prefetcher just in time to avoid # import loop during initialization from glance.image_cache import prefetcher # noqa cache_prefetcher = prefetcher.Prefetcher() cache_images(cache_prefetcher)
def main(): try: config.parse_cache_args() log.setup('glance') glance.store.create_stores() glance.store.verify_default_store() app = prefetcher.Prefetcher() app.run() except RuntimeError as e: sys.exit("ERROR: %s" % e)
def main(): try: config.parse_cache_args() logging.setup(CONF, 'glance') glance_store.register_opts(config.CONF) glance_store.create_stores(config.CONF) glance_store.verify_default_store() app = prefetcher.Prefetcher() app.run() except RuntimeError as e: sys.exit("ERROR: %s" % e)
def __init__(self, threads=1000, initialize_glance_store=False, initialize_prefetcher=False): os.umask(0o27) # ensure files are created with the correct privileges self._logger = logging.getLogger("eventlet.wsgi.server") self.threads = threads self.children = set() self.stale_children = set() self.running = True # NOTE(abhishek): Allows us to only re-initialize glance_store when # the API's configuration reloads. self.initialize_glance_store = initialize_glance_store self.initialize_prefetcher = initialize_prefetcher if self.initialize_prefetcher: self.prefetcher = prefetcher.Prefetcher()
def _create_upload_and_cache(self, cache_image=False, expected_code=200): image_id = self._create_and_upload() # Queue image for caching path = '/v2/queued_images/%s' % image_id response = self.api_put(path) self.assertEqual(expected_code, response.status_code) if cache_image: # NOTE(abhishekk): Here we are not running periodic job which # caches queued images as precaching is not part of this # patch, so to test all caching operations we are using this # way to cache images for us cache_prefetcher = prefetcher.Prefetcher() cache_prefetcher.run() return image_id
def _test_prefetcher(self, mock_get_db): self.config(enabled_backends={'cheap': 'file'}) store.register_store_opts(CONF) self.config(filesystem_store_datadir='/tmp', group='cheap') store.create_multi_stores(CONF) tempf = tempfile.NamedTemporaryFile() tempf.write(b'foo') db = unit_test_utils.FakeDB(initialize=False) mock_get_db.return_value = db ctx = context.RequestContext(is_admin=True, roles=['admin']) gateway = glance_gateway.Gateway() image_factory = gateway.get_image_factory(ctx, authorization_layer=False) image_repo = gateway.get_repo(ctx, authorization_layer=False) fetcher = prefetcher.Prefetcher() # Create an image with no values set and queue it image = image_factory.new_image() image_repo.add(image) fetcher.cache.queue_image(image.image_id) # Image is not active, so it should fail to cache, but remain queued self.assertFalse(fetcher.run()) self.assertFalse(fetcher.cache.is_cached(image.image_id)) self.assertTrue(fetcher.cache.is_queued(image.image_id)) # Set the disk/container format and give it a location image.disk_format = 'raw' image.container_format = 'bare' image.status = 'active' loc = {'url': 'file://%s' % tempf.name, 'metadata': {'store': 'cheap'}} with mock.patch('glance.location._check_image_location'): # FIXME(danms): Why do I have to do this? image.locations = [loc] image_repo.save(image) # Image is now active and has a location, so it should cache self.assertTrue(fetcher.run()) self.assertTrue(fetcher.cache.is_cached(image.image_id)) self.assertFalse(fetcher.cache.is_queued(image.image_id))