summaryrefslogtreecommitdiff
path: root/ironic/tests/unit/common/test_pxe_utils.py
diff options
context:
space:
mode:
authorSteve Baker <sbaker@redhat.com>2021-11-30 11:25:43 +1300
committerSteve Baker <sbaker@redhat.com>2021-12-10 15:44:50 +1300
commit3f76724dfb49df9501359e9b97acb1fc9c7689c8 (patch)
treea8ada7cc369e2287ace3b69e0aacc71458a4f592 /ironic/tests/unit/common/test_pxe_utils.py
parent45e8adc1df26f2b940603b2f85d54c0ffcfdfa66 (diff)
downloadironic-3f76724dfb49df9501359e9b97acb1fc9c7689c8.tar.gz
Write initial grub config on startup
This change removes the documentation to copy master_grub_cfg.txt to /tftpboot/grub/grub.cfg and instead writes it on conductor startup. This grub config is a simple redirect config requested by grub network boot. "master" has been renamed to "initial" as a more accurate label of its function. New configuration option [pxe]initial_grub_template allows the deployer to specify a different initial grub template. Change-Id: I71191dd399a6c49607f91d69b5b1673799a38624
Diffstat (limited to 'ironic/tests/unit/common/test_pxe_utils.py')
-rw-r--r--ironic/tests/unit/common/test_pxe_utils.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/ironic/tests/unit/common/test_pxe_utils.py b/ironic/tests/unit/common/test_pxe_utils.py
index fbfe7f05b..ef1e5d1f3 100644
--- a/ironic/tests/unit/common/test_pxe_utils.py
+++ b/ironic/tests/unit/common/test_pxe_utils.py
@@ -1035,6 +1035,53 @@ class TestPXEUtils(db_base.DbTestCase):
next(actual))
self.assertEqual('/tftpboot-path/' + address + '.conf', next(actual))
+ @mock.patch.object(os, 'makedirs', autospec=True)
+ @mock.patch.object(os.path, 'isdir', autospec=True)
+ @mock.patch.object(os, 'chmod', autospec=True)
+ def test_place_common_config(self, mock_chmod, mock_isdir,
+ mock_makedirs):
+ self.config(initial_grub_template=os.path.join(
+ '$pybasedir',
+ 'drivers/modules/initial_grub_cfg.template'),
+ group='pxe')
+ mock_isdir.return_value = False
+ self.config(group='pxe', dir_permission=0o777)
+
+ def write_to_file(path, contents):
+ self.assertEqual('/tftpboot/grub/grub.cfg', path)
+ self.assertIn(
+ 'configfile /tftpboot/$net_default_mac.conf',
+ contents
+ )
+
+ with mock.patch('ironic.common.utils.write_to_file',
+ wraps=write_to_file):
+ pxe_utils.place_common_config()
+
+ mock_isdir.assert_called_once_with('/tftpboot/grub')
+ mock_makedirs.assert_called_once_with('/tftpboot/grub', 511)
+ mock_chmod.assert_called_once_with('/tftpboot/grub', 0o777)
+
+ @mock.patch.object(os, 'makedirs', autospec=True)
+ @mock.patch.object(os.path, 'isdir', autospec=True)
+ @mock.patch.object(os, 'chmod', autospec=True)
+ def test_place_common_config_existing_dirs(self, mock_chmod, mock_isdir,
+ mock_makedirs):
+ self.config(initial_grub_template=os.path.join(
+ '$pybasedir',
+ 'drivers/modules/initial_grub_cfg.template'),
+ group='pxe')
+ mock_isdir.return_value = True
+
+ with mock.patch('ironic.common.utils.write_to_file',
+ autospec=True) as mock_write:
+ pxe_utils.place_common_config()
+ mock_write.assert_called_once()
+
+ mock_isdir.assert_called_once_with('/tftpboot/grub')
+ mock_makedirs.assert_not_called()
+ mock_chmod.assert_not_called()
+
@mock.patch.object(ipxe.iPXEBoot, '__init__', lambda self: None)
@mock.patch.object(pxe.PXEBoot, '__init__', lambda self: None)