From 0a8546c7d142acd2a1e68de7a36b71a3680ab0e1 Mon Sep 17 00:00:00 2001 From: Michael Still Date: Sat, 18 Feb 2012 14:22:02 +1100 Subject: Improve unit test coverage per bug/934566. bug/934566 identified an error which should have been caught by more complete unit test coverage. This review extends unit test coverage to include handle_base_image and is one of a series I will be sending. Change-Id: I287fc50ea6a92239f11a107f65da84d3ff0c8b3b --- nova/virt/libvirt/imagecache.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/libvirt/imagecache.py b/nova/virt/libvirt/imagecache.py index 6226e8d4e..bd4da528f 100644 --- a/nova/virt/libvirt/imagecache.py +++ b/nova/virt/libvirt/imagecache.py @@ -107,6 +107,10 @@ class ImageCacheManager(object): self.image_popularity = {} self.instance_names = {} + self.removable_base_files = [] + self.active_base_files = [] + self.corrupt_base_files = [] + def _store_image(self, base_dir, ent, original=False): """Store a base image for later examination.""" entpath = os.path.join(base_dir, ent) @@ -290,7 +294,6 @@ class ImageCacheManager(object): def _handle_base_image(self, img, base_file): """Handle the checks for a single base image.""" - # TODO(mikal): Write a unit test for this method image_bad = False image_in_use = False @@ -301,7 +304,11 @@ class ImageCacheManager(object): if base_file in self.unexplained_images: self.unexplained_images.remove(base_file) - self._verify_checksum(img, base_file) + + if (base_file and os.path.exists(base_file) + and os.path.isfile(base_file)): + # _verify_checksum returns True if the checksum is ok. + image_bad = not self._verify_checksum(img, base_file) instances = [] if str(img['id']) in self.used_images: @@ -332,8 +339,7 @@ class ImageCacheManager(object): else: LOG.debug(_('%(container_format)s-%(id)s (%(base_file)s): ' - 'in: on other nodes (%(remote)d on other ' - 'nodes)'), + 'in use on (%(remote)d on other nodes)'), {'container_format': img['container_format'], 'id': img['id'], 'base_file': base_file, -- cgit