summaryrefslogtreecommitdiff
path: root/ironic/common
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2022-03-12 04:06:41 +0000
committerGerrit Code Review <review@openstack.org>2022-03-12 04:06:41 +0000
commit01dd06a17673ec5157dda2ecfc51feb9d2f8e5c2 (patch)
treea656a006f8b4057b1658fd2553bee332e1e9d0b1 /ironic/common
parent1d1cfbc1af8ae67613d085849508e31faf14a7d7 (diff)
parentab68c9d88b76e4ff83f9dffddcc204676fdb50d5 (diff)
downloadironic-01dd06a17673ec5157dda2ecfc51feb9d2f8e5c2.tar.gz
Merge "Fix rebuilds using anaconda deploy interface"
Diffstat (limited to 'ironic/common')
-rw-r--r--ironic/common/pxe_utils.py73
1 files changed, 42 insertions, 31 deletions
diff --git a/ironic/common/pxe_utils.py b/ironic/common/pxe_utils.py
index c31eeed8c..42d860f8d 100644
--- a/ironic/common/pxe_utils.py
+++ b/ironic/common/pxe_utils.py
@@ -668,16 +668,22 @@ def get_instance_image_info(task, ipxe_enabled=False):
return image_info
- labels = ('kernel', 'ramdisk')
image_properties = None
d_info = deploy_utils.get_image_instance_info(node)
+
+ def _get_image_properties():
+ nonlocal image_properties
+ if not image_properties:
+ glance_service = service.GlanceImageService(context=ctx)
+ image_properties = glance_service.show(
+ d_info['image_source'])['properties']
+
+ labels = ('kernel', 'ramdisk')
if not (i_info.get('kernel') and i_info.get('ramdisk')):
# NOTE(rloo): If both are not specified in instance_info
# we won't use any of them. We'll use the values specified
# with the image, which we assume have been set.
- glance_service = service.GlanceImageService(context=ctx)
- image_properties = glance_service.show(
- d_info['image_source'])['properties']
+ _get_image_properties()
for label in labels:
i_info[label] = str(image_properties[label + '_id'])
node.instance_info = i_info
@@ -689,36 +695,41 @@ def get_instance_image_info(task, ipxe_enabled=False):
# ks_template: anaconda kickstart template
# ks_cfg - rendered ks_template
anaconda_labels = ('stage2', 'ks_template', 'ks_cfg')
- if not i_info.get('stage2') or not i_info.get('ks_template'):
- if not image_properties:
- glance_service = service.GlanceImageService(context=ctx)
- image_properties = glance_service.show(
- d_info['image_source'])['properties']
- if not i_info.get('ks_template'):
- # ks_template is an optional property on the image
- if 'ks_template' not in image_properties:
- i_info['ks_template'] = CONF.anaconda.default_ks_template
- else:
- i_info['ks_template'] = str(
- image_properties['ks_template'])
- if not i_info.get('stage2'):
+ # NOTE(rloo): We save stage2 & ks_template values in case they
+ # are changed by the user after we start using them and to
+ # prevent re-computing them again.
+ if not node.driver_internal_info.get('stage2'):
+ if i_info.get('stage2'):
+ node.set_driver_internal_info('stage2', i_info['stage2'])
+ else:
+ _get_image_properties()
if 'stage2_id' not in image_properties:
- msg = ("'stage2_id' property is missing from the OS image "
- "%s. The anaconda deploy interface requires this "
- "to be set with the OS image or in instance_info. "
- % d_info['image_source'])
+ msg = (_("'stage2_id' is missing from the properties of "
+ "the OS image %s. The anaconda deploy interface "
+ "requires this to be set with the OS image or "
+ "in instance_info['stage2']. ") %
+ d_info['image_source'])
raise exception.ImageUnacceptable(msg)
else:
- i_info['stage2'] = str(image_properties['stage2_id'])
- # NOTE(rloo): This is internally generated; cannot be specified.
- i_info['ks_cfg'] = ''
-
- node.instance_info = i_info
- node.save()
+ node.set_driver_internal_info(
+ 'stage2', str(image_properties['stage2_id']))
+ if i_info.get('ks_template'):
+ node.set_driver_internal_info('ks_template',
+ i_info['ks_template'])
+ else:
+ _get_image_properties()
+ # ks_template is an optional property on the image
+ if 'ks_template' not in image_properties:
+ node.set_driver_internal_info(
+ 'ks_template', CONF.anaconda.default_ks_template)
+ else:
+ node.set_driver_internal_info(
+ 'ks_template', str(image_properties['ks_template']))
+ node.save()
for label in labels + anaconda_labels:
image_info[label] = (
- i_info[label],
+ i_info.get(label) or node.driver_internal_info.get(label, ''),
get_file_path_from_label(node.uuid, root_dir, label)
)
@@ -1116,9 +1127,9 @@ def validate_kickstart_file(ks_cfg):
'ksvalidator', ks_file.name, check_on_exit=[0], attempts=1
)
except processutils.ProcessExecutionError as e:
- msg = _(("The kickstart file generated does not pass validation. "
+ msg = (_("The kickstart file generated does not pass validation. "
"The ksvalidator tool returned the following error: %s") %
- (e))
+ e)
raise exception.InvalidKickstartFile(msg)
@@ -1214,7 +1225,7 @@ def cache_ramdisk_kernel(task, pxe_info, ipxe_enabled=False):
path = os.path.join(CONF.pxe.tftp_root, node.uuid)
ensure_tree(path)
# anaconda deploy will have 'stage2' as one of the labels in pxe_info dict
- if 'stage2' in pxe_info.keys():
+ if 'stage2' in pxe_info:
# stage2 will be stored in ipxe http directory so make sure the
# directory exists.
file_path = get_file_path_from_label(node.uuid,