Set correct initrd_filename for iPXE when using Swift

iPXE derives its "file names" from the last component of the URL path.
In case of the conductor's local server it's {mode}_{component} where
mode = deploy/rescue and component = kernel/ramdisk. However, in case
of Swift/Ceph, the last component will be different. This patch accounts
for it.

Change-Id: I7ba5545032069509a9c302abe1c21537ccb5ec8a
(cherry picked from commit c975eaa8c6)
This commit is contained in:
Dmitry Tantsur 2022-02-10 18:11:15 +01:00
parent 78703943c9
commit e296ec97a7
3 changed files with 20 additions and 5 deletions

View File

@ -18,6 +18,7 @@ import copy
import os
import shutil
import tempfile
from urllib import parse as urlparse
from ironic_lib import utils as ironic_utils
import jinja2
@ -741,6 +742,7 @@ def build_deploy_pxe_options(task, pxe_info, mode='deploy',
node = task.node
kernel_label = '%s_kernel' % mode
ramdisk_label = '%s_ramdisk' % mode
initrd_filename = ramdisk_label
for label, option in ((kernel_label, 'deployment_aki_path'),
(ramdisk_label, 'deployment_ari_path')):
if ipxe_enabled:
@ -749,6 +751,10 @@ def build_deploy_pxe_options(task, pxe_info, mode='deploy',
and service_utils.is_glance_image(image_href)):
pxe_opts[option] = images.get_temp_url_for_glance_image(
task.context, image_href)
if label == ramdisk_label:
path = urlparse.urlparse(pxe_opts[option]).path.strip('/')
if path:
initrd_filename = path.split('/')[-1]
else:
pxe_opts[option] = '/'.join([CONF.deploy.http_url, node.uuid,
label])
@ -756,7 +762,7 @@ def build_deploy_pxe_options(task, pxe_info, mode='deploy',
pxe_opts[option] = os.path.relpath(pxe_info[label][1],
CONF.pxe.tftp_root)
if ipxe_enabled:
pxe_opts['initrd_filename'] = ramdisk_label
pxe_opts['initrd_filename'] = initrd_filename
return pxe_opts

View File

@ -1864,9 +1864,10 @@ class iPXEBuildConfigOptionsTestCase(db_base.DbTestCase):
self.config(ipxe_use_swift=True, group='pxe')
glance = mock.Mock()
glance_mock.return_value = glance
glance.swift_temp_url.side_effect = [
pxe_kernel, pxe_ramdisk] = [
'swift_kernel', 'swift_ramdisk']
glance.swift_temp_url.side_effect = [pxe_kernel, pxe_ramdisk] = [
'http://example.com/account/swift_kernel',
'http://example.com/account/swift_ramdisk'
]
image_info = {
kernel_label: (uuidutils.generate_uuid(),
os.path.join(root_dir,
@ -1877,6 +1878,7 @@ class iPXEBuildConfigOptionsTestCase(db_base.DbTestCase):
self.node.uuid,
ramdisk_label))
}
expected_initrd_filename = 'swift_ramdisk'
else:
pxe_kernel = os.path.join(http_url, self.node.uuid,
kernel_label)
@ -1892,6 +1894,7 @@ class iPXEBuildConfigOptionsTestCase(db_base.DbTestCase):
self.node.uuid,
ramdisk_label))
}
expected_initrd_filename = ramdisk_label
kernel = os.path.join(http_url, self.node.uuid, 'kernel')
ramdisk = os.path.join(http_url, self.node.uuid, 'ramdisk')
@ -1926,7 +1929,7 @@ class iPXEBuildConfigOptionsTestCase(db_base.DbTestCase):
'ipxe_timeout': ipxe_timeout_in_ms,
'ari_path': ramdisk,
'aki_path': kernel,
'initrd_filename': ramdisk_label,
'initrd_filename': expected_initrd_filename,
}
if mode == 'rescue':

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Fixes the ``initrd`` kernel parameter when booting ramdisk directly from
Swift/RadosGW using iPXE. Previously it was always ``deploy_ramdisk``,
even when the actual file name is different.