Cleanup of remaining pxe focused is_ipxe_enabled

After this cleanup, only one use of is_ipxe_enabled remains
which is in the storage interface. That will be removed in
a separate patchset that I have been working on.

Change-Id: I625ac56122ac4dd17d0c9e7dacc4444301a88e75
Story: 1628069
This commit is contained in:
Julia Kreger 2018-10-19 11:35:38 -07:00
parent dd02698ad4
commit 38f6fff02e
6 changed files with 88 additions and 55 deletions

View File

@ -343,7 +343,7 @@ def create_ipxe_boot_script():
utils.write_to_file(bootfile_path, boot_script)
def clean_up_pxe_config(task):
def clean_up_pxe_config(task, ipxe_enabled=False):
"""Clean up the TFTP environment for the task's node.
:param task: A TaskManager instance.
@ -353,7 +353,6 @@ def clean_up_pxe_config(task):
is_uefi_boot_mode = (boot_mode_utils.get_boot_mode_for_deploy(task.node)
== 'uefi')
ipxe_enabled = is_ipxe_enabled(task)
if is_uefi_boot_mode and not ipxe_enabled:
api = dhcp_factory.DHCPFactory().provider
@ -641,11 +640,10 @@ def get_image_info(node, mode='deploy'):
node.uuid, d_info, mode=mode)
def build_deploy_pxe_options(task, pxe_info, mode='deploy'):
def build_deploy_pxe_options(task, pxe_info, mode='deploy',
ipxe_enabled=False):
pxe_opts = {}
node = task.node
# TODO(TheJulia): In the future this should become an argument
ipxe_enabled = is_ipxe_enabled(task)
kernel_label = '%s_kernel' % mode
ramdisk_label = '%s_ramdisk' % mode
for label, option in ((kernel_label, 'deployment_aki_path'),
@ -667,14 +665,14 @@ def build_deploy_pxe_options(task, pxe_info, mode='deploy'):
return pxe_opts
def build_instance_pxe_options(task, pxe_info):
def build_instance_pxe_options(task, pxe_info, ipxe_enabled=False):
pxe_opts = {}
node = task.node
for label, option in (('kernel', 'aki_path'),
('ramdisk', 'ari_path')):
if label in pxe_info:
if is_ipxe_enabled(task):
if ipxe_enabled:
# NOTE(pas-ha) do not use Swift TempURLs for kernel and
# ramdisk of user image when boot_option is not local,
# as this breaks instance reboot later when temp urls
@ -743,14 +741,16 @@ def build_pxe_config_options(task, pxe_info, service=False,
and ipxe_enabled):
pxe_options = get_volume_pxe_options(task)
else:
pxe_options = build_deploy_pxe_options(task, pxe_info, mode=mode)
pxe_options = build_deploy_pxe_options(task, pxe_info, mode=mode,
ipxe_enabled=ipxe_enabled)
# NOTE(pas-ha) we still must always add user image kernel and ramdisk
# info as later during switching PXE config to service mode the
# template will not be regenerated anew, but instead edited as-is.
# This can be changed later if/when switching PXE config will also use
# proper templating instead of editing existing files on disk.
pxe_options.update(build_instance_pxe_options(task, pxe_info))
pxe_options.update(build_instance_pxe_options(task, pxe_info,
ipxe_enabled=ipxe_enabled))
pxe_options.update(build_extra_pxe_options())
@ -922,11 +922,11 @@ class TFTPImageCache(image_cache.ImageCache):
cache_ttl=CONF.pxe.image_cache_ttl * 60)
def cache_ramdisk_kernel(task, pxe_info):
def cache_ramdisk_kernel(task, pxe_info, ipxe_enabled=False):
"""Fetch the necessary kernels and ramdisks for the instance."""
ctx = task.context
node = task.node
if is_ipxe_enabled(task):
if ipxe_enabled:
path = os.path.join(get_ipxe_root_dir(), node.uuid)
else:
path = os.path.join(get_root_dir(), node.uuid)
@ -937,7 +937,7 @@ def cache_ramdisk_kernel(task, pxe_info):
CONF.force_raw_images)
def clean_up_pxe_env(task, images_info):
def clean_up_pxe_env(task, images_info, ipxe_enabled=False):
"""Cleanup PXE environment of all the images in images_info.
Cleans up the PXE environment for the mentioned images in
@ -952,5 +952,5 @@ def clean_up_pxe_env(task, images_info):
path = images_info[label][1]
ironic_utils.unlink_without_raise(path)
clean_up_pxe_config(task)
clean_up_pxe_config(task, ipxe_enabled=ipxe_enabled)
TFTPImageCache().clean_up()

View File

@ -156,7 +156,8 @@ class iPXEBoot(pxe_base.PXEBaseMixin, base.BootInterface):
pxe_utils.get_instance_image_info(task, ipxe_enabled=True))
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(task, pxe_info,
ipxe_enabled=True)
pxe_options.update(ramdisk_params)
pxe_config_template = deploy_utils.get_pxe_config_template(node)
@ -177,7 +178,7 @@ class iPXEBoot(pxe_base.PXEBaseMixin, base.BootInterface):
pxe_info.pop(ramdisk_label, None)
if pxe_info:
pxe_utils.cache_ramdisk_kernel(task, pxe_info)
pxe_utils.cache_ramdisk_kernel(task, pxe_info, ipxe_enabled=True)
@METRICS.timer('iPXEBoot.prepare_instance')
def prepare_instance(self, task):
@ -201,7 +202,8 @@ class iPXEBoot(pxe_base.PXEBaseMixin, base.BootInterface):
if boot_option == "ramdisk":
instance_image_info = pxe_utils.get_instance_image_info(
task, ipxe_enabled=True)
pxe_utils.cache_ramdisk_kernel(task, instance_image_info)
pxe_utils.cache_ramdisk_kernel(task, instance_image_info,
ipxe_enabled=True)
if deploy_utils.is_iscsi_boot(task) or boot_option == "ramdisk":
pxe_utils.prepare_instance_pxe_config(
@ -217,7 +219,8 @@ class iPXEBoot(pxe_base.PXEBaseMixin, base.BootInterface):
# This is for the takeover scenario for active nodes.
instance_image_info = pxe_utils.get_instance_image_info(
task, ipxe_enabled=True)
pxe_utils.cache_ramdisk_kernel(task, instance_image_info)
pxe_utils.cache_ramdisk_kernel(task, instance_image_info,
ipxe_enabled=True)
# If it's going to PXE boot we need to update the DHCP server
dhcp_opts = pxe_utils.dhcp_options_for_instance(task,
@ -244,7 +247,7 @@ class iPXEBoot(pxe_base.PXEBaseMixin, base.BootInterface):
"from deployment mode to service (boot) mode "
"for node %(node)s. Booting the instance "
"from disk.", {"node": task.node.uuid})
pxe_utils.clean_up_pxe_config(task)
pxe_utils.clean_up_pxe_config(task, ipxe_enabled=True)
boot_device = boot_devices.DISK
else:
pxe_utils.build_service_pxe_config(task, instance_image_info,
@ -256,7 +259,7 @@ class iPXEBoot(pxe_base.PXEBaseMixin, base.BootInterface):
# PXE config files. They still need to be generated as part
# of the prepare() because the deployment does PXE boot the
# deploy ramdisk
pxe_utils.clean_up_pxe_config(task)
pxe_utils.clean_up_pxe_config(task, ipxe_enabled=True)
boot_device = boot_devices.DISK
# NOTE(pas-ha) do not re-set boot device on ACTIVE nodes

View File

@ -163,7 +163,8 @@ class PXEBoot(pxe_base.PXEBaseMixin, base.BootInterface):
pxe_info.update(pxe_utils.get_instance_image_info(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(
task, pxe_info, ipxe_enabled=ipxe_enabled)
pxe_options.update(ramdisk_params)
pxe_config_template = deploy_utils.get_pxe_config_template(node)
@ -184,7 +185,8 @@ class PXEBoot(pxe_base.PXEBaseMixin, base.BootInterface):
pxe_info.pop(ramdisk_label, None)
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)
@METRICS.timer('PXEBoot.prepare_instance')
def prepare_instance(self, task):
@ -207,7 +209,8 @@ class PXEBoot(pxe_base.PXEBaseMixin, base.BootInterface):
instance_image_info = {}
if boot_option == "ramdisk":
instance_image_info = pxe_utils.get_instance_image_info(task)
pxe_utils.cache_ramdisk_kernel(task, instance_image_info)
pxe_utils.cache_ramdisk_kernel(task, instance_image_info,
ipxe_enabled=CONF.pxe.ipxe_enabled)
if deploy_utils.is_iscsi_boot(task) or boot_option == "ramdisk":
pxe_utils.prepare_instance_pxe_config(
@ -222,7 +225,9 @@ class PXEBoot(pxe_base.PXEBaseMixin, base.BootInterface):
# Make sure that the instance kernel/ramdisk is cached.
# This is for the takeover scenario for active nodes.
instance_image_info = pxe_utils.get_instance_image_info(task)
pxe_utils.cache_ramdisk_kernel(task, instance_image_info)
pxe_utils.cache_ramdisk_kernel(
task, instance_image_info,
ipxe_enabled=CONF.pxe.ipxe_enabled)
# If it's going to PXE boot we need to update the DHCP server
dhcp_opts = pxe_utils.dhcp_options_for_instance(
@ -249,7 +254,8 @@ class PXEBoot(pxe_base.PXEBaseMixin, base.BootInterface):
"from deployment mode to service (boot) mode "
"for node %(node)s. Booting the instance "
"from disk.", {"node": task.node.uuid})
pxe_utils.clean_up_pxe_config(task)
pxe_utils.clean_up_pxe_config(
task, ipxe_enabled=CONF.pxe.ipxe_enabled)
boot_device = boot_devices.DISK
else:
pxe_utils.build_service_pxe_config(task, instance_image_info,
@ -261,7 +267,8 @@ class PXEBoot(pxe_base.PXEBaseMixin, base.BootInterface):
# PXE config files. They still need to be generated as part
# of the prepare() because the deployment does PXE boot the
# deploy ramdisk
pxe_utils.clean_up_pxe_config(task)
pxe_utils.clean_up_pxe_config(
task, ipxe_enabled=CONF.pxe.ipxe_enabled)
boot_device = boot_devices.DISK
# NOTE(pas-ha) do not re-set boot device on ACTIVE nodes

View File

@ -958,7 +958,7 @@ class TestPXEUtils(db_base.DbTestCase):
with task_manager.acquire(self.context, self.node.uuid) as task:
task.node.properties = properties
pxe_utils.clean_up_pxe_config(task)
pxe_utils.clean_up_pxe_config(task, ipxe_enabled=True)
ensure_calls = [
mock.call("/httpboot/pxelinux.cfg/%s"
@ -1697,6 +1697,6 @@ class CleanUpPxeEnvTestCase(db_base.DbTestCase):
with task_manager.acquire(self.context, self.node.uuid,
shared=True) as task:
pxe_utils.clean_up_pxe_env(task, image_info)
mock_pxe_clean.assert_called_once_with(task)
mock_pxe_clean.assert_called_once_with(task, ipxe_enabled=False)
mock_unlink.assert_any_call('deploy_kernel')
mock_cache.return_value.clean_up.assert_called_once_with()

View File

@ -272,21 +272,26 @@ class iPXEBootTestCase(db_base.DbTestCase):
self.assertFalse(mock_cache_r_k.called)
else:
mock_cache_r_k.assert_called_once_with(
task, {'kernel': 'b'})
task, {'kernel': 'b'},
ipxe_enabled=True)
mock_instance_img_info.assert_called_once_with(
task, ipxe_enabled=True)
elif not cleaning and mode == 'deploy':
mock_cache_r_k.assert_called_once_with(
task, {'deploy_kernel': 'a', 'deploy_ramdisk': 'r',
'kernel': 'b'})
task,
{'deploy_kernel': 'a', 'deploy_ramdisk': 'r',
'kernel': 'b'},
ipxe_enabled=True)
mock_instance_img_info.assert_called_once_with(
task, ipxe_enabled=True)
elif mode == 'deploy':
mock_cache_r_k.assert_called_once_with(
task, {'deploy_kernel': 'a', 'deploy_ramdisk': 'r'})
task, {'deploy_kernel': 'a', 'deploy_ramdisk': 'r'},
ipxe_enabled=True)
elif mode == 'rescue':
mock_cache_r_k.assert_called_once_with(
task, {'rescue_kernel': 'a', 'rescue_ramdisk': 'r'})
task, {'rescue_kernel': 'a', 'rescue_ramdisk': 'r'},
ipxe_enabled=True)
if uefi:
mock_pxe_config.assert_called_once_with(
task, {'foo': 'bar'}, CONF.pxe.uefi_pxe_config_template,
@ -552,7 +557,8 @@ class iPXEBootTestCase(db_base.DbTestCase):
get_image_info_mock.assert_called_once_with(
task, ipxe_enabled=True)
cache_mock.assert_called_once_with(task, image_info)
cache_mock.assert_called_once_with(task, image_info,
ipxe_enabled=True)
provider_mock.update_dhcp.assert_called_once_with(task, dhcp_opts)
switch_pxe_config_mock.assert_called_once_with(
pxe_config_path, "30212642-09d3-467f-8e09-21685826ab50",
@ -593,7 +599,8 @@ class iPXEBootTestCase(db_base.DbTestCase):
get_image_info_mock.assert_called_once_with(
task, ipxe_enabled=True)
cache_mock.assert_called_once_with(task, image_info)
cache_mock.assert_called_once_with(task, image_info,
ipxe_enabled=True)
provider_mock.update_dhcp.assert_called_once_with(task, dhcp_opts)
create_pxe_config_mock.assert_called_once_with(
task, mock.ANY, CONF.pxe.pxe_config_template,
@ -627,7 +634,8 @@ class iPXEBootTestCase(db_base.DbTestCase):
get_image_info_mock.assert_called_once_with(
task, ipxe_enabled=True)
cache_mock.assert_called_once_with(task, image_info)
cache_mock.assert_called_once_with(task, image_info,
ipxe_enabled=True)
provider_mock.update_dhcp.assert_called_once_with(task, dhcp_opts)
self.assertFalse(switch_pxe_config_mock.called)
self.assertFalse(set_boot_device_mock.called)
@ -655,10 +663,10 @@ class iPXEBootTestCase(db_base.DbTestCase):
task.driver.boot.prepare_instance(task)
get_image_info_mock.assert_called_once_with(
task, ipxe_enabled=True)
cache_mock.assert_called_once_with(task, {})
cache_mock.assert_called_once_with(task, {}, ipxe_enabled=True)
provider_mock.update_dhcp.assert_called_once_with(task, dhcp_opts)
self.assertTrue(log_mock.called)
clean_up_pxe_mock.assert_called_once_with(task)
clean_up_pxe_mock.assert_called_once_with(task, ipxe_enabled=True)
set_boot_device_mock.assert_called_once_with(
task, boot_devices.DISK, persistent=True)
@ -722,7 +730,8 @@ class iPXEBootTestCase(db_base.DbTestCase):
task.node.instance_info = instance_info
task.node.save()
task.driver.boot.prepare_instance(task)
clean_up_pxe_config_mock.assert_called_once_with(task)
clean_up_pxe_config_mock.assert_called_once_with(
task, ipxe_enabled=True)
set_boot_device_mock.assert_called_once_with(task,
boot_devices.DISK,
persistent=True)
@ -737,7 +746,8 @@ class iPXEBootTestCase(db_base.DbTestCase):
task.node.instance_info = instance_info
task.node.save()
task.driver.boot.prepare_instance(task)
clean_up_pxe_config_mock.assert_called_once_with(task)
clean_up_pxe_config_mock.assert_called_once_with(
task, ipxe_enabled=True)
driver_info = task.node.driver_info
driver_info['force_persistent _boot_device'] = True
task.node.driver_info = driver_info
@ -757,7 +767,8 @@ class iPXEBootTestCase(db_base.DbTestCase):
task.node.instance_info = instance_info
task.node.save()
task.driver.boot.prepare_instance(task)
clean_up_pxe_config_mock.assert_called_once_with(task)
clean_up_pxe_config_mock.assert_called_once_with(
task, ipxe_enabled=True)
self.assertFalse(set_boot_device_mock.called)
@mock.patch.object(pxe_utils, 'clean_up_pxe_env', autospec=True)

View File

@ -271,22 +271,26 @@ class PXEBootTestCase(db_base.DbTestCase):
else:
mock_cache_r_k.assert_called_once_with(
task,
{'kernel': 'b'})
{'kernel': 'b'},
ipxe_enabled=CONF.pxe.ipxe_enabled)
mock_instance_img_info.assert_called_once_with(task)
elif not cleaning and mode == 'deploy':
mock_cache_r_k.assert_called_once_with(
task,
{'deploy_kernel': 'a', 'deploy_ramdisk': 'r',
'kernel': 'b'})
'kernel': 'b'},
ipxe_enabled=CONF.pxe.ipxe_enabled)
mock_instance_img_info.assert_called_once_with(task)
elif mode == 'deploy':
mock_cache_r_k.assert_called_once_with(
task,
{'deploy_kernel': 'a', 'deploy_ramdisk': 'r'})
{'deploy_kernel': 'a', 'deploy_ramdisk': 'r'},
ipxe_enabled=CONF.pxe.ipxe_enabled)
elif mode == 'rescue':
mock_cache_r_k.assert_called_once_with(
task,
{'rescue_kernel': 'a', 'rescue_ramdisk': 'r'})
{'rescue_kernel': 'a', 'rescue_ramdisk': 'r'},
ipxe_enabled=CONF.pxe.ipxe_enabled)
if uefi:
mock_pxe_config.assert_called_once_with(
task, {'foo': 'bar'}, CONF.pxe.uefi_pxe_config_template,
@ -557,7 +561,8 @@ class PXEBootTestCase(db_base.DbTestCase):
get_image_info_mock.assert_called_once_with(
task)
cache_mock.assert_called_once_with(task, image_info)
cache_mock.assert_called_once_with(
task, image_info, ipxe_enabled=CONF.pxe.ipxe_enabled)
provider_mock.update_dhcp.assert_called_once_with(task, dhcp_opts)
switch_pxe_config_mock.assert_called_once_with(
pxe_config_path, "30212642-09d3-467f-8e09-21685826ab50",
@ -599,7 +604,7 @@ class PXEBootTestCase(db_base.DbTestCase):
get_image_info_mock.assert_called_once_with(
task)
cache_mock.assert_called_once_with(
task, image_info)
task, image_info, ipxe_enabled=CONF.pxe.ipxe_enabled)
provider_mock.update_dhcp.assert_called_once_with(task, dhcp_opts)
create_pxe_config_mock.assert_called_once_with(
task, mock.ANY, CONF.pxe.pxe_config_template,
@ -632,7 +637,8 @@ class PXEBootTestCase(db_base.DbTestCase):
task.driver.boot.prepare_instance(task)
get_image_info_mock.assert_called_once_with(task)
cache_mock.assert_called_once_with(task, image_info)
cache_mock.assert_called_once_with(
task, image_info, ipxe_enabled=CONF.pxe.ipxe_enabled)
provider_mock.update_dhcp.assert_called_once_with(task, dhcp_opts)
self.assertFalse(switch_pxe_config_mock.called)
self.assertFalse(set_boot_device_mock.called)
@ -658,10 +664,11 @@ class PXEBootTestCase(db_base.DbTestCase):
task.driver.boot.prepare_instance(task)
get_image_info_mock.assert_called_once_with(task)
cache_mock.assert_called_once_with(
task, {})
task, {}, ipxe_enabled=CONF.pxe.ipxe_enabled)
provider_mock.update_dhcp.assert_called_once_with(task, dhcp_opts)
self.assertTrue(log_mock.called)
clean_up_pxe_mock.assert_called_once_with(task)
clean_up_pxe_mock.assert_called_once_with(
task, ipxe_enabled=CONF.pxe.ipxe_enabled)
set_boot_device_mock.assert_called_once_with(
task, boot_devices.DISK, persistent=True)
@ -725,7 +732,8 @@ class PXEBootTestCase(db_base.DbTestCase):
task.node.instance_info = instance_info
task.node.save()
task.driver.boot.prepare_instance(task)
clean_up_pxe_config_mock.assert_called_once_with(task)
clean_up_pxe_config_mock.assert_called_once_with(
task, ipxe_enabled=CONF.pxe.ipxe_enabled)
set_boot_device_mock.assert_called_once_with(task,
boot_devices.DISK,
persistent=True)
@ -740,7 +748,8 @@ class PXEBootTestCase(db_base.DbTestCase):
task.node.instance_info = instance_info
task.node.save()
task.driver.boot.prepare_instance(task)
clean_up_pxe_config_mock.assert_called_once_with(task)
clean_up_pxe_config_mock.assert_called_once_with(
task, ipxe_enabled=CONF.pxe.ipxe_enabled)
driver_info = task.node.driver_info
driver_info['force_persistent _boot_device'] = True
task.node.driver_info = driver_info
@ -760,7 +769,8 @@ class PXEBootTestCase(db_base.DbTestCase):
task.node.instance_info = instance_info
task.node.save()
task.driver.boot.prepare_instance(task)
clean_up_pxe_config_mock.assert_called_once_with(task)
clean_up_pxe_config_mock.assert_called_once_with(
task, ipxe_enabled=CONF.pxe.ipxe_enabled)
self.assertFalse(set_boot_device_mock.called)
@mock.patch.object(manager_utils, 'node_set_boot_device', autospec=True)
@ -793,7 +803,8 @@ class PXEBootTestCase(db_base.DbTestCase):
task.driver.boot.prepare_instance(task)
get_image_info_mock.assert_called_once_with(task)
cache_mock.assert_called_once_with(task, image_info)
cache_mock.assert_called_once_with(
task, image_info, CONF.pxe.ipxe_enabled)
provider_mock.update_dhcp.assert_called_once_with(task, dhcp_opts)
if config_file_exits:
self.assertFalse(create_pxe_config_mock.called)
@ -889,7 +900,7 @@ class PXERamdiskDeployTestCase(db_base.DbTestCase):
get_image_info_mock.assert_called_once_with(task)
cache_mock.assert_called_once_with(
task, image_info)
task, image_info, ipxe_enabled=CONF.pxe.ipxe_enabled)
provider_mock.update_dhcp.assert_called_once_with(task, dhcp_opts)
switch_pxe_config_mock.assert_called_once_with(
pxe_config_path, None,
@ -916,7 +927,8 @@ class PXERamdiskDeployTestCase(db_base.DbTestCase):
with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertIsNone(task.driver.deploy.deploy(task))
mock_image_info.assert_called_once_with(task)
mock_cache.assert_called_once_with(task, image_info)
mock_cache.assert_called_once_with(
task, image_info, ipxe_enabled=CONF.pxe.ipxe_enabled)
self.assertFalse(mock_warning.called)
i_info['configdrive'] = 'meow'
self.node.instance_info = i_info