From 47af69254cc0fd86bfe1b0769e6ea579674f157e Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Thu, 10 Feb 2022 12:18:09 +0000 Subject: [PATCH] builder: map koji api image types to cloud ones Map the image types used by the koji API to the image types used by the cloud api. This should allow for a smooth transition when the plugin is upgraded, i.e. the pungi configuration can be used unmodified. After all the plugins are upgraded the pungi config should be changed to use the native image types and then this mapping could be removed again. --- plugins/builder/osbuild.py | 21 +++++++++++++++++++++ test/unit/test_builder.py | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/plugins/builder/osbuild.py b/plugins/builder/osbuild.py index a0eb446..bec9b51 100644 --- a/plugins/builder/osbuild.py +++ b/plugins/builder/osbuild.py @@ -42,6 +42,14 @@ DEFAULT_CONFIG_FILES = [ API_BASE = "api/image-builder-composer/v2/" +# For compatibility reasons we support the image types used by the +# koji api. +KOJIAPI_IMAGE_TYPES = { + "qcow2": "guest-image", + "ec2": "aws-rhui", + "ec2-ha": "aws-ha-rhui", + "ec2-sap": "aws-sap-rhui", +} # The following classes are a implementation of osbuild composer's # cloud API. It is based on the corresponding OpenAPI specification @@ -497,6 +505,15 @@ class OSBuildImage(BaseTaskHandler): self.logger.debug("user repo override: %s", str(repos)) return [Repository(r) for r in repos] + def map_koji_api_image_type(self, image_type: str) -> str: + mapped = KOJIAPI_IMAGE_TYPES.get(image_type) + if not mapped: + return image_type + + self.logger.debug("mapped koji api image type: '%s' -> '%s'", + image_type, mapped) + return mapped + def tag_build(self, tag, build_id): args = [ tag, # tag id @@ -552,6 +569,7 @@ class OSBuildImage(BaseTaskHandler): nvr.release = self.session.getNextRelease(nvr.as_dict()) # Arches and image types + image_types = [self.map_koji_api_image_type(i) for i in image_types] ireqs = [ImageRequest(a, i, repos) for a in arches for i in image_types] self.logger.debug("Creating compose: %s (%s)\n koji: %s\n images: %s", nvr, distro, self.koji_url, @@ -620,6 +638,9 @@ def compose_cmd(client: Client, args): nvr = NVR(args.name, args.version, args.release) images = [] formats = args.format or ["guest-image"] + formats = [ + KOJIAPI_IMAGE_TYPES.get(f, f) for f in formats + ] repos = [Repository(url) for url in args.repo] for fmt in formats: for arch in args.arch: diff --git a/test/unit/test_builder.py b/test/unit/test_builder.py index 952811e..aeba73d 100644 --- a/test/unit/test_builder.py +++ b/test/unit/test_builder.py @@ -716,6 +716,26 @@ class TestBuilderPlugin(PluginTest): with self.assertRaises(AssertionError): self.uploads.assert_upload("x86_64-image_type.manifest.json") + @httpretty.activate + def test_kojiapi_image_types(self): + # Simulate api requests with koji api image types + session = self.mock_session() + handler = self.make_handler(session=session) + + url = self.plugin.DEFAULT_COMPOSER_URL + composer = MockComposer(url) + composer.httpretty_regsiter() + + for it in ("qcow2", "ec2", "ec2-ha", "ec2-sap"): + args = ["name", "version", "distro", + [it], + "fedora-candidate", + composer.architectures, + {"skip_tag": True}] + + res = handler.handler(*args) + assert res, "invalid compose result" + @httpretty.activate def test_skip_tag(self): # Simulate a successful compose, where the tagging