Update libvirt imagecache to support resizes.

Updates the libvirt image cache manage so that it accounts
for instances which are resizing.

Also fixes an issue where an exception was thrown when
the image cache manager ran while instances were resizing.
This is because instances which are resizing may have files in the
Nova instances directory which are missing backing files.

Fixes LP Bug #1006616.

Change-Id: I724c6855b68eca24a00893fd96b26b1443f9da5c
This commit is contained in:
Dan Prince
2012-06-06 17:35:18 -04:00
parent fcc19aaf5c
commit b034686900

View File

@@ -26,6 +26,7 @@ import time
from nova import test
from nova.compute import task_states
from nova import db
from nova import flags
from nova import log
@@ -148,15 +149,18 @@ class ImageCacheManagerTestCase(test.TestCase):
lambda x: [{'image_ref': '1',
'host': FLAGS.host,
'name': 'inst-1',
'uuid': '123'},
'uuid': '123',
'task_state': ''},
{'image_ref': '2',
'host': FLAGS.host,
'name': 'inst-2',
'uuid': '456'},
'uuid': '456',
'task_state': ''},
{'image_ref': '2',
'host': 'remotehost',
'name': 'inst-3',
'uuid': '789'}])
'uuid': '789',
'task_state': ''}])
image_cache_manager = imagecache.ImageCacheManager()
@@ -173,6 +177,26 @@ class ImageCacheManagerTestCase(test.TestCase):
self.assertEqual(image_cache_manager.image_popularity['1'], 1)
self.assertEqual(image_cache_manager.image_popularity['2'], 2)
def test_list_resizing_instances(self):
self.stubs.Set(db, 'instance_get_all',
lambda x: [{'image_ref': '1',
'host': FLAGS.host,
'name': 'inst-1',
'uuid': '123',
'task_state': task_states.RESIZE_VERIFY}])
image_cache_manager = imagecache.ImageCacheManager()
image_cache_manager._list_running_instances(None)
self.assertEqual(len(image_cache_manager.used_images), 1)
self.assertTrue(image_cache_manager.used_images['1'] ==
(1, 0, ['inst-1']))
self.assertTrue(image_cache_manager.instance_names ==
set(['inst-1', 'inst-1_resize']))
self.assertEqual(len(image_cache_manager.image_popularity), 1)
self.assertEqual(image_cache_manager.image_popularity['1'], 1)
def test_list_backing_images_small(self):
self.stubs.Set(os, 'listdir',
lambda x: ['_base', 'instance-00000001',
@@ -741,11 +765,13 @@ class ImageCacheManagerTestCase(test.TestCase):
lambda x: [{'image_ref': '1',
'host': FLAGS.host,
'name': 'instance-1',
'uuid': '123'},
'uuid': '123',
'task_state': ''},
{'image_ref': '1',
'host': FLAGS.host,
'name': 'instance-2',
'uuid': '456'}])
'uuid': '456',
'task_state': ''}])
image_cache_manager = imagecache.ImageCacheManager()
@@ -838,11 +864,13 @@ class ImageCacheManagerTestCase(test.TestCase):
lambda x: [{'image_ref': '1',
'host': FLAGS.host,
'name': 'instance-1',
'uuid': '123'},
'uuid': '123',
'task_state': ''},
{'image_ref': '1',
'host': FLAGS.host,
'name': 'instance-2',
'uuid': '456'}])
'uuid': '456',
'task_state': ''}])
def touch(filename):
f = open(filename, 'w')