From 5c3bb2f752316bdfb8bfb13ab6c7d43ed900d137 Mon Sep 17 00:00:00 2001 From: dekehn Date: Tue, 10 Dec 2013 17:11:53 -0700 Subject: [PATCH] Method to generate PXE options for Neutron ports Add a new method to generate the structure containing the PXE bootfile-name, server-ip-address, and tftp-server information. This information will be used to provide Neutron DHCP options to set up the PXE booting of nodes. This patch does not actually pass the data to Neutron, however. Change-Id: Iadf5b803bb5a5465fc2adcb94fa3fd2a756340be --- etc/ironic/ironic.conf.sample | 3 +++ ironic/drivers/modules/pxe.py | 25 ++++++++++++++++++++++--- ironic/tests/drivers/test_pxe.py | 12 ++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/etc/ironic/ironic.conf.sample b/etc/ironic/ironic.conf.sample index 0c389c3091..6cc2c87c51 100644 --- a/etc/ironic/ironic.conf.sample +++ b/etc/ironic/ironic.conf.sample @@ -711,4 +711,7 @@ # (string value) #instance_master_path=/var/lib/ironic/master_images +# Neutron bootfile DHCP parameter. (string value) +#pxe_bootfile_name=pxelinux.0 + diff --git a/ironic/drivers/modules/pxe.py b/ironic/drivers/modules/pxe.py index b2072bcad5..d8176b079a 100644 --- a/ironic/drivers/modules/pxe.py +++ b/ironic/drivers/modules/pxe.py @@ -59,8 +59,6 @@ pxe_opts = [ cfg.IntOpt('pxe_deploy_timeout', help='Timeout for PXE deployments. Default: 0 (unlimited)', default=0), - # TODO(sjing): when adding neutron-port configuration, use this option - # instead of assuming tftp server is on $my_ip cfg.StrOpt('tftp_server', default='$my_ip', help='IP address of Ironic compute node\'s tftp server'), @@ -75,7 +73,12 @@ pxe_opts = [ help='Directory where master tftp images are stored on disk'), cfg.StrOpt('instance_master_path', default='/var/lib/ironic/master_images', - help='Directory where master tftp images are stored on disk') + help='Directory where master tftp images are stored on disk'), + # NOTE(dekehn): Additional boot files options may be created in the event + # other architectures require different boot files. + cfg.StrOpt('pxe_bootfile_name', + default='pxelinux.0', + help='Neutron bootfile DHCP parameter.'), ] LOG = logging.getLogger(__name__) @@ -205,6 +208,11 @@ def _get_pxe_config_file_path(instance_uuid): return os.path.join(CONF.pxe.tftp_root, instance_uuid, 'config') +def _get_pxe_bootfile_name(): + """Returns the pxe_bootfile_name option.""" + return CONF.pxe.pxe_bootfile_name + + def _get_image_dir_path(d_info): """Generate the dir for an instances disk.""" return os.path.join(CONF.pxe.images_path, d_info['instance_name']) @@ -438,6 +446,17 @@ def _destroy_token_file(node): utils.unlink_without_raise(token_file_path) +def _dhcp_options_for_instance(): + """Retrives the DHCP PXE boot options.""" + return [{'opt_name': 'bootfile-name', + 'opt_value': _get_pxe_bootfile_name()}, + {'opt_name': 'server-ip-address', + 'opt_value': CONF.pxe.tftp_server}, + {'opt_name': 'tftp-server', + 'opt_value': CONF.pxe.tftp_server} + ] + + def _create_pxe_config(task, node, pxe_info): """Generate pxe configuration file and link mac ports to it for tftp booting. diff --git a/ironic/tests/drivers/test_pxe.py b/ironic/tests/drivers/test_pxe.py index fbe7feafb2..d901729179 100644 --- a/ironic/tests/drivers/test_pxe.py +++ b/ironic/tests/drivers/test_pxe.py @@ -280,6 +280,18 @@ class PXEPrivateMethodsTestCase(base.TestCase): db_key = db_node['driver_info'].get('pxe_deploy_key') self.assertEqual(db_key, fake_key) + def test__dhcp_options_for_instance(self): + CONF.set_default('pxe_bootfile_name', 'test_pxe_bootfile', group='pxe') + CONF.set_default('tftp_server', '192.0.2.1', group='pxe') + expected_info = [{'opt_name': 'bootfile-name', + 'opt_value': 'test_pxe_bootfile'}, + {'opt_name': 'server-ip-address', + 'opt_value': '192.0.2.1'}, + {'opt_name': 'tftp-server', + 'opt_value': '192.0.2.1'} + ] + self.assertEqual(expected_info, pxe._dhcp_options_for_instance()) + def test__get_pxe_config_file_path(self): self.assertEqual('/tftpboot/instance_uuid_123/config', pxe._get_pxe_config_file_path('instance_uuid_123'))