Move flags in libvirt's imagecache to the libvirt group
This change continues moving libvirt specific flags into a libvirt specific configuration group. Progresses blueprint libvirt-opts-group. DocImpact: the following flags move into the libvirt group: image_info_filename_pattern, remove_unused_base_images, remove_unused_kernels, remove_unused_resized_minimum_age_seconds, remove_unused_original_minimum_age_seconds, checksum_base_images, checksum_interval_seconds. Change-Id: Iea681c7db7efc9da0525ef8e01b4900ca71f10cf
This commit is contained in:
parent
26e861c816
commit
5102ae18cb
|
@ -1969,38 +1969,6 @@
|
|||
#libvirt_images_rbd_ceph_conf=
|
||||
|
||||
|
||||
#
|
||||
# Options defined in nova.virt.libvirt.imagecache
|
||||
#
|
||||
|
||||
# Allows image information files to be stored in non-standard
|
||||
# locations (string value)
|
||||
#image_info_filename_pattern=$instances_path/$image_cache_subdirectory_name/%(image)s.info
|
||||
|
||||
# Should unused base images be removed? (boolean value)
|
||||
#remove_unused_base_images=true
|
||||
|
||||
# Should unused kernel images be removed? This is only safe to
|
||||
# enable if all compute nodes have been updated to support
|
||||
# this option. This will enabled by default in future.
|
||||
# (boolean value)
|
||||
#remove_unused_kernels=false
|
||||
|
||||
# Unused resized base images younger than this will not be
|
||||
# removed (integer value)
|
||||
#remove_unused_resized_minimum_age_seconds=3600
|
||||
|
||||
# Unused unresized base images younger than this will not be
|
||||
# removed (integer value)
|
||||
#remove_unused_original_minimum_age_seconds=86400
|
||||
|
||||
# Write a checksum for files in _base to disk (boolean value)
|
||||
#checksum_base_images=false
|
||||
|
||||
# How frequently to checksum base images (integer value)
|
||||
#checksum_interval_seconds=3600
|
||||
|
||||
|
||||
#
|
||||
# Options defined in nova.virt.libvirt.utils
|
||||
#
|
||||
|
@ -2674,6 +2642,38 @@
|
|||
#vcpu_pin_set=<None>
|
||||
|
||||
|
||||
#
|
||||
# Options defined in nova.virt.libvirt.imagecache
|
||||
#
|
||||
|
||||
# Allows image information files to be stored in non-standard
|
||||
# locations (string value)
|
||||
#image_info_filename_pattern=$instances_path/$image_cache_subdirectory_name/%(image)s.info
|
||||
|
||||
# Should unused base images be removed? (boolean value)
|
||||
#remove_unused_base_images=true
|
||||
|
||||
# Should unused kernel images be removed? This is only safe to
|
||||
# enable if all compute nodes have been updated to support
|
||||
# this option. This will be enabled by default in future.
|
||||
# (boolean value)
|
||||
#remove_unused_kernels=false
|
||||
|
||||
# Unused resized base images younger than this will not be
|
||||
# removed (integer value)
|
||||
#remove_unused_resized_minimum_age_seconds=3600
|
||||
|
||||
# Unused unresized base images younger than this will not be
|
||||
# removed (integer value)
|
||||
#remove_unused_original_minimum_age_seconds=86400
|
||||
|
||||
# Write a checksum for files in _base to disk (boolean value)
|
||||
#checksum_base_images=false
|
||||
|
||||
# How frequently to checksum base images (integer value)
|
||||
#checksum_interval_seconds=3600
|
||||
|
||||
|
||||
[baremetal]
|
||||
|
||||
#
|
||||
|
|
|
@ -71,7 +71,8 @@ class ImageCacheManagerTestCase(test.NoDBTestCase):
|
|||
with utils.tempdir() as tmpdir:
|
||||
self.flags(instances_path=tmpdir)
|
||||
self.flags(image_info_filename_pattern=('$instances_path/'
|
||||
'%(image)s.info'))
|
||||
'%(image)s.info'),
|
||||
group='libvirt')
|
||||
|
||||
csum_input = '{"sha1": "fdghkfhkgjjksfdgjksjkghsdf"}\n'
|
||||
fname = os.path.join(tmpdir, 'aaa')
|
||||
|
@ -89,7 +90,8 @@ class ImageCacheManagerTestCase(test.NoDBTestCase):
|
|||
with utils.tempdir() as tmpdir:
|
||||
self.flags(instances_path=tmpdir)
|
||||
self.flags(image_info_filename_pattern=('$instances_path/'
|
||||
'%(image)s.info'))
|
||||
'%(image)s.info'),
|
||||
group='libvirt')
|
||||
|
||||
fname = os.path.join(tmpdir, 'aaa')
|
||||
old_fname = fname + '.sha1'
|
||||
|
@ -366,7 +368,8 @@ class ImageCacheManagerTestCase(test.NoDBTestCase):
|
|||
with utils.tempdir() as tmpdir:
|
||||
self.flags(instances_path=tmpdir)
|
||||
self.flags(image_info_filename_pattern=('$instances_path/'
|
||||
'%(image)s.info'))
|
||||
'%(image)s.info'),
|
||||
group='libvirt')
|
||||
fname = os.path.join(tmpdir, 'aaa')
|
||||
|
||||
base_file = open(fname, 'w')
|
||||
|
@ -428,7 +431,8 @@ class ImageCacheManagerTestCase(test.NoDBTestCase):
|
|||
with utils.tempdir() as tmpdir:
|
||||
self.flags(instances_path=tmpdir)
|
||||
self.flags(image_info_filename_pattern=('$instances_path/'
|
||||
'%(image)s.info'))
|
||||
'%(image)s.info'),
|
||||
group='libvirt')
|
||||
|
||||
fname = os.path.join(tmpdir, 'aaa')
|
||||
image_cache_manager = imagecache.ImageCacheManager()
|
||||
|
@ -439,7 +443,8 @@ class ImageCacheManagerTestCase(test.NoDBTestCase):
|
|||
with utils.tempdir() as tmpdir:
|
||||
self.flags(instances_path=tmpdir)
|
||||
self.flags(image_info_filename_pattern=('$instances_path/'
|
||||
'%(image)s.info'))
|
||||
'%(image)s.info'),
|
||||
group='libvirt')
|
||||
|
||||
fname = os.path.join(tmpdir, 'aaa')
|
||||
|
||||
|
@ -521,7 +526,8 @@ class ImageCacheManagerTestCase(test.NoDBTestCase):
|
|||
with utils.tempdir() as tmpdir:
|
||||
self.flags(instances_path=tmpdir)
|
||||
self.flags(image_info_filename_pattern=('$instances_path/'
|
||||
'%(image)s.info'))
|
||||
'%(image)s.info'),
|
||||
group='libvirt')
|
||||
|
||||
fname = os.path.join(tmpdir, 'aaa')
|
||||
|
||||
|
@ -535,7 +541,7 @@ class ImageCacheManagerTestCase(test.NoDBTestCase):
|
|||
self.assertEqual(image_cache_manager.corrupt_base_files, [])
|
||||
|
||||
def test_handle_base_image_checksum_fails(self):
|
||||
self.flags(checksum_base_images=True)
|
||||
self.flags(checksum_base_images=True, group='libvirt')
|
||||
self.stubs.Set(virtutils, 'chown', lambda x, y: None)
|
||||
|
||||
img = '123'
|
||||
|
@ -565,8 +571,9 @@ class ImageCacheManagerTestCase(test.NoDBTestCase):
|
|||
hashed_42 = '92cfceb39d57d914ed8b14d0e37643de0797ae56'
|
||||
|
||||
self.flags(instances_path='/instance_path',
|
||||
image_cache_subdirectory_name='_base',
|
||||
remove_unused_base_images=True)
|
||||
image_cache_subdirectory_name='_base')
|
||||
self.flags(remove_unused_base_images=True,
|
||||
group='libvirt')
|
||||
|
||||
base_file_list = ['00000001',
|
||||
'ephemeral_0_20_None',
|
||||
|
@ -738,7 +745,8 @@ class ImageCacheManagerTestCase(test.NoDBTestCase):
|
|||
|
||||
self.flags(instances_path='/tmp/no/such/dir/name/please')
|
||||
self.flags(image_info_filename_pattern=('$instances_path/_base/'
|
||||
'%(image)s.info'))
|
||||
'%(image)s.info'),
|
||||
group='libvirt')
|
||||
base_filename = os.path.join(CONF.instances_path, '_base', hashed)
|
||||
|
||||
is_valid_info_file = imagecache.is_valid_info_file
|
||||
|
@ -753,8 +761,9 @@ class ImageCacheManagerTestCase(test.NoDBTestCase):
|
|||
with utils.tempdir() as tmpdir:
|
||||
self.flags(instances_path=tmpdir)
|
||||
self.flags(image_info_filename_pattern=('$instances_path/'
|
||||
'%(image)s.info'))
|
||||
self.flags(remove_unused_base_images=True)
|
||||
'%(image)s.info'),
|
||||
remove_unused_base_images=True,
|
||||
group='libvirt')
|
||||
|
||||
# Ensure there is a base directory
|
||||
os.mkdir(os.path.join(tmpdir, '_base'))
|
||||
|
@ -828,7 +837,7 @@ class VerifyChecksumTestCase(test.NoDBTestCase):
|
|||
def setUp(self):
|
||||
super(VerifyChecksumTestCase, self).setUp()
|
||||
self.img = {'container_format': 'ami', 'id': '42'}
|
||||
self.flags(checksum_base_images=True)
|
||||
self.flags(checksum_base_images=True, group='libvirt')
|
||||
|
||||
def _make_checksum(self, tmpdir):
|
||||
testdata = ('OpenStack Software delivers a massively scalable cloud '
|
||||
|
@ -857,7 +866,8 @@ class VerifyChecksumTestCase(test.NoDBTestCase):
|
|||
def _check_body(self, tmpdir, info_attr):
|
||||
self.flags(instances_path=tmpdir)
|
||||
self.flags(image_info_filename_pattern=('$instances_path/'
|
||||
'%(image)s.info'))
|
||||
'%(image)s.info'),
|
||||
group='libvirt')
|
||||
fname, info_fname, testdata = self._make_checksum(tmpdir)
|
||||
self._write_file(info_fname, info_attr, testdata)
|
||||
image_cache_manager = imagecache.ImageCacheManager()
|
||||
|
@ -870,7 +880,7 @@ class VerifyChecksumTestCase(test.NoDBTestCase):
|
|||
self.assertTrue(res)
|
||||
|
||||
def test_verify_checksum_disabled(self):
|
||||
self.flags(checksum_base_images=False)
|
||||
self.flags(checksum_base_images=False, group='libvirt')
|
||||
with utils.tempdir() as tmpdir:
|
||||
image_cache_manager, fname = self._check_body(tmpdir, "csum valid")
|
||||
res = image_cache_manager._verify_checksum(self.img, fname)
|
||||
|
@ -913,7 +923,8 @@ class VerifyChecksumTestCase(test.NoDBTestCase):
|
|||
with utils.tempdir() as tmpdir:
|
||||
self.flags(instances_path=tmpdir)
|
||||
self.flags(image_info_filename_pattern=('$instances_path/'
|
||||
'%(image)s.info'))
|
||||
'%(image)s.info'),
|
||||
group='libvirt')
|
||||
fname, info_fname, testdata = self._make_checksum(tmpdir)
|
||||
|
||||
image_cache_manager = imagecache.ImageCacheManager()
|
||||
|
|
|
@ -46,34 +46,41 @@ imagecache_opts = [
|
|||
default='$instances_path/$image_cache_subdirectory_name/'
|
||||
'%(image)s.info',
|
||||
help='Allows image information files to be stored in '
|
||||
'non-standard locations'),
|
||||
'non-standard locations',
|
||||
deprecated_group='DEFAULT'),
|
||||
cfg.BoolOpt('remove_unused_base_images',
|
||||
default=True,
|
||||
help='Should unused base images be removed?'),
|
||||
help='Should unused base images be removed?',
|
||||
deprecated_group='DEFAULT'),
|
||||
cfg.BoolOpt('remove_unused_kernels',
|
||||
default=False,
|
||||
help='Should unused kernel images be removed? This is only '
|
||||
'safe to enable if all compute nodes have been updated '
|
||||
'to support this option. This will enabled by default '
|
||||
'in future.'),
|
||||
'to support this option. This will be enabled by default '
|
||||
'in future.',
|
||||
deprecated_group='DEFAULT'),
|
||||
cfg.IntOpt('remove_unused_resized_minimum_age_seconds',
|
||||
default=3600,
|
||||
help='Unused resized base images younger than this will not be '
|
||||
'removed'),
|
||||
'removed',
|
||||
deprecated_group='DEFAULT'),
|
||||
cfg.IntOpt('remove_unused_original_minimum_age_seconds',
|
||||
default=(24 * 3600),
|
||||
help='Unused unresized base images younger than this will not '
|
||||
'be removed'),
|
||||
'be removed',
|
||||
deprecated_group='DEFAULT'),
|
||||
cfg.BoolOpt('checksum_base_images',
|
||||
default=False,
|
||||
help='Write a checksum for files in _base to disk'),
|
||||
help='Write a checksum for files in _base to disk',
|
||||
deprecated_group='DEFAULT'),
|
||||
cfg.IntOpt('checksum_interval_seconds',
|
||||
default=3600,
|
||||
help='How frequently to checksum base images'),
|
||||
help='How frequently to checksum base images',
|
||||
deprecated_group='DEFAULT'),
|
||||
]
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.register_opts(imagecache_opts)
|
||||
CONF.register_opts(imagecache_opts, 'libvirt')
|
||||
CONF.import_opt('host', 'nova.netconf')
|
||||
CONF.import_opt('instances_path', 'nova.compute.manager')
|
||||
CONF.import_opt('image_cache_subdirectory_name', 'nova.compute.manager')
|
||||
|
@ -96,7 +103,8 @@ def get_cache_fname(images, key):
|
|||
assume this.
|
||||
"""
|
||||
image_id = str(images[key])
|
||||
if not CONF.remove_unused_kernels and key in ['kernel_id', 'ramdisk_id']:
|
||||
if ((not CONF.libvirt.remove_unused_kernels and
|
||||
key in ['kernel_id', 'ramdisk_id'])):
|
||||
return image_id
|
||||
else:
|
||||
return hashlib.sha1(image_id).hexdigest()
|
||||
|
@ -110,7 +118,7 @@ def get_info_filename(base_path):
|
|||
"""
|
||||
|
||||
base_file = os.path.basename(base_path)
|
||||
return (CONF.image_info_filename_pattern
|
||||
return (CONF.libvirt.image_info_filename_pattern
|
||||
% {'image': base_file})
|
||||
|
||||
|
||||
|
@ -118,7 +126,7 @@ def is_valid_info_file(path):
|
|||
"""Test if a given path matches the pattern for info files."""
|
||||
|
||||
digest_size = hashlib.sha1().digestsize * 2
|
||||
regexp = (CONF.image_info_filename_pattern
|
||||
regexp = (CONF.libvirt.image_info_filename_pattern
|
||||
% {'image': ('([0-9a-f]{%(digest_size)d}|'
|
||||
'[0-9a-f]{%(digest_size)d}_sm|'
|
||||
'[0-9a-f]{%(digest_size)d}_[0-9]+)'
|
||||
|
@ -394,7 +402,7 @@ class ImageCacheManager(object):
|
|||
handle manually when it occurs.
|
||||
"""
|
||||
|
||||
if not CONF.checksum_base_images:
|
||||
if not CONF.libvirt.checksum_base_images:
|
||||
return None
|
||||
|
||||
lock_name = 'hash-%s' % os.path.split(base_file)[-1]
|
||||
|
@ -411,7 +419,7 @@ class ImageCacheManager(object):
|
|||
# shared storage), then we don't need to checksum again.
|
||||
if (stored_timestamp and
|
||||
time.time() - stored_timestamp <
|
||||
CONF.checksum_interval_seconds):
|
||||
CONF.libvirt.checksum_interval_seconds):
|
||||
return True
|
||||
|
||||
# NOTE(mikal): If there is no timestamp, then the checksum was
|
||||
|
@ -441,7 +449,7 @@ class ImageCacheManager(object):
|
|||
# NOTE(mikal): If the checksum file is missing, then we should
|
||||
# create one. We don't create checksums when we download images
|
||||
# from glance because that would delay VM startup.
|
||||
if CONF.checksum_base_images and create_if_missing:
|
||||
if CONF.libvirt.checksum_base_images and create_if_missing:
|
||||
LOG.info(_('%(id)s (%(base_file)s): generating checksum'),
|
||||
{'id': img_id,
|
||||
'base_file': base_file})
|
||||
|
@ -464,9 +472,9 @@ class ImageCacheManager(object):
|
|||
mtime = os.path.getmtime(base_file)
|
||||
age = time.time() - mtime
|
||||
|
||||
maxage = CONF.remove_unused_resized_minimum_age_seconds
|
||||
maxage = CONF.libvirt.remove_unused_resized_minimum_age_seconds
|
||||
if base_file in self.originals:
|
||||
maxage = CONF.remove_unused_original_minimum_age_seconds
|
||||
maxage = CONF.libvirt.remove_unused_original_minimum_age_seconds
|
||||
|
||||
if age < maxage:
|
||||
LOG.info(_('Base file too young to remove: %s'),
|
||||
|
@ -614,7 +622,7 @@ class ImageCacheManager(object):
|
|||
LOG.info(_('Removable base files: %s'),
|
||||
' '.join(self.removable_base_files))
|
||||
|
||||
if CONF.remove_unused_base_images:
|
||||
if CONF.libvirt.remove_unused_base_images:
|
||||
for base_file in self.removable_base_files:
|
||||
self._remove_base_file(base_file)
|
||||
|
||||
|
|
Loading…
Reference in New Issue