Clean up kernel_append_params for PXE/iPXE

Currently handling of kernel_append_params is very inconsistent. This
change applies a straightforward process:
1. instance_info[kernel_append_params]
2. driver_info[kernel_append_params]
3. [pxe]kernel_append_params (renamed from pxe_append_params).

Also adds a helper for subsequent fixes in other drivers.

Change-Id: I79bcf4d8ef1f0f55a82e0991dd5bb1685b3f7957
Story: #2008902
Task: #42469
This commit is contained in:
Dmitry Tantsur 2021-05-17 15:18:55 +02:00
parent af94a3da1e
commit 2a73f5a84e
12 changed files with 86 additions and 17 deletions

View File

@ -1717,7 +1717,7 @@ function configure_ironic_conductor {
pxe_params+=" $IRONIC_EXTRA_PXE_PARAMS" pxe_params+=" $IRONIC_EXTRA_PXE_PARAMS"
if [[ -n "$pxe_params" ]]; then if [[ -n "$pxe_params" ]]; then
iniset $IRONIC_CONF_FILE pxe pxe_append_params "$pxe_params" iniset $IRONIC_CONF_FILE pxe kernel_append_params "$pxe_params"
fi fi
local kernel_append_params="nofb nomodeset console=${IRONIC_TTY_DEV}" local kernel_append_params="nofb nomodeset console=${IRONIC_TTY_DEV}"

View File

@ -13,11 +13,16 @@ Network boot
Currently, the Bare Metal service supports assigning unified kernel parameters to PXE Currently, the Bare Metal service supports assigning unified kernel parameters to PXE
booted instances by: booted instances by:
* Modifying the ``[pxe]/pxe_append_params`` configuration option, for example:: * Modifying the ``[pxe]/kernel_append_params`` configuration option, for
example:
.. code-block:: ini
[pxe] [pxe]
kernel_append_params = quiet splash
pxe_append_params = quiet splash .. note::
The option was called ``pxe_append_params`` before the Xena cycle.
* Copying a template from shipped templates to another place, for example:: * Copying a template from shipped templates to another place, for example::
@ -86,7 +91,7 @@ respectively.
[pxe] [pxe]
# Additional append parameters for baremetal PXE boot. # Additional append parameters for baremetal PXE boot.
pxe_append_params = nofb nomodeset vga=normal console=ttyS0,115200n8 kernel_append_params = nofb nomodeset vga=normal console=ttyS0,115200n8
* For node web console configuration is similar with the addition of ``ttyX`` * For node web console configuration is similar with the addition of ``ttyX``
@ -95,7 +100,7 @@ respectively.
[pxe] [pxe]
# Additional append parameters for baremetal PXE boot. # Additional append parameters for baremetal PXE boot.
pxe_append_params = nofb nomodeset vga=normal console=tty0 console=ttyS0,115200n8 kernel_append_params = nofb nomodeset vga=normal console=tty0 console=ttyS0,115200n8
For detailed information on how to add consoles see the reference documents For detailed information on how to add consoles see the reference documents
`kernel params`_ and `serial console`_. `kernel params`_ and `serial console`_.

View File

@ -38,6 +38,7 @@ from ironic.conf import CONF
from ironic.drivers.modules import boot_mode_utils from ironic.drivers.modules import boot_mode_utils
from ironic.drivers.modules import deploy_utils from ironic.drivers.modules import deploy_utils
from ironic.drivers.modules import image_cache from ironic.drivers.modules import image_cache
from ironic.drivers import utils as driver_utils
from ironic import objects from ironic import objects
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -831,10 +832,11 @@ def build_instance_pxe_options(task, pxe_info, ipxe_enabled=False):
return pxe_opts return pxe_opts
def build_extra_pxe_options(task=None, ramdisk_params=None): def build_extra_pxe_options(task, ramdisk_params=None):
pxe_append_params = driver_utils.get_kernel_append_params(
task.node, default=CONF.pxe.kernel_append_params)
# 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
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: if ramdisk_params:

View File

@ -21,7 +21,8 @@ from oslo_config import cfg
from ironic.common.i18n import _ from ironic.common.i18n import _
opts = [ opts = [
cfg.StrOpt('pxe_append_params', cfg.StrOpt('kernel_append_params',
deprecated_name='pxe_append_params',
default='nofb nomodeset vga=normal', default='nofb nomodeset vga=normal',
mutable=True, mutable=True,
help=_('Additional append parameters for baremetal PXE boot.')), help=_('Additional append parameters for baremetal PXE boot.')),

View File

@ -308,7 +308,8 @@ def _prepare_boot_iso(task, root_uuid):
deploy_iso_href = deploy_info['irmc_deploy_iso'] deploy_iso_href = deploy_info['irmc_deploy_iso']
boot_mode = boot_mode_utils.get_boot_mode(task.node) boot_mode = boot_mode_utils.get_boot_mode(task.node)
kernel_params = CONF.pxe.pxe_append_params # FIXME(dtantsur): why is iRMC virtual media using PXE options?
kernel_params = CONF.pxe.kernel_append_params
boot_iso_filename = _get_iso_name(task.node, label='boot') boot_iso_filename = _get_iso_name(task.node, label='boot')
boot_iso_fullpathname = os.path.join( boot_iso_fullpathname = os.path.join(

View File

@ -51,9 +51,19 @@ RESCUE_PROPERTIES = {
'that is used at node rescue time. This value is ' 'that is used at node rescue time. This value is '
'required for rescue mode.'), 'required for rescue mode.'),
} }
OPTIONAL_PROPERTIES = {
'kernel_append_params': _("Additional kernel parameters to pass down to "
"instance kernel. These parameters can be "
"consumed by the kernel or by the applications "
"by reading /proc/cmdline. Mind severe cmdline "
"size limit. Overrides "
"[pxe]/kernel_append_params ironic "
"option."),
}
COMMON_PROPERTIES = REQUIRED_PROPERTIES.copy() COMMON_PROPERTIES = REQUIRED_PROPERTIES.copy()
COMMON_PROPERTIES.update(driver_utils.OPTIONAL_PROPERTIES) COMMON_PROPERTIES.update(driver_utils.OPTIONAL_PROPERTIES)
COMMON_PROPERTIES.update(RESCUE_PROPERTIES) COMMON_PROPERTIES.update(RESCUE_PROPERTIES)
COMMON_PROPERTIES.update(OPTIONAL_PROPERTIES)
class PXEBaseMixin(object): class PXEBaseMixin(object):

View File

@ -384,3 +384,23 @@ OPTIONAL_PROPERTIES = {
"deprecated in favor of the new ones." "deprecated in favor of the new ones."
"Defaults to 'Default'. Optional."), "Defaults to 'Default'. Optional."),
} }
def get_kernel_append_params(node, default):
"""Get the applicable kernel params.
The locations are checked in this order:
1. The node's instance_info.
2. The node's driver_info.
3. Configuration.
:param node: Node object.
:param default: Default value.
"""
for location in ('instance_info', 'driver_info'):
result = getattr(node, location).get('kernel_append_params')
if result is not None:
return result
return default

View File

@ -1452,9 +1452,10 @@ class PXEBuildConfigOptionsTestCase(db_base.DbTestCase):
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): ramdisk_params=None,
expected_pxe_params=None):
self.config(debug=debug) self.config(debug=debug)
self.config(pxe_append_params='test_param', group='pxe') self.config(kernel_append_params='test_param', group='pxe')
driver_internal_info = self.node.driver_internal_info driver_internal_info = self.node.driver_internal_info
driver_internal_info['is_whole_disk_image'] = whle_dsk_img driver_internal_info['is_whole_disk_image'] = whle_dsk_img
@ -1498,7 +1499,8 @@ class PXEBuildConfigOptionsTestCase(db_base.DbTestCase):
'ramdisk')) 'ramdisk'))
}) })
expected_pxe_params = 'test_param' if expected_pxe_params is None:
expected_pxe_params = 'test_param'
if debug: if debug:
expected_pxe_params += ' ipa-debug=1' expected_pxe_params += ' ipa-debug=1'
if ramdisk_params: if ramdisk_params:
@ -1554,6 +1556,22 @@ class PXEBuildConfigOptionsTestCase(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_kernel_params_from_driver_info(self):
info = self.node.driver_info
info['kernel_append_params'] = 'params2'
self.node.driver_info = info
self.node.save()
self._test_build_pxe_config_options_pxe(whle_dsk_img=True,
expected_pxe_params='params2')
def test_build_pxe_config_options_kernel_params_from_instance_info(self):
info = self.node.instance_info
info['kernel_append_params'] = 'params2'
self.node.instance_info = info
self.node.save()
self._test_build_pxe_config_options_pxe(whle_dsk_img=True,
expected_pxe_params='params2')
def test_build_pxe_config_options_ramdisk_params(self): def test_build_pxe_config_options_ramdisk_params(self):
self._test_build_pxe_config_options_pxe(whle_dsk_img=True, self._test_build_pxe_config_options_pxe(whle_dsk_img=True,
ramdisk_params={'foo': 'bar'}) ramdisk_params={'foo': 'bar'})
@ -1562,7 +1580,7 @@ class PXEBuildConfigOptionsTestCase(db_base.DbTestCase):
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()
pxe_params = 'my-pxe-append-params ipa-debug=0' pxe_params = 'my-pxe-append-params ipa-debug=0'
self.config(group='pxe', pxe_append_params=pxe_params) self.config(group='pxe', kernel_append_params=pxe_params)
self.config(group='pxe', tftp_server='my-tftp-server') self.config(group='pxe', tftp_server='my-tftp-server')
self.config(group='pxe', tftp_root='/tftp-path/') self.config(group='pxe', tftp_root='/tftp-path/')
image_info = { image_info = {
@ -1717,7 +1735,7 @@ class iPXEBuildConfigOptionsTestCase(db_base.DbTestCase):
iso_boot=False, iso_boot=False,
multipath=False): multipath=False):
self.config(debug=debug) self.config(debug=debug)
self.config(pxe_append_params='test_param', group='pxe') self.config(kernel_append_params='test_param', group='pxe')
self.config(ipxe_timeout=ipxe_timeout, group='pxe') self.config(ipxe_timeout=ipxe_timeout, group='pxe')
root_dir = CONF.deploy.http_root root_dir = CONF.deploy.http_root

View File

@ -5695,7 +5695,8 @@ class ManagerTestProperties(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
'image_http_proxy', 'image_https_proxy', 'image_http_proxy', 'image_https_proxy',
'image_no_proxy']) 'image_no_proxy'])
if pxe_common: if pxe_common:
expected.extend(['rescue_kernel', 'rescue_ramdisk']) expected.extend(['kernel_append_params',
'rescue_kernel', 'rescue_ramdisk'])
expected.append('force_persistent_boot_device') expected.append('force_persistent_boot_device')
self.assertCountEqual(expected, properties) self.assertCountEqual(expected, properties)

View File

@ -492,7 +492,7 @@ class IRMCDeployPrivateMethodsTestCase(test_common.BaseIRMCTest):
boot_mode_mock, boot_mode_mock,
create_boot_iso_mock, create_boot_iso_mock,
check_share_fs_mounted_mock): check_share_fs_mounted_mock):
CONF.pxe.pxe_append_params = 'kernel-params' self.config(kernel_append_params='kernel-params', group='pxe')
deploy_info_mock.return_value = \ deploy_info_mock.return_value = \
{'image_source': 'image-uuid', {'image_source': 'image-uuid',

View File

@ -72,7 +72,8 @@ class ManualManagementHardwareTestCase(db_base.DbTestCase):
'deploy_kernel', 'deploy_ramdisk', 'deploy_kernel', 'deploy_ramdisk',
'image_download_source', 'image_http_proxy', 'image_download_source', 'image_http_proxy',
'image_https_proxy', 'image_no_proxy', 'image_https_proxy', 'image_no_proxy',
'force_persistent_boot_device', 'rescue_kernel', 'rescue_ramdisk'] 'force_persistent_boot_device', 'kernel_append_params',
'rescue_kernel', 'rescue_ramdisk']
hardware_type = driver_factory.get_hardware_type("manual-management") hardware_type = driver_factory.get_hardware_type("manual-management")
properties = hardware_type.get_properties() properties = hardware_type.get_properties()
self.assertCountEqual(expected_prop_keys, properties) self.assertCountEqual(expected_prop_keys, properties)

View File

@ -0,0 +1,10 @@
---
features:
- |
Adds support for setting kernel parameters for PXE and iPXE boot through
the new ``kernel_append_params`` setting in the node's ``driver_info`` or
``instance_info``.
deprecations:
- |
The configuration option ``[pxe]pxe_append_params`` has been renamed to
``[pxe]kernel_append_params``. The old name is now deprecated.