Allow disabling TFTP image cache

We document that this can be disabled by setting the
[pxe]tftp_master_path config  to "<None>", but don't
actually support it in code. oslo.config doesn't actually
translate that value to the Python None as we expect.

Allow disabling the cache by setting the config to the empty
string, as in "tftp_master_path=". This doesn't make sense as
a directory to use as a cache anyway, so it shouldn't break anyone.

Change-Id: Icc7d08ae47e0e450a612c922ae3d665c56880262
Story: 2004608
Task: 28506
This commit is contained in:
Ruby Loo 2018-12-13 21:27:41 +00:00
parent 87b25d5447
commit 4c987aa51b
4 changed files with 36 additions and 2 deletions

View File

@ -925,8 +925,9 @@ def prepare_instance_pxe_config(task, image_info,
@image_cache.cleanup(priority=25)
class TFTPImageCache(image_cache.ImageCache):
def __init__(self):
master_path = CONF.pxe.tftp_master_path or None
super(TFTPImageCache, self).__init__(
CONF.pxe.tftp_master_path,
master_path,
# MiB -> B
cache_size=CONF.pxe.image_cache_size * 1024 * 1024,
# min -> sec

View File

@ -76,7 +76,7 @@ opts = [
default='/tftpboot/master_images',
help=_('On ironic-conductor node, directory where master TFTP '
'images are stored on disk. '
'Setting to <None> disables image caching.')),
'Setting to the empty string disables image caching.')),
cfg.IntOpt('dir_permission',
help=_("The permission that will be applied to the TFTP "
"folders upon creation. This should be set to the "

View File

@ -1740,3 +1740,29 @@ class CleanUpPxeEnvTestCase(db_base.DbTestCase):
mock_pxe_clean.assert_called_once_with(task, ipxe_enabled=False)
mock_unlink.assert_any_call('deploy_kernel')
mock_cache.return_value.clean_up.assert_called_once_with()
class TFTPImageCacheTestCase(db_base.DbTestCase):
@mock.patch.object(fileutils, 'ensure_tree')
def test_with_master_path(self, mock_ensure_tree):
self.config(tftp_master_path='/fake/path', group='pxe')
self.config(image_cache_size=500, group='pxe')
self.config(image_cache_ttl=30, group='pxe')
cache = pxe_utils.TFTPImageCache()
mock_ensure_tree.assert_called_once_with('/fake/path')
self.assertEqual(500 * 1024 * 1024, cache._cache_size)
self.assertEqual(30 * 60, cache._cache_ttl)
@mock.patch.object(fileutils, 'ensure_tree')
def test_without_master_path(self, mock_ensure_tree):
self.config(tftp_master_path='', group='pxe')
self.config(image_cache_size=500, group='pxe')
self.config(image_cache_ttl=30, group='pxe')
cache = pxe_utils.TFTPImageCache()
mock_ensure_tree.assert_not_called()
self.assertEqual(500 * 1024 * 1024, cache._cache_size)
self.assertEqual(30 * 60, cache._cache_ttl)

View File

@ -0,0 +1,7 @@
---
fixes:
- |
Fixes an issue where the master TFTP image cache could not be disbled.
The configuration option ``[pxe]/tftp_master_path`` may now be set to
the empty string to disable the cache. For more information, see
story `2004608 <https://storyboard.openstack.org/#!/story/2004608>`_.