Skip to content

Commit

Permalink
builder: map koji api image types to cloud ones
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gicmo committed Feb 10, 2022
1 parent a82ac3b commit 58f45b8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
21 changes: 21 additions & 0 deletions plugins/builder/osbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@

API_BASE = "api/image-builder-composer/v2/"

# For compatability 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
Expand Down Expand Up @@ -497,6 +505,15 @@ def make_repos_for_user(self, repos):
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
Expand Down Expand Up @@ -552,6 +569,7 @@ def handler(self, name, version, distro, image_types, target, arches, opts):
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,
Expand Down Expand Up @@ -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:
Expand Down
20 changes: 20 additions & 0 deletions test/unit/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,26 @@ def test_compose_no_manifest(self):
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
Expand Down

0 comments on commit 58f45b8

Please sign in to comment.