From 2c5112e5938e3d567504748f923fb198fad3117e Mon Sep 17 00:00:00 2001 From: Michael Still Date: Wed, 28 Mar 2012 21:13:26 +1100 Subject: Touch in use image files when they're checked. It was intended that FLAGS.remove_unused_resized_minimum_age_seconds would indicate the number of seconds a base file was unused before it was removed. This however isn't true at the moment. Because instances are COW mostly, this will be the time since the resize occurred, which is normally instantly true once the image isn't being used any more. This small patch corrects that by touching the base image during check cycles which find it in use. Resolves bug 967845. Change-Id: I75bf06cf758c9a2d7a8bde5ce67c789d7e299174 --- nova/tests/test_imagecache.py | 4 ++++ nova/virt/libvirt/imagecache.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/nova/tests/test_imagecache.py b/nova/tests/test_imagecache.py index 09f5f9fce..6c356ea9a 100644 --- a/nova/tests/test_imagecache.py +++ b/nova/tests/test_imagecache.py @@ -562,6 +562,10 @@ class ImageCacheManagerTestCase(test.TestCase): self.stubs.Set(os.path, 'exists', lambda x: exists(x)) + # We need to stub utime as well + orig_utime = os.utime + self.stubs.Set(os, 'utime', lambda x, y: None) + # Fake up some instances in the instances directory orig_listdir = os.listdir diff --git a/nova/virt/libvirt/imagecache.py b/nova/virt/libvirt/imagecache.py index 07bab5cd3..f3750ae0d 100644 --- a/nova/virt/libvirt/imagecache.py +++ b/nova/virt/libvirt/imagecache.py @@ -352,6 +352,8 @@ class ImageCacheManager(object): LOG.debug(_('%(id)s (%(base_file)s): image is in use'), {'id': img_id, 'base_file': base_file}) + if os.path.exists(base_file): + os.utime(base_file, None) def verify_base_images(self, context): """Verify that base images are in a reasonable state.""" -- cgit