From d72493deb21db90961c80757fd81d30fb39a43c8 Mon Sep 17 00:00:00 2001 From: Lucas Alvares Gomes Date: Fri, 28 Aug 2015 15:19:30 +0100 Subject: [PATCH] Do not overwrite the iPXE boot script on every deployment This patch just add a check to verify if the iPXE boot script have already been laid down in the HTTP root directory and do not overwrite it if it's already there. The script is the same for all deployments so we don't need to write it over and over. This also makes it easier to test some custom parameter in the script without having to deal with Ironic undoing the changes prior to deploy a node. Closes-Bug: #1489904 Change-Id: I0d56767978a6d1290442e50d7cb1308d78e3a352 --- ironic/drivers/modules/pxe.py | 3 ++- ironic/tests/drivers/test_pxe.py | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/ironic/drivers/modules/pxe.py b/ironic/drivers/modules/pxe.py index 2461beac70..7c9ece81a7 100644 --- a/ironic/drivers/modules/pxe.py +++ b/ironic/drivers/modules/pxe.py @@ -429,7 +429,8 @@ class PXEBoot(base.BootInterface): bootfile_path = os.path.join( CONF.deploy.http_root, os.path.basename(CONF.pxe.ipxe_boot_script)) - shutil.copyfile(CONF.pxe.ipxe_boot_script, bootfile_path) + if not os.path.exists(bootfile_path): + shutil.copyfile(CONF.pxe.ipxe_boot_script, bootfile_path) dhcp_opts = pxe_utils.dhcp_options_for_instance(task) provider = dhcp_factory.DHCPFactory() diff --git a/ironic/tests/drivers/test_pxe.py b/ironic/tests/drivers/test_pxe.py index e3fc80cab4..e6aa2e7016 100644 --- a/ironic/tests/drivers/test_pxe.py +++ b/ironic/tests/drivers/test_pxe.py @@ -737,19 +737,31 @@ class PXEBootTestCase(db_base.DbTestCase): self.node.save() self._test_prepare_ramdisk(uefi=True) - @mock.patch.object(shutil, 'copyfile', autospec=True) - def test_prepare_ramdisk_ipxe(self, copyfile_mock): + def _prepare_ramdisk_ipxe(self): self.node.provision_state = states.DEPLOYING self.node.save() self.config(group='pxe', ipxe_enabled=True) self.config(group='deploy', http_url='http://myserver') self._test_prepare_ramdisk() + + @mock.patch.object(shutil, 'copyfile', autospec=True) + def test_prepare_ramdisk_ipxe(self, copyfile_mock): + self._prepare_ramdisk_ipxe() copyfile_mock.assert_called_once_with( CONF.pxe.ipxe_boot_script, os.path.join( CONF.deploy.http_root, os.path.basename(CONF.pxe.ipxe_boot_script))) + @mock.patch.object(os.path, 'exists', autospec=True) + @mock.patch.object(shutil, 'copyfile', autospec=True) + def test_prepare_ramdisk_ipxe_already_present( + self, copyfile_mock, path_exists_mock): + path_exists_mock.return_value = True + self._prepare_ramdisk_ipxe() + # Assert we don't copy the boot script again + self.assertFalse(copyfile_mock.called) + def test_prepare_ramdisk_cleaning(self): self.node.provision_state = states.CLEANING self.node.save()