Fix ipxe interface to perform ipxe boot without ipxe_enabled enabled

When ipxe hardware interface is in use, the node should always be boot
with iPXE disregards the deprecated configuration option [pxe]ipxe_enabled.

Story: 2007003
Task: 37779

Change-Id: Ia658ddc966e13a7ce973eccd9c42e40a3da406f4
(cherry picked from commit f61624e069)
This commit is contained in:
Kaifeng Wang 2019-12-06 16:24:16 +08:00
parent 6ceec86ad4
commit 0e84dea473
6 changed files with 30 additions and 32 deletions

View File

@ -117,7 +117,8 @@ def _link_mac_pxe_configs(task, ipxe_enabled=False):
create_link(_get_pxe_mac_path(port.address, client_id=client_id,
ipxe_enabled=ipxe_enabled))
# Grub2 MAC address only
create_link(_get_pxe_grub_mac_path(port.address))
create_link(_get_pxe_grub_mac_path(port.address,
ipxe_enabled=ipxe_enabled))
def _link_ip_address_pxe_configs(task, ipxe_enabled=False):
@ -158,8 +159,9 @@ def _link_ip_address_pxe_configs(task, ipxe_enabled=False):
ip_address_path)
def _get_pxe_grub_mac_path(mac):
return os.path.join(get_root_dir(), mac + '.conf')
def _get_pxe_grub_mac_path(mac, ipxe_enabled=False):
root_dir = get_ipxe_root_dir() if ipxe_enabled else get_root_dir()
return os.path.join(root_dir, mac + '.conf')
def _get_pxe_mac_path(mac, delimiter='-', client_id=None,
@ -367,7 +369,7 @@ def clean_up_pxe_config(task, ipxe_enabled=False):
ipxe_enabled=ipxe_enabled))
# Grub2 MAC address based confiuration
ironic_utils.unlink_without_raise(
_get_pxe_grub_mac_path(port.address))
_get_pxe_grub_mac_path(port.address, ipxe_enabled=ipxe_enabled))
if ipxe_enabled:
utils.rmtree_without_raise(os.path.join(get_ipxe_root_dir(),
task.node.uuid))
@ -781,7 +783,8 @@ def build_service_pxe_config(task, instance_image_info,
ramdisk_boot=False,
ipxe_enabled=False):
node = task.node
pxe_config_path = get_pxe_config_file_path(node.uuid)
pxe_config_path = get_pxe_config_file_path(node.uuid,
ipxe_enabled=ipxe_enabled)
# NOTE(pas-ha) if it is takeover of ACTIVE node or node performing
# unrescue operation, first ensure that basic PXE configs and links
# are in place before switching pxe config
@ -919,7 +922,7 @@ def prepare_instance_pxe_config(task, image_info,
provider = dhcp_factory.DHCPFactory()
provider.update_dhcp(task, dhcp_opts)
pxe_config_path = get_pxe_config_file_path(
node.uuid)
node.uuid, ipxe_enabled=ipxe_enabled)
if not os.path.isfile(pxe_config_path):
pxe_options = build_pxe_config_options(
task, image_info, service=ramdisk_boot,

View File

@ -21,6 +21,7 @@ import retrying
from ironic.common import cinder
from ironic.common import exception
from ironic.common.i18n import _
from ironic.common import pxe_utils
from ironic.common import states
from ironic.drivers import base
from ironic.drivers import utils
@ -76,13 +77,7 @@ class CinderStorage(base.StorageInterface):
iscsi_uuids_found = []
wwpn_found = 0
wwnn_found = 0
ipxe_enabled = False
if 'pxe_boot' in task.driver.boot.capabilities:
if CONF.pxe.ipxe_enabled:
ipxe_enabled = True
elif 'ipxe_boot' in task.driver.boot.capabilities:
ipxe_enabled = True
ipxe_enabled = pxe_utils.is_ipxe_enabled(task)
for connector in task.volume_connectors:
if (connector.type in VALID_ISCSI_TYPES
and connector.connector_id is not None):

View File

@ -639,16 +639,9 @@ class TestPXEUtils(db_base.DbTestCase):
def test_get_root_dir(self):
expected_dir = '/tftproot'
self.config(ipxe_enabled=False, group='pxe')
self.config(tftp_root=expected_dir, group='pxe')
self.assertEqual(expected_dir, pxe_utils.get_root_dir())
def test_get_root_dir_ipxe(self):
expected_dir = '/httpboot'
self.config(ipxe_enabled=True, group='pxe')
self.config(http_root=expected_dir, group='deploy')
self.assertEqual(expected_dir, pxe_utils.get_root_dir())
def test_get_pxe_config_file_path(self):
self.assertEqual(os.path.join(CONF.pxe.tftp_root,
self.node.uuid,
@ -700,7 +693,8 @@ class TestPXEUtils(db_base.DbTestCase):
self.config(tftp_server='ff80::1', group='pxe')
self._dhcp_options_for_instance(ip_version=6)
def _test_get_kernel_ramdisk_info(self, expected_dir, mode='deploy'):
def _test_get_kernel_ramdisk_info(self, expected_dir, mode='deploy',
ipxe_enabled=False):
node_uuid = 'fake-node'
driver_info = {
@ -713,7 +707,8 @@ class TestPXEUtils(db_base.DbTestCase):
expected[k] = (v, expected_dir + '/fake-node/%s' % k)
kr_info = pxe_utils.get_kernel_ramdisk_info(node_uuid,
driver_info,
mode=mode)
mode=mode,
ipxe_enabled=ipxe_enabled)
self.assertEqual(expected, kr_info)
def test_get_kernel_ramdisk_info(self):
@ -723,9 +718,8 @@ class TestPXEUtils(db_base.DbTestCase):
def test_get_kernel_ramdisk_info_ipxe(self):
expected_dir = '/http'
self.config(ipxe_enabled=True, group='pxe')
self.config(http_root=expected_dir, group='deploy')
self._test_get_kernel_ramdisk_info(expected_dir)
self._test_get_kernel_ramdisk_info(expected_dir, ipxe_enabled=True)
def test_get_kernel_ramdisk_info_bad_driver_info(self):
self.config(tftp_root='/tftp', group='pxe')
@ -743,9 +737,9 @@ class TestPXEUtils(db_base.DbTestCase):
def test_get_rescue_kr_info_ipxe(self):
expected_dir = '/http'
self.config(ipxe_enabled=True, group='pxe')
self.config(http_root=expected_dir, group='deploy')
self._test_get_kernel_ramdisk_info(expected_dir, mode='rescue')
self._test_get_kernel_ramdisk_info(expected_dir, mode='rescue',
ipxe_enabled=True)
def _dhcp_options_for_instance_ipxe(self, task, boot_file, ip_version=4):
self.config(ipxe_enabled=True, group='pxe')
@ -1639,13 +1633,13 @@ class PXEInterfacesTestCase(db_base.DbTestCase):
@mock.patch.object(deploy_utils, 'fetch_images', autospec=True)
def test_cache_ramdisk_kernel_ipxe(self, mock_fetch_image,
mock_ensure_tree):
self.config(ipxe_enabled=True, group='pxe')
fake_pxe_info = {'foo': 'bar'}
expected_path = os.path.join(CONF.deploy.http_root,
self.node.uuid)
with task_manager.acquire(self.context, self.node.uuid,
shared=True) as task:
pxe_utils.cache_ramdisk_kernel(task, fake_pxe_info)
pxe_utils.cache_ramdisk_kernel(task, fake_pxe_info,
ipxe_enabled=True)
mock_ensure_tree.assert_called_with(expected_path)
mock_fetch_image.assert_called_once_with(self.context, mock.ANY,
list(fake_pxe_info.values()),

View File

@ -622,7 +622,7 @@ class iPXEBootTestCase(db_base.DbTestCase):
dhcp_opts = pxe_utils.dhcp_options_for_instance(
task, ipxe_enabled=True)
pxe_config_path = pxe_utils.get_pxe_config_file_path(
task.node.uuid)
task.node.uuid, ipxe_enabled=True)
task.node.properties['capabilities'] = 'boot_mode:bios'
task.node.driver_internal_info['root_uuid_or_disk_id'] = (
"30212642-09d3-467f-8e09-21685826ab50")
@ -664,7 +664,7 @@ class iPXEBootTestCase(db_base.DbTestCase):
dhcp_opts = pxe_utils.dhcp_options_for_instance(
task, ipxe_enabled=True)
pxe_config_path = pxe_utils.get_pxe_config_file_path(
task.node.uuid)
task.node.uuid, ipxe_enabled=True)
task.node.properties['capabilities'] = 'boot_mode:bios'
task.node.driver_internal_info['root_uuid_or_disk_id'] = (
"30212642-09d3-467f-8e09-21685826ab50")
@ -779,7 +779,7 @@ class iPXEBootTestCase(db_base.DbTestCase):
dhcp_opts = pxe_utils.dhcp_options_for_instance(task,
ipxe_enabled=True)
pxe_config_path = pxe_utils.get_pxe_config_file_path(
task.node.uuid)
task.node.uuid, ipxe_enabled=True)
task.node.properties['capabilities'] = 'boot_mode:bios'
task.driver.boot.prepare_instance(task)
self.assertFalse(get_image_info_mock.called)

View File

@ -779,7 +779,7 @@ class PXEBootTestCase(db_base.DbTestCase):
dhcp_opts = pxe_utils.dhcp_options_for_instance(task,
ipxe_enabled=True)
pxe_config_path = pxe_utils.get_pxe_config_file_path(
task.node.uuid)
task.node.uuid, ipxe_enabled=True)
task.node.properties['capabilities'] = 'boot_mode:bios'
task.driver.boot.prepare_instance(task)
self.assertFalse(get_image_info_mock.called)

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Fixes an issue that when ``ipxe`` interface is in use with
``[pxe]ipxe_enabled`` set to false, the PXE configuration is not handled
properly which prevents the machine from performing a successful iPXE boot.