Merge "Correct handling of ramdisk_params in (i)PXE boot"

This commit is contained in:
Zuul 2019-10-30 21:44:19 +00:00 committed by Gerrit Code Review
commit 2d8e9f6aee
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 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 # Enable debug in IPA according to CONF.debug if it was not
# specified yet # specified yet
pxe_append_params = CONF.pxe.pxe_append_params pxe_append_params = CONF.pxe.pxe_append_params
if CONF.debug and 'ipa-debug' not in pxe_append_params: if CONF.debug and 'ipa-debug' not in pxe_append_params:
pxe_append_params += ' ipa-debug=1' 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, return {'pxe_append_params': pxe_append_params,
'tftp_server': CONF.pxe.tftp_server, '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, 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 """Build the PXE config options for a node
This method builds the PXE boot 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. to PXE options.
:param ipxe_enabled: Default false boolean to indicate if ipxe :param ipxe_enabled: Default false boolean to indicate if ipxe
is in use by the caller. 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 :returns: A dictionary of pxe options to be used in the pxe bootfile
template. 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, pxe_options.update(build_instance_pxe_options(task, pxe_info,
ipxe_enabled=ipxe_enabled)) ipxe_enabled=ipxe_enabled))
pxe_options.update(build_extra_pxe_options()) pxe_options.update(build_extra_pxe_options(ramdisk_params))
return pxe_options return pxe_options

View File

@ -2,7 +2,7 @@ default deploy
label deploy label deploy
kernel {{ pxe_options.deployment_aki_path }} 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 label boot_partition
kernel {{ pxe_options.aki_path }} 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)) pxe_utils.get_instance_image_info(task, ipxe_enabled=True))
boot_mode_utils.sync_boot_mode(task) boot_mode_utils.sync_boot_mode(task)
pxe_options = pxe_utils.build_pxe_config_options(task, pxe_info, pxe_options = pxe_utils.build_pxe_config_options(
ipxe_enabled=True) task, pxe_info, ipxe_enabled=True, ramdisk_params=ramdisk_params)
pxe_options.update(ramdisk_params)
pxe_config_template = deploy_utils.get_pxe_config_template(node) pxe_config_template = deploy_utils.get_pxe_config_template(node)
@ -187,6 +186,10 @@ class iPXEBoot(pxe_base.PXEBaseMixin, base.BootInterface):
if pxe_info: if pxe_info:
pxe_utils.cache_ramdisk_kernel(task, pxe_info, ipxe_enabled=True) 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') @METRICS.timer('iPXEBoot.prepare_instance')
def prepare_instance(self, task): def prepare_instance(self, task):
"""Prepares the boot of instance. """Prepares the boot of instance.

View File

@ -7,7 +7,7 @@ goto deploy
:deploy :deploy
imgfree 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 initrd {% if pxe_options.ipxe_timeout > 0 %}--timeout {{ pxe_options.ipxe_timeout }} {% endif %}{{ pxe_options.deployment_ari_path }} || goto retry
boot boot

View File

@ -164,8 +164,8 @@ class PXEBoot(pxe_base.PXEBaseMixin, base.BootInterface):
boot_mode_utils.sync_boot_mode(task) boot_mode_utils.sync_boot_mode(task)
pxe_options = pxe_utils.build_pxe_config_options( pxe_options = pxe_utils.build_pxe_config_options(
task, pxe_info, ipxe_enabled=ipxe_enabled) task, pxe_info, ipxe_enabled=ipxe_enabled,
pxe_options.update(ramdisk_params) ramdisk_params=ramdisk_params)
pxe_config_template = deploy_utils.get_pxe_config_template(node) pxe_config_template = deploy_utils.get_pxe_config_template(node)
@ -186,6 +186,9 @@ class PXEBoot(pxe_base.PXEBaseMixin, base.BootInterface):
if pxe_info: if pxe_info:
pxe_utils.cache_ramdisk_kernel(task, pxe_info, pxe_utils.cache_ramdisk_kernel(task, pxe_info,
ipxe_enabled=CONF.pxe.ipxe_enabled) 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') @METRICS.timer('PXEBoot.prepare_instance')
def prepare_instance(self, task): def prepare_instance(self, task):

View File

@ -2,7 +2,7 @@ default deploy
label deploy label deploy
kernel {{ pxe_options.deployment_aki_path }} 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 ipappend 2

View File

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

View File

@ -7,7 +7,7 @@ goto deploy
:deploy :deploy
imgfree 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 initrd http://1.2.3.4:1234/deploy_ramdisk || goto retry
boot boot

View File

@ -7,7 +7,7 @@ goto deploy
:deploy :deploy
imgfree 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 initrd http://1.2.3.4:1234/deploy_ramdisk || goto retry
boot boot

View File

@ -7,7 +7,7 @@ goto deploy
:deploy :deploy
imgfree 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 initrd http://1.2.3.4:1234/deploy_ramdisk || goto retry
boot boot

View File

@ -7,7 +7,7 @@ goto deploy
:deploy :deploy
imgfree 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 initrd --timeout 120 http://1.2.3.4:1234/deploy_ramdisk || goto retry
boot boot

View File

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

View File

@ -290,11 +290,11 @@ class PXEBootTestCase(db_base.DbTestCase):
ipxe_enabled=CONF.pxe.ipxe_enabled) ipxe_enabled=CONF.pxe.ipxe_enabled)
if uefi: if uefi:
mock_pxe_config.assert_called_once_with( 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) ipxe_enabled=CONF.pxe.ipxe_enabled)
else: else:
mock_pxe_config.assert_called_once_with( 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) ipxe_enabled=CONF.pxe.ipxe_enabled)
def test_prepare_ramdisk(self): def test_prepare_ramdisk(self):

View File

@ -2,7 +2,7 @@ default deploy
label deploy label deploy
kernel /tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/deploy_kernel 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 ipappend 2

View File

@ -3,7 +3,7 @@ set timeout=5
set hidden_timeout_quiet=false set hidden_timeout_quiet=false
menuentry "deploy" { 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 initrdefi /tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/deploy_ramdisk
} }