Merge "Do not overwrite the iPXE boot script on every deployment"

This commit is contained in:
Jenkins 2015-08-31 18:28:50 +00:00 committed by Gerrit Code Review
commit ec461e7e38
2 changed files with 16 additions and 3 deletions

View File

@ -473,6 +473,7 @@ class PXEBoot(base.BootInterface):
bootfile_path = os.path.join( bootfile_path = os.path.join(
CONF.deploy.http_root, CONF.deploy.http_root,
os.path.basename(CONF.pxe.ipxe_boot_script)) os.path.basename(CONF.pxe.ipxe_boot_script))
if not os.path.exists(bootfile_path):
shutil.copyfile(CONF.pxe.ipxe_boot_script, bootfile_path) shutil.copyfile(CONF.pxe.ipxe_boot_script, bootfile_path)
dhcp_opts = pxe_utils.dhcp_options_for_instance(task) dhcp_opts = pxe_utils.dhcp_options_for_instance(task)

View File

@ -773,19 +773,31 @@ class PXEBootTestCase(db_base.DbTestCase):
self.node.save() self.node.save()
self._test_prepare_ramdisk(uefi=True) self._test_prepare_ramdisk(uefi=True)
@mock.patch.object(shutil, 'copyfile', autospec=True) def _prepare_ramdisk_ipxe(self):
def test_prepare_ramdisk_ipxe(self, copyfile_mock):
self.node.provision_state = states.DEPLOYING self.node.provision_state = states.DEPLOYING
self.node.save() self.node.save()
self.config(group='pxe', ipxe_enabled=True) self.config(group='pxe', ipxe_enabled=True)
self.config(group='deploy', http_url='http://myserver') self.config(group='deploy', http_url='http://myserver')
self._test_prepare_ramdisk() 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( copyfile_mock.assert_called_once_with(
CONF.pxe.ipxe_boot_script, CONF.pxe.ipxe_boot_script,
os.path.join( os.path.join(
CONF.deploy.http_root, CONF.deploy.http_root,
os.path.basename(CONF.pxe.ipxe_boot_script))) 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): def test_prepare_ramdisk_cleaning(self):
self.node.provision_state = states.CLEANING self.node.provision_state = states.CLEANING
self.node.save() self.node.save()