Correct handling of ramdisk_params in (i)PXE boot

Currently only ipa-api-url is recognized there, since it's hardcoded
in the templates. Anything else is silently ignored. This patch
fixes it by wiring all provided options in pxe_append_params and
dropping the hardcoded ipa-api-url (provided by agent deploy).

Add some logging to make debugging such issues easier.

Change-Id: I573cf99d52a6965d64c2ed7a87cf901c12ea3fec
Story: #1528920
Task: #37255
This commit is contained in:
Dmitry Tantsur 2019-10-23 11:29:53 +02:00
parent 630c85126b
commit 08fe4af481
16 changed files with 44 additions and 24 deletions

View File

@ -720,12 +720,15 @@ def build_instance_pxe_options(task, pxe_info, ipxe_enabled=False):
return pxe_opts
def build_extra_pxe_options():
def build_extra_pxe_options(ramdisk_params=None):
# Enable debug in IPA according to CONF.debug if it was not
# specified yet
pxe_append_params = CONF.pxe.pxe_append_params
if CONF.debug and 'ipa-debug' not in pxe_append_params:
pxe_append_params += ' ipa-debug=1'
if ramdisk_params:
pxe_append_params += ' ' + ' '.join('%s=%s' % tpl
for tpl in ramdisk_params.items())
return {'pxe_append_params': pxe_append_params,
'tftp_server': CONF.pxe.tftp_server,
@ -733,7 +736,7 @@ def build_extra_pxe_options():
def build_pxe_config_options(task, pxe_info, service=False,
ipxe_enabled=False):
ipxe_enabled=False, ramdisk_params=None):
"""Build the PXE config options for a node
This method builds the PXE boot options for a node,
@ -749,6 +752,8 @@ def build_pxe_config_options(task, pxe_info, service=False,
to PXE options.
:param ipxe_enabled: Default false boolean to indicate if ipxe
is in use by the caller.
:param ramdisk_params: the parameters to be passed to the ramdisk.
as kernel command-line arguments.
:returns: A dictionary of pxe options to be used in the pxe bootfile
template.
"""
@ -771,7 +776,7 @@ def build_pxe_config_options(task, pxe_info, service=False,
pxe_options.update(build_instance_pxe_options(task, pxe_info,
ipxe_enabled=ipxe_enabled))
pxe_options.update(build_extra_pxe_options())
pxe_options.update(build_extra_pxe_options(ramdisk_params))
return pxe_options

View File

@ -2,7 +2,7 @@ default deploy
label deploy
kernel {{ pxe_options.deployment_aki_path }}
append initrd={{ pxe_options.deployment_ari_path }} text {{ pxe_options.pxe_append_params }} ipa-api-url={{ pxe_options['ipa-api-url'] }}
append initrd={{ pxe_options.deployment_ari_path }} text {{ pxe_options.pxe_append_params }}
label boot_partition
kernel {{ pxe_options.aki_path }}

View File

@ -158,9 +158,8 @@ class iPXEBoot(pxe_base.PXEBaseMixin, base.BootInterface):
pxe_utils.get_instance_image_info(task, ipxe_enabled=True))
boot_mode_utils.sync_boot_mode(task)
pxe_options = pxe_utils.build_pxe_config_options(task, pxe_info,
ipxe_enabled=True)
pxe_options.update(ramdisk_params)
pxe_options = pxe_utils.build_pxe_config_options(
task, pxe_info, ipxe_enabled=True, ramdisk_params=ramdisk_params)
pxe_config_template = deploy_utils.get_pxe_config_template(node)
@ -187,6 +186,10 @@ class iPXEBoot(pxe_base.PXEBaseMixin, base.BootInterface):
if pxe_info:
pxe_utils.cache_ramdisk_kernel(task, pxe_info, ipxe_enabled=True)
LOG.debug('Ramdisk iPXE boot for node %(node)s has been prepared '
'with kernel params %(params)s',
{'node': node.uuid, 'params': pxe_options})
@METRICS.timer('iPXEBoot.prepare_instance')
def prepare_instance(self, task):
"""Prepares the boot of instance.

View File

@ -7,7 +7,7 @@ goto deploy
:deploy
imgfree
kernel {% if pxe_options.ipxe_timeout > 0 %}--timeout {{ pxe_options.ipxe_timeout }} {% endif %}{{ pxe_options.deployment_aki_path }} selinux=0 troubleshoot=0 text {{ pxe_options.pxe_append_params|default("", true) }} BOOTIF=${mac} ipa-api-url={{ pxe_options['ipa-api-url'] }} initrd={{ pxe_options.initrd_filename|default("deploy_ramdisk", true) }} || goto retry
kernel {% if pxe_options.ipxe_timeout > 0 %}--timeout {{ pxe_options.ipxe_timeout }} {% endif %}{{ pxe_options.deployment_aki_path }} selinux=0 troubleshoot=0 text {{ pxe_options.pxe_append_params|default("", true) }} BOOTIF=${mac} initrd={{ pxe_options.initrd_filename|default("deploy_ramdisk", true) }} || goto retry
initrd {% if pxe_options.ipxe_timeout > 0 %}--timeout {{ pxe_options.ipxe_timeout }} {% endif %}{{ pxe_options.deployment_ari_path }} || goto retry
boot

View File

@ -164,8 +164,8 @@ class PXEBoot(pxe_base.PXEBaseMixin, base.BootInterface):
boot_mode_utils.sync_boot_mode(task)
pxe_options = pxe_utils.build_pxe_config_options(
task, pxe_info, ipxe_enabled=ipxe_enabled)
pxe_options.update(ramdisk_params)
task, pxe_info, ipxe_enabled=ipxe_enabled,
ramdisk_params=ramdisk_params)
pxe_config_template = deploy_utils.get_pxe_config_template(node)
@ -186,6 +186,9 @@ class PXEBoot(pxe_base.PXEBaseMixin, base.BootInterface):
if pxe_info:
pxe_utils.cache_ramdisk_kernel(task, pxe_info,
ipxe_enabled=CONF.pxe.ipxe_enabled)
LOG.debug('Ramdisk PXE boot for node %(node)s has been prepared '
'with kernel params %(params)s',
{'node': node.uuid, 'params': pxe_options})
@METRICS.timer('PXEBoot.prepare_instance')
def prepare_instance(self, task):

View File

@ -2,7 +2,7 @@ default deploy
label deploy
kernel {{ pxe_options.deployment_aki_path }}
append initrd={{ pxe_options.deployment_ari_path }} selinux=0 troubleshoot=0 text {{ pxe_options.pxe_append_params|default("", true) }} ipa-api-url={{ pxe_options['ipa-api-url'] }}
append initrd={{ pxe_options.deployment_ari_path }} selinux=0 troubleshoot=0 text {{ pxe_options.pxe_append_params|default("", true) }}
ipappend 2

View File

@ -3,7 +3,7 @@ set timeout=5
set hidden_timeout_quiet=false
menuentry "deploy" {
linuxefi {{ pxe_options.deployment_aki_path }} selinux=0 troubleshoot=0 text {{ pxe_options.pxe_append_params|default("", true) }} boot_server={{pxe_options.tftp_server}} ipa-api-url={{ pxe_options['ipa-api-url'] }}
linuxefi {{ pxe_options.deployment_aki_path }} selinux=0 troubleshoot=0 text {{ pxe_options.pxe_append_params|default("", true) }} boot_server={{pxe_options.tftp_server}}
initrdefi {{ pxe_options.deployment_ari_path }}
}

View File

@ -1164,7 +1164,8 @@ class PXEInterfacesTestCase(db_base.DbTestCase):
@mock.patch('ironic.common.utils.render_template', autospec=True)
def _test_build_pxe_config_options_pxe(self, render_mock,
whle_dsk_img=False,
debug=False, mode='deploy'):
debug=False, mode='deploy',
ramdisk_params=None):
self.config(debug=debug)
self.config(pxe_append_params='test_param', group='pxe')
# NOTE: right '/' should be removed from url string
@ -1216,6 +1217,9 @@ class PXEInterfacesTestCase(db_base.DbTestCase):
expected_pxe_params = 'test_param'
if debug:
expected_pxe_params += ' ipa-debug=1'
if ramdisk_params:
expected_pxe_params += ' ' + ' '.join(
'%s=%s' % tpl for tpl in ramdisk_params.items())
expected_options = {
'deployment_ari_path': pxe_ramdisk,
@ -1233,7 +1237,8 @@ class PXEInterfacesTestCase(db_base.DbTestCase):
with task_manager.acquire(self.context, self.node.uuid,
shared=True) as task:
options = pxe_utils.build_pxe_config_options(task, image_info)
options = pxe_utils.build_pxe_config_options(
task, image_info, ramdisk_params=ramdisk_params)
self.assertEqual(expected_options, options)
def test_build_pxe_config_options_pxe(self):
@ -1263,6 +1268,10 @@ class PXEInterfacesTestCase(db_base.DbTestCase):
self.node.save()
self._test_build_pxe_config_options_pxe(whle_dsk_img=False)
def test_build_pxe_config_options_ramdisk_params(self):
self._test_build_pxe_config_options_pxe(whle_dsk_img=True,
ramdisk_params={'foo': 'bar'})
def test_build_pxe_config_options_pxe_no_kernel_no_ramdisk(self):
del self.node.driver_internal_info['is_whole_disk_image']
self.node.save()

View File

@ -7,7 +7,7 @@ goto deploy
:deploy
imgfree
kernel http://1.2.3.4:1234/deploy_kernel selinux=0 troubleshoot=0 text test_param BOOTIF=${mac} ipa-api-url=http://192.168.122.184:6385 initrd=deploy_ramdisk || goto retry
kernel http://1.2.3.4:1234/deploy_kernel selinux=0 troubleshoot=0 text test_param BOOTIF=${mac} initrd=deploy_ramdisk || goto retry
initrd http://1.2.3.4:1234/deploy_ramdisk || goto retry
boot

View File

@ -7,7 +7,7 @@ goto deploy
:deploy
imgfree
kernel http://1.2.3.4:1234/deploy_kernel selinux=0 troubleshoot=0 text test_param BOOTIF=${mac} ipa-api-url=http://192.168.122.184:6385 initrd=deploy_ramdisk || goto retry
kernel http://1.2.3.4:1234/deploy_kernel selinux=0 troubleshoot=0 text test_param BOOTIF=${mac} initrd=deploy_ramdisk || goto retry
initrd http://1.2.3.4:1234/deploy_ramdisk || goto retry
boot

View File

@ -7,7 +7,7 @@ goto deploy
:deploy
imgfree
kernel http://1.2.3.4:1234/deploy_kernel selinux=0 troubleshoot=0 text test_param BOOTIF=${mac} ipa-api-url=http://192.168.122.184:6385 initrd=deploy_ramdisk || goto retry
kernel http://1.2.3.4:1234/deploy_kernel selinux=0 troubleshoot=0 text test_param BOOTIF=${mac} initrd=deploy_ramdisk || goto retry
initrd http://1.2.3.4:1234/deploy_ramdisk || goto retry
boot

View File

@ -7,7 +7,7 @@ goto deploy
:deploy
imgfree
kernel --timeout 120 http://1.2.3.4:1234/deploy_kernel selinux=0 troubleshoot=0 text test_param BOOTIF=${mac} ipa-api-url=http://192.168.122.184:6385 initrd=deploy_ramdisk || goto retry
kernel --timeout 120 http://1.2.3.4:1234/deploy_kernel selinux=0 troubleshoot=0 text test_param BOOTIF=${mac} initrd=deploy_ramdisk || goto retry
initrd --timeout 120 http://1.2.3.4:1234/deploy_ramdisk || goto retry
boot

View File

@ -293,11 +293,11 @@ class iPXEBootTestCase(db_base.DbTestCase):
ipxe_enabled=True)
if uefi:
mock_pxe_config.assert_called_once_with(
task, {'foo': 'bar'}, CONF.pxe.uefi_pxe_config_template,
task, {}, CONF.pxe.uefi_pxe_config_template,
ipxe_enabled=True)
else:
mock_pxe_config.assert_called_once_with(
task, {'foo': 'bar'}, CONF.pxe.pxe_config_template,
task, {}, CONF.pxe.pxe_config_template,
ipxe_enabled=True)
def test_prepare_ramdisk(self):

View File

@ -290,11 +290,11 @@ class PXEBootTestCase(db_base.DbTestCase):
ipxe_enabled=CONF.pxe.ipxe_enabled)
if uefi:
mock_pxe_config.assert_called_once_with(
task, {'foo': 'bar'}, CONF.pxe.uefi_pxe_config_template,
task, {}, CONF.pxe.uefi_pxe_config_template,
ipxe_enabled=CONF.pxe.ipxe_enabled)
else:
mock_pxe_config.assert_called_once_with(
task, {'foo': 'bar'}, CONF.pxe.pxe_config_template,
task, {}, CONF.pxe.pxe_config_template,
ipxe_enabled=CONF.pxe.ipxe_enabled)
def test_prepare_ramdisk(self):

View File

@ -2,7 +2,7 @@ default deploy
label deploy
kernel /tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/deploy_kernel
append initrd=/tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/deploy_ramdisk selinux=0 troubleshoot=0 text test_param ipa-api-url=http://192.168.122.184:6385
append initrd=/tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/deploy_ramdisk selinux=0 troubleshoot=0 text test_param
ipappend 2

View File

@ -3,7 +3,7 @@ set timeout=5
set hidden_timeout_quiet=false
menuentry "deploy" {
linuxefi /tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/deploy_kernel selinux=0 troubleshoot=0 text test_param boot_server=192.0.2.1 ipa-api-url=http://192.168.122.184:6385
linuxefi /tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/deploy_kernel selinux=0 troubleshoot=0 text test_param boot_server=192.0.2.1
initrdefi /tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/deploy_ramdisk
}