Skip to content

Commit af48b61

Browse files
committed
AWS: add fallback for build_info.version
This commit adds a fallback for loading the `version` from an existing AMI whenever such information is not present in the `push_item.build`. With this change it will look for the `push_item.build_info.version` whenever the `push_item.build` is not properly set, which may happen when using a staging structure to load an existing AMI. Signed-off-by: Jonathan Gangi <jgangi@redhat.com> Assisted-by: Cursor/Gemini
1 parent 7336dcd commit af48b61

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/pubtools/_marketplacesvm/cloud_providers/aws.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,10 @@ def _upload(
407407
tags.update(custom_tags)
408408

409409
if push_item.src.startswith("ami"):
410-
tags["version"] = push_item.build.split("-")[2]
410+
version = (
411+
push_item.build.split("-")[2] if push_item.build else push_item.build_info.version
412+
)
413+
tags["version"] = version
411414
tags["nvra"] = (
412415
f"{binfo.name}-{tags['version']}-{binfo.release}.{push_item.release.arch}" # noqa: E501
413416
)

tests/cloud_providers/test_provider_aws.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,38 @@ def test_upload_of_rhcos_image(
282282
)
283283

284284

285+
def test_upload_of_rhcos_image_without_build(
286+
aws_rhcos_push_item: AmiPushItem,
287+
fake_aws_provider: AWSProvider,
288+
):
289+
push_item = evolve(aws_rhcos_push_item, build=None)
290+
binfo = push_item.build_info
291+
292+
tags = {
293+
"arch": push_item.release.arch,
294+
"buildid": str(push_item.build_info.id),
295+
"name": push_item.build_info.name,
296+
"nvra": f"{binfo.name}-{binfo.version}-{binfo.release}.{push_item.release.arch}",
297+
"release": push_item.build_info.release,
298+
"version": binfo.version,
299+
}
300+
301+
fake_aws_provider.upload_svc_partial.return_value.get_image_from_ami_catalog.return_value = (
302+
FakeImageResp()
303+
)
304+
fake_aws_provider.upload_svc_partial.return_value.copy_ami.return_value = {
305+
"ImageId": "fake-ami-02"
306+
}
307+
fake_aws_provider.upload_svc_partial.return_value.get_image_by_name.return_value = None
308+
fake_aws_provider.upload_svc_partial.return_value.get_image_by_id.return_value = "test_image"
309+
310+
_, result = fake_aws_provider.upload(push_item)
311+
assert result.id == "fake-ami-02"
312+
fake_aws_provider.upload_svc_partial.return_value.tag_image.assert_called_once_with(
313+
"test_image", tags
314+
)
315+
316+
285317
def test_upload_of_rhcos_image_not_found(
286318
aws_rhcos_push_item: AmiPushItem,
287319
fake_aws_provider: AWSProvider,

0 commit comments

Comments
 (0)