Merge "Glance cache to not prune newly cached images"
This commit is contained in:
commit
b9cbb4c8e9
@ -321,8 +321,8 @@ class Driver(base.Driver):
|
|||||||
|
|
||||||
db.execute("""INSERT INTO cached_images
|
db.execute("""INSERT INTO cached_images
|
||||||
(image_id, last_accessed, last_modified, hits, size)
|
(image_id, last_accessed, last_modified, hits, size)
|
||||||
VALUES (?, 0, ?, 0, ?)""",
|
VALUES (?, ?, ?, 0, ?)""",
|
||||||
(image_id, now, filesize))
|
(image_id, now, now, filesize))
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
def rollback(e):
|
def rollback(e):
|
||||||
|
@ -174,16 +174,15 @@ class ImageCacheTestCase(object):
|
|||||||
"""
|
"""
|
||||||
self.assertEqual(0, self.cache.get_cache_size())
|
self.assertEqual(0, self.cache.get_cache_size())
|
||||||
|
|
||||||
# Add a bunch of images to the cache. The max cache
|
# Add a bunch of images to the cache. The max cache size for the cache
|
||||||
# size for the cache is set to 5KB and each image is
|
# is set to 5KB and each image is 1K. We use 11 images in this test.
|
||||||
# 1K. We add 10 images to the cache and then we'll
|
# The first 10 are added to and retrieved from cache in the same order.
|
||||||
# prune it. We should see only 5 images left after
|
# Then, the 11th image is added to cache but not retrieved before we
|
||||||
# pruning, and the images that are least recently accessed
|
# prune. We should see only 5 images left after pruning, and the
|
||||||
# should be the ones pruned...
|
# images that are least recently accessed should be the ones pruned...
|
||||||
for x in range(10):
|
for x in range(10):
|
||||||
FIXTURE_FILE = six.StringIO(FIXTURE_DATA)
|
FIXTURE_FILE = six.StringIO(FIXTURE_DATA)
|
||||||
self.assertTrue(self.cache.cache_image_file(x,
|
self.assertTrue(self.cache.cache_image_file(x, FIXTURE_FILE))
|
||||||
FIXTURE_FILE))
|
|
||||||
|
|
||||||
self.assertEqual(10 * units.Ki, self.cache.get_cache_size())
|
self.assertEqual(10 * units.Ki, self.cache.get_cache_size())
|
||||||
|
|
||||||
@ -194,18 +193,28 @@ class ImageCacheTestCase(object):
|
|||||||
for chunk in cache_file:
|
for chunk in cache_file:
|
||||||
buff.write(chunk)
|
buff.write(chunk)
|
||||||
|
|
||||||
|
# Add a new image to cache.
|
||||||
|
# This is specifically to test the bug: 1438564
|
||||||
|
FIXTURE_FILE = six.StringIO(FIXTURE_DATA)
|
||||||
|
self.assertTrue(self.cache.cache_image_file(99, FIXTURE_FILE))
|
||||||
|
|
||||||
self.cache.prune()
|
self.cache.prune()
|
||||||
|
|
||||||
self.assertEqual(5 * units.Ki, self.cache.get_cache_size())
|
self.assertEqual(5 * units.Ki, self.cache.get_cache_size())
|
||||||
|
|
||||||
for x in range(0, 5):
|
# Ensure images 0, 1, 2, 3, 4 & 5 are not cached anymore
|
||||||
|
for x in range(0, 6):
|
||||||
self.assertFalse(self.cache.is_cached(x),
|
self.assertFalse(self.cache.is_cached(x),
|
||||||
"Image %s was cached!" % x)
|
"Image %s was cached!" % x)
|
||||||
|
|
||||||
for x in range(5, 10):
|
# Ensure images 6, 7, 8 and 9 are still cached
|
||||||
|
for x in range(6, 10):
|
||||||
self.assertTrue(self.cache.is_cached(x),
|
self.assertTrue(self.cache.is_cached(x),
|
||||||
"Image %s was not cached!" % x)
|
"Image %s was not cached!" % x)
|
||||||
|
|
||||||
|
# Ensure the newly added image, 99, is still cached
|
||||||
|
self.assertTrue(self.cache.is_cached(99), "Image 99 was not cached!")
|
||||||
|
|
||||||
@skip_if_disabled
|
@skip_if_disabled
|
||||||
def test_prune_to_zero(self):
|
def test_prune_to_zero(self):
|
||||||
"""Test that an image_cache_max_size of 0 doesn't kill the pruner
|
"""Test that an image_cache_max_size of 0 doesn't kill the pruner
|
||||||
|
Loading…
Reference in New Issue
Block a user