unused images are always deleted (add to in-tree hper-v code)

This is to apply changes applied to openstack/computer-hyperv
to the in-tree hyper-v code.

Change-Id: Ib89c2e407bea5168f2eebb12cfb2d50e4566ff7a
Closes-Bug: #1773342
This commit is contained in:
Hesam Chobanlou 2019-01-06 19:55:24 -05:00
parent a8e992b105
commit 716d17e054
3 changed files with 21 additions and 4 deletions

View File

@ -15,6 +15,7 @@
import os
import ddt
import fixtures
import mock
from oslo_config import cfg
@ -32,6 +33,7 @@ from nova.virt.hyperv import imagecache
CONF = cfg.CONF
@ddt.ddt
class ImageCacheTestCase(test_base.HyperVBaseTestCase):
"""Unit tests for the Hyper-V ImageCache class."""
@ -184,7 +186,10 @@ class ImageCacheTestCase(test_base.HyperVBaseTestCase):
self.imagecache._vhdutils.get_vhd_info.assert_called_once_with(
expected_vhd_path)
def test_age_and_verify_cached_images(self):
@ddt.data(True, False)
def test_age_and_verify_cached_images(self, remove_unused_base_images):
self.flags(remove_unused_base_images=remove_unused_base_images)
fake_images = [mock.sentinel.FAKE_IMG1, mock.sentinel.FAKE_IMG2]
fake_used_images = [mock.sentinel.FAKE_IMG1]
@ -201,8 +206,12 @@ class ImageCacheTestCase(test_base.HyperVBaseTestCase):
self.imagecache._update_image_timestamp.assert_called_once_with(
mock.sentinel.FAKE_IMG1)
self.imagecache._remove_if_old_image.assert_called_once_with(
mock.sentinel.FAKE_IMG2)
if remove_unused_base_images:
self.imagecache._remove_if_old_image.assert_called_once_with(
mock.sentinel.FAKE_IMG2)
else:
self.imagecache._remove_if_old_image.assert_not_called()
@mock.patch.object(imagecache.os, 'utime')
@mock.patch.object(imagecache.ImageCache, '_get_image_backing_files')

View File

@ -171,7 +171,7 @@ class ImageCache(imagecache.ImageCacheManager):
# change the timestamp on the image so as to reflect the last
# time it was used
self._update_image_timestamp(img)
else:
elif CONF.remove_unused_base_images:
self._remove_if_old_image(img)
def _update_image_timestamp(self, image):

View File

@ -0,0 +1,8 @@
---
fixes:
- |
Fixes `bug 1773342`_ where the Hyper-v driver always deleted unused images
ignoring ``remove_unused_images`` config option. This change will now allow
deployers to disable the auto-removal of old images.
.. _bug 1773342: https://bugs.launchpad.net/nova/+bug/1773342