Skip to content

Commit

Permalink
Support ipxe with Dnsmasq
Browse files Browse the repository at this point in the history
The workflow of ipxe in ironic now only support ISC dhcpd.
the cause is the option '!175,bootfile-name' is not recognized
by dnsmasq.
Add tag:!ipxe instead of !175 can correct this.

Change-Id: Ie5cb7828c68cf7536a266d1a69c4bad296f43e26
Closes-Bug: #1384577
  • Loading branch information
Tan0 committed Oct 31, 2014
1 parent 5e72ff0 commit 42f3d52
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ironic/common/pxe_utils.py
Expand Up @@ -233,11 +233,19 @@ def dhcp_options_for_instance(task):
if CONF.pxe.ipxe_enabled:
script_name = os.path.basename(CONF.pxe.ipxe_boot_script)
ipxe_script_url = '/'.join([CONF.pxe.http_url, script_name])
dhcp_provider_name = dhcp_factory.CONF.dhcp.dhcp_provider
# if the request comes from dumb firmware send them the iPXE
# boot image. !175 == non-iPXE.
# http://ipxe.org/howto/dhcpd#ipxe-specific_options
dhcp_opts.append({'opt_name': '!175,bootfile-name',
'opt_value': CONF.pxe.pxe_bootfile_name})
# boot image.
if dhcp_provider_name == 'neutron':
# Neutron use dnsmasq as default DHCP agent, add extra config
# to neutron "dhcp-match=set:ipxe,175" and use below option
dhcp_opts.append({'opt_name': 'tag:!ipxe,bootfile-name',
'opt_value': CONF.pxe.pxe_bootfile_name})
else:
# !175 == non-iPXE.
# http://ipxe.org/howto/dhcpd#ipxe-specific_options
dhcp_opts.append({'opt_name': '!175,bootfile-name',
'opt_value': CONF.pxe.pxe_bootfile_name})
# If the request comes from iPXE, direct it to boot from the
# iPXE script
dhcp_opts.append({'opt_name': 'bootfile-name',
Expand Down
15 changes: 15 additions & 0 deletions ironic/tests/test_pxe_utils.py
Expand Up @@ -260,6 +260,7 @@ def test_dhcp_options_for_instance_ipxe(self):
self.config(http_url='http://192.0.3.2:1234', group='pxe')
self.config(ipxe_boot_script='/test/boot.ipxe', group='pxe')

self.config(dhcp_provider='isc', group='dhcp')
expected_boot_script_url = 'http://192.0.3.2:1234/boot.ipxe'
expected_info = [{'opt_name': '!175,bootfile-name',
'opt_value': 'fake-bootfile'},
Expand All @@ -273,6 +274,20 @@ def test_dhcp_options_for_instance_ipxe(self):
self.assertEqual(sorted(expected_info),
sorted(pxe_utils.dhcp_options_for_instance(task)))

self.config(dhcp_provider='neutron', group='dhcp')
expected_boot_script_url = 'http://192.0.3.2:1234/boot.ipxe'
expected_info = [{'opt_name': 'tag:!ipxe,bootfile-name',
'opt_value': 'fake-bootfile'},
{'opt_name': 'server-ip-address',
'opt_value': '192.0.2.1'},
{'opt_name': 'tftp-server',
'opt_value': '192.0.2.1'},
{'opt_name': 'bootfile-name',
'opt_value': expected_boot_script_url}]
with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertEqual(sorted(expected_info),
sorted(pxe_utils.dhcp_options_for_instance(task)))

@mock.patch('ironic.common.utils.rmtree_without_raise', autospec=True)
@mock.patch('ironic.common.utils.unlink_without_raise', autospec=True)
@mock.patch('ironic.common.dhcp_factory.DHCPFactory.provider')
Expand Down

0 comments on commit 42f3d52

Please sign in to comment.