diff options
author | Riccardo Pittau <elfosardo@gmail.com> | 2021-11-23 15:06:59 +0100 |
---|---|---|
committer | Riccardo Pittau <elfosardo@gmail.com> | 2022-03-14 12:30:50 +0100 |
commit | 7d1d2da0d17b86b49279389865787bdcfab64c93 (patch) | |
tree | 284167348033a92905d1d81b3d7279a14bf5eb98 /ironic/common/images.py | |
parent | 01dd06a17673ec5157dda2ecfc51feb9d2f8e5c2 (diff) | |
download | ironic-7d1d2da0d17b86b49279389865787bdcfab64c93.tar.gz |
Use pycdlib to extract deploy iso
Use pycdlib to extract the content of the deploy iso to get efiboot
and grub config.
Story: 2009704
Task: 44033
Change-Id: I62cdf2a09bc4233056799b64b7fdb87ad21b5bbd
Diffstat (limited to 'ironic/common/images.py')
-rw-r--r-- | ironic/common/images.py | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/ironic/common/images.py b/ironic/common/images.py index 9f771ca29..8652ba1fb 100644 --- a/ironic/common/images.py +++ b/ironic/common/images.py @@ -27,6 +27,7 @@ from ironic_lib import disk_utils from oslo_concurrency import processutils from oslo_log import log as logging from oslo_utils import fileutils +import pycdlib from ironic.common import exception from ironic.common.glance_service import service_utils as glance_utils @@ -72,14 +73,6 @@ def _create_root_fs(root_directory, files_info): shutil.copyfile(src_file, target_file) -def _umount_without_raise(mount_dir): - """Helper method to umount without raise.""" - try: - utils.umount(mount_dir) - except processutils.ProcessExecutionError: - pass - - def create_vfat_image(output_file, files_info=None, parameters=None, parameters_file='parameters.txt', fs_size_kib=100): """Creates the fat fs image on the desired file. @@ -299,7 +292,7 @@ def create_esp_image_for_uefi( # directory. if deploy_iso and not esp_image: uefi_path_info, e_img_rel_path, grub_rel_path = ( - _mount_deploy_iso(deploy_iso, mountdir)) + _get_deploy_iso_files(deploy_iso, mountdir)) grub_cfg = os.path.join(tmpdir, grub_rel_path) @@ -336,7 +329,7 @@ def create_esp_image_for_uefi( finally: if deploy_iso: - _umount_without_raise(mountdir) + shutil.rmtree(mountdir) # Generate and copy grub config file. grub_conf = _generate_cfg(kernel_params, @@ -622,7 +615,27 @@ def is_whole_disk_image(ctx, instance_info): return is_whole_disk_image -def _mount_deploy_iso(deploy_iso, mountdir): +def _extract_iso(extract_iso, extract_dir): + # NOTE(rpittau): we could probably just extract the files we need + # if we find them. Also we probably need to detect the correct iso + # type (UDF, RR, JOLIET). + iso = pycdlib.PyCdlib() + iso.open(extract_iso) + + for dirname, dirlist, filelist in iso.walk(iso_path='/'): + dir_path = dirname.lstrip('/') + for dir_iso in dirlist: + os.makedirs(os.path.join(extract_dir, dir_path, dir_iso)) + for file in filelist: + file_path = os.path.join(extract_dir, dirname, file) + iso.get_file_from_iso( + os.path.join(extract_dir, dir_path, file), + iso_path=file_path) + + iso.close() + + +def _get_deploy_iso_files(deploy_iso, mountdir): """This function opens up the deploy iso used for deploy. :param deploy_iso: path to the deploy iso where its @@ -641,9 +654,9 @@ def _mount_deploy_iso(deploy_iso, mountdir): grub_path = None try: - utils.mount(deploy_iso, mountdir, '-o', 'loop') - except processutils.ProcessExecutionError as e: - LOG.exception("mounting the deploy iso failed.") + _extract_iso(deploy_iso, mountdir) + except Exception as e: + LOG.exception("extracting the deploy iso failed.") raise exception.ImageCreationFailed(image_type='iso', error=e) try: @@ -658,14 +671,14 @@ def _mount_deploy_iso(deploy_iso, mountdir): mountdir) except (OSError, IOError) as e: LOG.exception("examining the deploy iso failed.") - _umount_without_raise(mountdir) + shutil.rmtree(mountdir) raise exception.ImageCreationFailed(image_type='iso', error=e) # check if the variables are assigned some values or not during # walk of the mountdir. if not (e_img_path and e_img_rel_path and grub_path and grub_rel_path): error = (_("Deploy iso didn't contain efiboot.img or grub.cfg")) - _umount_without_raise(mountdir) + shutil.rmtree(mountdir) raise exception.ImageCreationFailed(image_type='iso', error=error) uefi_path_info = {e_img_path: e_img_rel_path, |