From 31e579fd3ffc87d0917fd2f461eaf6272029222f Mon Sep 17 00:00:00 2001 From: Michael Still Date: Sat, 18 Feb 2012 16:16:24 +1100 Subject: Improve unit test coverage per bug/934566. Add unit test coverage for the last untested method in imagecache.py. This brings the coverage for this module to 100%. Change-Id: I9d4c0a521842bdbb72f4ae5b54839c15ab49f38e --- nova/virt/libvirt/imagecache.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/libvirt/imagecache.py b/nova/virt/libvirt/imagecache.py index bd4da528f..22a4d1e8b 100644 --- a/nova/virt/libvirt/imagecache.py +++ b/nova/virt/libvirt/imagecache.py @@ -99,17 +99,20 @@ def write_stored_checksum(target): class ImageCacheManager(object): def __init__(self): - self.unexplained_images = [] - self.originals = [] + self._reset_state() + + def _reset_state(self): + """Reset state variables used for each pass.""" - # These are populated by a call to _list_running_instances() self.used_images = {} self.image_popularity = {} self.instance_names = {} - self.removable_base_files = [] self.active_base_files = [] self.corrupt_base_files = [] + self.originals = [] + self.removable_base_files = [] + self.unexplained_images = [] def _store_image(self, base_dir, ent, original=False): """Store a base image for later examination.""" @@ -297,10 +300,10 @@ class ImageCacheManager(object): image_bad = False image_in_use = False - LOG.debug(_('%(container_format)s-%(id)s (%(base_file)s): checking'), - {'container_format': img['container_format'], - 'id': img['id'], - 'base_file': base_file}) + LOG.info(_('%(container_format)s-%(id)s (%(base_file)s): checking'), + {'container_format': img['container_format'], + 'id': img['id'], + 'base_file': base_file}) if base_file in self.unexplained_images: self.unexplained_images.remove(base_file) @@ -377,12 +380,7 @@ class ImageCacheManager(object): # CoW is disabled, the resize occurs as part of the copy from the # cache to the instance directory. Files ending in _sm are no longer # created, but may remain from previous versions. - - self.unexplained_images = [] - self.active_base_files = [] - self.corrupt_base_files = [] - self.removable_base_files = [] - self.originals = [] + self._reset_state() base_dir = os.path.join(FLAGS.instances_path, '_base') if not os.path.exists(base_dir): -- cgit