summaryrefslogtreecommitdiff
path: root/ironic/common
diff options
context:
space:
mode:
authorRuby Loo <rloo@verizonmedia.com>2022-02-04 22:14:45 +0000
committerRuby Loo <rloo@verizonmedia.com>2022-03-03 15:28:09 +0000
commit09d8a94d5a9b3cabdf7fddc483821fd0df69e5ee (patch)
tree25f2959ed2fc31b864f4d4337fdb1f0201f23512 /ironic/common
parent4e6a3d52edc42b490c10c110dee5ea9e64fc3467 (diff)
downloadironic-09d8a94d5a9b3cabdf7fddc483821fd0df69e5ee.tar.gz
Anaconda deploy handles configdrive correctly
The anaconda deploy interface wasn't handling configdrive correctly. This fixes: - the code was incorrectly treating the config drive as a dict, whereas it could also be in iso6600 format, gzipped and base64-encoded. It is handled properly now. - kickstart commands that deal with the config drive were added to the end of the kickstart file. Which means that they are executed after an ironic API request is sent to ironic to indicate that the node has been provisioned and is ready to be rebooted. Which means that there is a possible race condition wrt these commands being completed before the node is powered off. This has been fixed by putting the API request at the end of the kickstart file. Also, a sync was added to ensure that all modifications are written to disk. - extra newlines ('\n') were incorrectly added to the user data content. This broke the content-type decoding and cloud-init was unable to proces them. The extra newlines have been removed. Change-Id: If00342a1bfa3e87b2094061b0e2b0b69de3a8a4f
Diffstat (limited to 'ironic/common')
-rw-r--r--ironic/common/kickstart_utils.py14
-rw-r--r--ironic/common/pxe_utils.py5
2 files changed, 11 insertions, 8 deletions
diff --git a/ironic/common/kickstart_utils.py b/ironic/common/kickstart_utils.py
index 519cb5326..433cf2390 100644
--- a/ironic/common/kickstart_utils.py
+++ b/ironic/common/kickstart_utils.py
@@ -55,7 +55,7 @@ def _get_config_drive_dict_from_iso(
iso_path=iso_file_path, outfp=b_buf
)
b_buf.seek(0)
- content = b"\n".join(b_buf.readlines()).decode('utf-8')
+ content = b"".join(b_buf.readlines()).decode('utf-8')
drive_dict[target_file_path] = content
@@ -113,8 +113,7 @@ def _fetch_config_drive_from_url(url):
"Can't download the configdrive content from '%(url)s'. "
"Reason: %(reason)s" %
{'url': url, 'reason': e})
- config_drive_iso = decode_and_extract_config_drive_iso(config_drive)
- return read_iso9600_config_drive(config_drive_iso)
+ return config_drive
def _write_config_drive_content(content, file_path):
@@ -152,10 +151,15 @@ def prepare_config_drive(task,
if not config_drive:
return ks_config_drive
- if not isinstance(config_drive, dict) and \
- ironic_utils.is_http_url(config_drive):
+ if ironic_utils.is_http_url(config_drive):
config_drive = _fetch_config_drive_from_url(config_drive)
+ if not isinstance(config_drive, dict):
+ # The config drive is in iso6600 format, gzipped and base-64-encoded.
+ # Convert it to a dict.
+ config_drive_iso = decode_and_extract_config_drive_iso(config_drive)
+ config_drive = read_iso9600_config_drive(config_drive_iso)
+
for key in sorted(config_drive.keys()):
target_path = os.path.join(config_drive_path, key)
ks_config_drive += _write_config_drive_content(
diff --git a/ironic/common/pxe_utils.py b/ironic/common/pxe_utils.py
index 8192cd458..c31eeed8c 100644
--- a/ironic/common/pxe_utils.py
+++ b/ironic/common/pxe_utils.py
@@ -957,6 +957,7 @@ def build_kickstart_config_options(task):
node.uuid
)
params['heartbeat_url'] = heartbeat_url
+ params['config_drive'] = ks_utils.prepare_config_drive(task)
return {'ks_options': params}
@@ -1067,6 +1068,7 @@ def validate_kickstart_template(ks_template):
"""
ks_options = {'liveimg_url': 'fake_image_url',
'agent_token': 'fake_token',
+ 'config_drive': '',
'heartbeat_url': 'fake_heartbeat_url'}
params = {'ks_options': ks_options}
try:
@@ -1185,9 +1187,6 @@ def prepare_instance_kickstart_config(task, image_info, anaconda_boot=False):
ks_options = build_kickstart_config_options(task)
kickstart_template = image_info['ks_template'][1]
ks_cfg = utils.render_template(kickstart_template, ks_options)
- ks_config_drive = ks_utils.prepare_config_drive(task)
- if ks_config_drive:
- ks_cfg = ks_cfg + ks_config_drive
utils.write_to_file(image_info['ks_cfg'][1], ks_cfg,
CONF.pxe.file_permission)