From 99a6dfe8adb838c711f36971ca931727dc51ffdb Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Mon, 11 Mar 2024 13:47:19 -0700 Subject: [PATCH] Kiwi: translate virtualbox and azure productmd formats As discussed in https://pagure.io/releng/failed-composes/issue/6047#comment-899622 the list of 'acceptable' types and formats (in productmd terms) is locked down in productmd, we cannot just 'declare' new formats in pungi as we kinda wound up doing by adding these Kiwi extensions to the EXTENSIONS dict in image_build phase. So instead, let's return the image_build phase to the way it was, and add an additional layer of handling in kiwibuild phase for these awkward cases, which 'translates' the file suffix to a format productmd knows about already. This is actually how we would rather behave anyway, because a Kiwi-produced `vagrant.libvirt.box` file really is the same kind of thing as an ImageFactory-produced `vagrant-libvirt.box` file; we want them to have compatible metadata, we don't want them to look like different things. Merges: https://pagure.io/pungi/pull-request/1740 Signed-off-by: Adam Williamson (cherry picked from commit 8fb694f000848a90b51ec17294375fd13e07733b) --- pungi/phases/image_build.py | 6 +++--- pungi/phases/kiwibuild.py | 21 ++++++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/pungi/phases/image_build.py b/pungi/phases/image_build.py index c5b98606..cb76c1aa 100644 --- a/pungi/phases/image_build.py +++ b/pungi/phases/image_build.py @@ -34,12 +34,12 @@ EXTENSIONS = { "rhevm-ova": ["rhevm.ova"], "tar-gz": ["tar.gz"], "vagrant-hyperv": ["vagrant-hyperv.box"], - "vagrant-libvirt": ["vagrant-libvirt.box", "vagrant.libvirt.box"], - "vagrant-virtualbox": ["vagrant-virtualbox.box", "vagrant.virtualbox.box"], + "vagrant-libvirt": ["vagrant-libvirt.box"], + "vagrant-virtualbox": ["vagrant-virtualbox.box"], "vagrant-vmware-fusion": ["vagrant-vmware-fusion.box"], "vdi": ["vdi"], "vmdk": ["vmdk"], - "vpc": ["vhd", "vhdfixed"], + "vpc": ["vhd"], "vhd-compressed": ["vhd.gz", "vhd.xz"], "vsphere-ova": ["vsphere.ova"], } diff --git a/pungi/phases/kiwibuild.py b/pungi/phases/kiwibuild.py index c065b4aa..328a8bb3 100644 --- a/pungi/phases/kiwibuild.py +++ b/pungi/phases/kiwibuild.py @@ -11,6 +11,12 @@ from ..linker import Linker from ..wrappers import kojiwrapper from .image_build import EXTENSIONS +KIWIEXTENSIONS = [ + ("vhd-compressed", ["vhdfixed.xz"], "vhd.xz"), + ("vagrant-libvirt", ["vagrant.libvirt.box"], "vagrant-libvirt.box"), + ("vagrant-virtualbox", ["vagrant.virtualbox.box"], "vagrant-virtualbox.box"), +] + class KiwiBuildPhase( base.PhaseLoggerMixin, base.ImageConfigMixin, base.ConfigGuardedPhase @@ -158,9 +164,9 @@ class RunKiwiBuildThread(WorkerThread): for arch, paths in paths.items(): for path in paths: - type_, suffix = _find_suffix(path) - if not suffix: - # Path doesn't match any know type. + type_, format_ = _find_type_and_format(path) + if not format_: + # Path doesn't match any known type. continue # image_dir is absolute path to which the image should be copied. @@ -186,7 +192,7 @@ class RunKiwiBuildThread(WorkerThread): # Get the manifest type from the config if supplied, otherwise we # determine the manifest type based on the koji output img.type = type_ - img.format = suffix + img.format = format_ img.path = os.path.join(rel_image_dir, filename) img.mtime = util.get_mtime(image_dest) img.size = util.get_file_size(image_dest) @@ -202,9 +208,14 @@ class RunKiwiBuildThread(WorkerThread): self.pool.log_info("[DONE ] %s (task id: %s)" % (msg, task_id)) -def _find_suffix(path): +def _find_type_and_format(path): for type_, suffixes in EXTENSIONS.items(): for suffix in suffixes: if path.endswith(suffix): return type_, suffix + # these are our kiwi-exclusive mappings for images whose extensions + # aren't quite the same as imagefactory + for type_, suffixes, format_ in KIWIEXTENSIONS: + if any(path.endswith(suffix) for suffix in suffixes): + return type_, format_ return None, None