diff --git a/ironic/common/pxe_utils.py b/ironic/common/pxe_utils.py index ad34f43056..ecc573504c 100644 --- a/ironic/common/pxe_utils.py +++ b/ironic/common/pxe_utils.py @@ -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 diff --git a/ironic/conf/pxe.py b/ironic/conf/pxe.py index f16aa94e04..49882ebfe6 100644 --- a/ironic/conf/pxe.py +++ b/ironic/conf/pxe.py @@ -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 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 " diff --git a/ironic/tests/unit/common/test_pxe_utils.py b/ironic/tests/unit/common/test_pxe_utils.py index 5d99f06105..87f64c2630 100644 --- a/ironic/tests/unit/common/test_pxe_utils.py +++ b/ironic/tests/unit/common/test_pxe_utils.py @@ -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) diff --git a/releasenotes/notes/fix-tftp-master-path-config-77face94f5db9af7.yaml b/releasenotes/notes/fix-tftp-master-path-config-77face94f5db9af7.yaml new file mode 100644 index 0000000000..0769ceddcf --- /dev/null +++ b/releasenotes/notes/fix-tftp-master-path-config-77face94f5db9af7.yaml @@ -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 `_.