From 194d1e6cd3139004313b33076418a59257a62144 Mon Sep 17 00:00:00 2001 From: chunfuwen Date: Thu, 19 Sep 2024 01:21:25 -0400 Subject: [PATCH] Add new image type:vdh support in bootc image builder vdh is newly introduced support disk image type, and is only supported on upstream Signed-off-by: chunfuwen --- .../bootc_image_build_utils.py | 31 +++++++++++++++++++ .../bootc_disk_image_build.cfg | 12 ++++++- .../bootc_disk_image_install.cfg | 12 ++++++- .../bootc_disk_image_install.py | 10 +++++- 4 files changed, 62 insertions(+), 3 deletions(-) diff --git a/provider/bootc_image_builder/bootc_image_build_utils.py b/provider/bootc_image_builder/bootc_image_build_utils.py index 5d369fbd46..8e0cee1d37 100644 --- a/provider/bootc_image_builder/bootc_image_build_utils.py +++ b/provider/bootc_image_builder/bootc_image_build_utils.py @@ -838,6 +838,37 @@ def cleanup_aws_ami_and_snapshot(params): aws_utils.delete_aws_ami_snapshot_id(params) +def convert_vhd_to_qcow2(params): + """ + Convert vhd disk format into qcow2 + + @param params: one dictionary wrapping various parameter + """ + original_image_path = params.get('vm_disk_image_path') + converted_image_path = original_image_path.replace("vhd", "qcow2") + LOG.debug(f"converted vhd to qcow2 output is : {converted_image_path}") + + convert_cmd = f"qemu-img convert -p -f vpc -O qcow2 {original_image_path} {converted_image_path}" + process.run(convert_cmd, shell=True, verbose=True, ignore_status=False) + return converted_image_path + + +def untar_tgz_to_raw(params): + """ + extract image.tgz for GCP format to raw format:disk.raw + + @param params: one dictionary wrapping various parameter + """ + original_image_path = params.get('vm_disk_image_path') + untar_image_path = original_image_path.replace("tgz", "raw").replace("image", "disk") + tar_image_folder = os.path.dirname(original_image_path) + LOG.debug(f"untar image.tgz to gce output is : {untar_image_path}") + + tar_cmd = f"tar -xvzf {original_image_path} -C {converted_image_path}" + process.run(tar_cmd, shell=True, verbose=True, ignore_status=False) + return untar_image_path + + def get_baseurl_from_repo_file(repo_file_path): """ One method to get compose url from current repository file diff --git a/virttools/tests/cfg/bootc_image_builder/bootc_disk_image_build.cfg b/virttools/tests/cfg/bootc_image_builder/bootc_disk_image_build.cfg index 5bd0b929cd..ed740b17a9 100644 --- a/virttools/tests/cfg/bootc_image_builder/bootc_disk_image_build.cfg +++ b/virttools/tests/cfg/bootc_image_builder/bootc_disk_image_build.cfg @@ -60,7 +60,7 @@ container_url = "localhost/bootc:eln" local_container = "yes" build_container = "registry.stage.redhat.io/rhel9/rhel-bootc:rhel-9.4" - rhel_9.5_nightly_bib: + rhel_9.5_nightly_bib, upstream_bib: build_container = "registry.stage.redhat.io/rhel9/rhel-bootc:rhel-9.5" rhel_10.0_bib: build_container = "registry.stage.redhat.io/rhel10-beta/rhel-bootc:rhel-10.0-beta" @@ -158,3 +158,13 @@ disk_image_type = "raw" output_sub_folder = "image" output_name = "disk.raw" + - vhd: + disk_image_type = "vhd" + output_sub_folder = "vpc" + output_name = "disk.vhd" + only upstream_bib + - gce: + disk_image_type = "gce" + output_sub_folder = "gce" + output_name = "image.tgz" + only upstream_bib diff --git a/virttools/tests/cfg/bootc_image_builder/bootc_disk_image_install.cfg b/virttools/tests/cfg/bootc_image_builder/bootc_disk_image_install.cfg index 800f6f1fad..cb4329eef2 100644 --- a/virttools/tests/cfg/bootc_image_builder/bootc_disk_image_install.cfg +++ b/virttools/tests/cfg/bootc_image_builder/bootc_disk_image_install.cfg @@ -67,7 +67,7 @@ container_url = "localhost/bootc:eln" local_container = "yes" build_container = "registry.stage.redhat.io/rhel9/rhel-bootc:rhel-9.4" - rhel_9.5_nightly_bib: + rhel_9.5_nightly_bib, upstream_bib: build_container = "registry.stage.redhat.io/rhel9/rhel-bootc:rhel-9.5" fips_enable = "yes" rhel_10.0_bib: @@ -168,3 +168,13 @@ disk_image_type = "raw" output_sub_folder = "image" output_name = "disk.raw" + - vhd: + disk_image_type = "vhd" + output_sub_folder = "vpc" + output_name = "disk.vhd" + only upstream_bib + - gce: + disk_image_type = "gce" + output_sub_folder = "gce" + output_name = "image.tgz" + only upstream_bib diff --git a/virttools/tests/src/bootc_image_builder/bootc_disk_image_install.py b/virttools/tests/src/bootc_image_builder/bootc_disk_image_install.py index 419555403a..7f985f6ceb 100644 --- a/virttools/tests/src/bootc_image_builder/bootc_disk_image_install.py +++ b/virttools/tests/src/bootc_image_builder/bootc_disk_image_install.py @@ -45,6 +45,14 @@ def update_bib_env_info(params, test): params.update({'vm_disk_image_path': full_path_dest}) params.update({'vm_name_bootc': disk_name}) + if params.get("disk_image_type") == "vhd": + converted_image_from_vhd_qcow2 = bib_utils.convert_vhd_to_qcow2(params) + params.update({'vm_disk_image_path': converted_image_from_vhd_qcow2}) + + if params.get("disk_image_type") == "gce": + untar_raw_image = bib_utils.untar_tgz_to_raw(params) + params.update({'vm_disk_image_path': untar_raw_image}) + iso_install_path = os.path.join(libvirt_base_folder, f"{disk_name}_{firmware}.qcow2") params.update({'iso_install_path': iso_install_path}) cleanup_files.append(iso_install_path) @@ -128,7 +136,7 @@ def run(test, params, env): update_bib_env_info(params, test) if disk_image_type in ["vmdk"]: bib_utils.create_and_start_vmware_vm(params) - elif disk_image_type in ["qcow2", "raw", "anaconda-iso"]: + elif disk_image_type in ["qcow2", "raw", "anaconda-iso", "vhd"]: bib_utils.create_qemu_vm(params, env, test) elif disk_image_type in ["ami"]: if len(aws_config_dict) != 0: