Skip to content

Commit f2b289d

Browse files
committed
Merge remote-tracking branch 'origin/master' into deps/pip-compile
2 parents affd43e + fd124d6 commit f2b289d

File tree

10 files changed

+266
-5
lines changed

10 files changed

+266
-5
lines changed

CHANGELOG.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
- n/a
1111

12+
## [2.44.0] - 2024-04-08
13+
14+
### Added
15+
16+
- Introduced `VMIPushItem.marketplace_name`
17+
- Added support for ART/rhcos koji builds
18+
1219
## [2.43.1] - 2024-02-29
1320

1421
### Fixed
@@ -489,7 +496,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
489496

490497
- Initial stable release of project
491498

492-
[Unreleased]: https://github.com/release-engineering/pushsource/compare/v2.43.1...HEAD
499+
[Unreleased]: https://github.com/release-engineering/pushsource/compare/v2.44.0...HEAD
500+
[2.44.0]: https://github.com/release-engineering/pushsource/compare/v2.43.1...v2.44.0
493501
[2.43.1]: https://github.com/release-engineering/pushsource/compare/v2.43.0...v2.43.1
494502
[2.43.0]: https://github.com/release-engineering/pushsource/compare/v2.42.0...v2.43.0
495503
[2.42.0]: https://github.com/release-engineering/pushsource/compare/v2.41.0...v2.42.0

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def get_requirements():
2121

2222
setup(
2323
name="pushsource",
24-
version="2.43.1",
24+
version="2.44.0",
2525
packages=find_packages("src"),
2626
package_dir={"": "src"},
2727
include_package_data=True,

src/pushsource/_impl/backend/koji_source.py

+98-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import threading
33
import logging
44
from functools import partial
5+
import json
56

67
from queue import Queue, Empty
78
from threading import Thread
@@ -538,8 +539,10 @@ def _push_items_from_vmi_build(self, nvr, meta):
538539
raise ValueError(message)
539540

540541
build_id = meta["id"]
541-
542542
archives = self._get_archives(build_id)
543+
for archive in archives:
544+
if archive["filename"] == "meta.json":
545+
return self._push_items_from_rhcos_build(nvr, meta)
543546

544547
# Supported types of VMI archives
545548
ami_types = ["raw", "raw-xz"]
@@ -559,9 +562,7 @@ def _push_items_from_vmi_build(self, nvr, meta):
559562
if elem.get("btype") == "image"
560563
and elem.get("type_name") in cloud_types.keys()
561564
]
562-
563565
out = []
564-
565566
# Generate the respective PushItem type for each archive
566567
for archive in vmi_archives:
567568
path = self._pathinfo.typedir(meta, archive["btype"])
@@ -621,6 +622,100 @@ def _push_items_from_vmi_build(self, nvr, meta):
621622

622623
return out
623624

625+
def _push_items_from_rhcos_build(self, nvr, meta, archives=None):
626+
627+
LOG.debug("Looking for core os assembler build on %s, %s", nvr, meta)
628+
629+
build_id = meta["id"]
630+
archives = archives or self._get_archives(build_id)
631+
632+
for archive in archives:
633+
if archive.get("filename") == "meta.json":
634+
path = self._pathinfo.typedir(meta, archive["btype"])
635+
item_src = os.path.join(path, archive["filename"])
636+
with open(item_src) as archive_file:
637+
rhcos_meta_data = json.loads(archive_file.read())
638+
639+
extra = meta.get("extra") or {}
640+
image = extra.get("typeinfo").get("image") or {}
641+
642+
arch = image.get("arch")
643+
644+
boot_mode = image.get("boot_mode")
645+
if boot_mode is not None:
646+
boot_mode = BootMode(boot_mode)
647+
648+
rhcos_container_config = (
649+
rhcos_meta_data.get("coreos-assembler.container-config-git") or {}
650+
)
651+
branch = rhcos_container_config.get("branch") or ""
652+
version = branch.split("-")[-1] or ""
653+
654+
# Try to get the resping version from release, if available
655+
respin = try_int(meta["release"])
656+
respin = 0 if not isinstance(respin, int) else respin
657+
658+
vms_with_custom_meta_data = []
659+
# add aws ami
660+
for ami in rhcos_meta_data["amis"]:
661+
vms_with_custom_meta_data.append(
662+
{
663+
"marketplace_name": "aws",
664+
"push_item_class": AmiPushItem,
665+
"custom_meta_data": {
666+
"region": ami.get("name"),
667+
"src": ami.get("hvm"),
668+
},
669+
}
670+
)
671+
672+
# add vm for azure
673+
vms_with_custom_meta_data.append(
674+
{
675+
"marketplace_name": "azure",
676+
"push_item_class": VHDPushItem,
677+
"custom_meta_data": {
678+
"src": rhcos_meta_data["azure"]["url"],
679+
},
680+
}
681+
)
682+
683+
out = []
684+
for vm_item in vms_with_custom_meta_data:
685+
klass = vm_item.get("push_item_class")
686+
rel_klass = klass._RELEASE_TYPE
687+
release = rel_klass(
688+
arch=arch,
689+
date=(meta.get("completion_time") or "").split(" ")[0],
690+
product=meta.get("name").split("-")[0].upper(),
691+
version=version,
692+
respin=respin,
693+
)
694+
images = rhcos_meta_data.get("images") or {}
695+
vm_target = images.get(vm_item["marketplace_name"]) or {}
696+
sha256sum = vm_target.get("sha256")
697+
698+
out.append(
699+
klass(
700+
name=rhcos_meta_data.get("name"),
701+
description=rhcos_meta_data.get("summary"),
702+
**vm_item["custom_meta_data"],
703+
boot_mode=boot_mode,
704+
build=nvr,
705+
build_info=KojiBuildInfo(
706+
id=int(build_id),
707+
name=meta["name"],
708+
version=version,
709+
release=meta["release"],
710+
),
711+
sha256sum=sha256sum,
712+
release=release,
713+
marketplace_name=vm_item["marketplace_name"]
714+
)
715+
)
716+
717+
return out
718+
624719
def _get_operator_item(self, nvr, meta, archives, container_items):
625720
extra = meta.get("extra") or {}
626721
typeinfo = extra.get("typeinfo") or {}

src/pushsource/_impl/model/vms.py

+3
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ class VMIPushItem(PushItem):
8181
8282
It's used by the property `marketplace_title` to format it as the marketplace title."""
8383

84+
marketplace_name = attr.ib(type=str, default=None, validator=optional_str)
85+
"""Name of the marketplace where the Image is expected to be shipped."""
86+
8487
@property
8588
def marketplace_title(self) -> str:
8689
"""The marketplace title which is used for some certain layered products.

src/pushsource/_impl/schema/staged-schema.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ definitions:
124124
marketplace_entity_type:
125125
$ref: "#/definitions/optional_string"
126126

127+
127128
scanning_port:
128129
type:
129130
- number
@@ -137,6 +138,8 @@ definitions:
137138
$ref: "#/definitions/optional_string"
138139
marketplace_title_template:
139140
$ref: "#/definitions/optional_string"
141+
marketplace_name:
142+
$ref: "#/definitions/optional_string"
140143
security_groups:
141144
type:
142145
- array

tests/baseline/cases/staged-simple-ami-bc.yml

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ items:
2424
ena_support: true
2525
image_id: null
2626
marketplace_entity_type: AMIProduct
27+
marketplace_name: null
2728
marketplace_title_template: null
2829
md5sum: null
2930
name: fake-image.raw

tests/baseline/cases/staged-simple-ami-bootmode.yml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ items:
2020
ena_support: true
2121
image_id: null
2222
marketplace_entity_type: null
23+
marketplace_name: null
2324
marketplace_title_template: null
2425
md5sum: null
2526
name: fake-image.raw

tests/baseline/cases/staged-simple-ami-uefi.yml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ items:
2020
ena_support: true
2121
image_id: null
2222
marketplace_entity_type: null
23+
marketplace_name: null
2324
marketplace_title_template: null
2425
md5sum: null
2526
name: fake-image.raw

tests/baseline/cases/staged-simple-ami.yml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ items:
2020
ena_support: true
2121
image_id: null
2222
marketplace_entity_type: null
23+
marketplace_name: null
2324
marketplace_title_template: null
2425
md5sum: null
2526
name: fake-image.raw

tests/koji/test_koji_vmi.py

+148
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,151 @@ def test_koji_vmi_compound_product_name(fake_koji, koji_dir):
238238
signing_key=None,
239239
release=rel_obj,
240240
)
241+
242+
243+
@mark.parametrize("boot_mode", [None, "legacy", "uefi", "hybrid"])
244+
def test_coreos_assembler_image(boot_mode, fake_koji, koji_dir):
245+
boot_mode_enum = BootMode(boot_mode) if boot_mode else None
246+
247+
archives = []
248+
images = {
249+
"meta.json": "json",
250+
"commitmeta.json": "json",
251+
"coreos-assembler-git.tar.gz": "tar",
252+
}
253+
for file_name, type_name in images.items():
254+
archives.append(
255+
{
256+
"btype": "image",
257+
"btype_id": 4,
258+
"build_id": 123456,
259+
"buildroot_id": 1234567,
260+
"checksum": "dde60621880aa996c42e356a687744ef",
261+
"checksum_type": 0,
262+
"compression_type": None,
263+
"filename": file_name,
264+
"id": 234792,
265+
"metadata_only": False,
266+
"size": 16077,
267+
"type_description": "JSON data",
268+
"type_extensions": "json",
269+
"type_id": 49,
270+
"type_name": type_name,
271+
}
272+
)
273+
274+
name = "rhcos"
275+
version = "4.11"
276+
release = "1"
277+
nvr = f"{name}-{version}-{release}"
278+
279+
source = Source.get(
280+
f"koji:https://koji.example.com/?vmi_build={nvr}", basedir=koji_dir
281+
)
282+
assert not fake_koji.last_url
283+
284+
fake_koji.build_data[1234] = {
285+
"id": 1234,
286+
"name": name,
287+
"version": version,
288+
"release": release,
289+
"nvr": nvr,
290+
"completion_time": "2022-12-20 12:30:25",
291+
"extra": {"typeinfo": {"image": {"arch": "x86_64", "boot_mode": boot_mode}}},
292+
}
293+
294+
fake_koji.build_data[nvr] = fake_koji.build_data[1234]
295+
296+
fake_koji.insert_archives(archives=archives, build_nvr=nvr)
297+
298+
meta_data_directory = os.path.join(
299+
koji_dir, "packages", name, version, release, "images"
300+
)
301+
os.makedirs(meta_data_directory)
302+
meta_data_path = os.path.join(meta_data_directory, "meta.json")
303+
304+
meta_data = """{
305+
"name": "rhcos",
306+
"summary": "OpenShift 4",
307+
"coreos-assembler.container-config-git":{
308+
"branch": "release-4.11"
309+
},
310+
"images": {
311+
"azure": {
312+
"path": "rhcos-4.11-0-azure.x86_64.vhd.gz",
313+
"sha256": "2cd817331af29093e2eaa025139ebddd6008c193970b06b35afbbdbebae0ce3e",
314+
"dest": ["https://example.windows.net/imagebucket/rhcos-4.11-0-azure.x86_64.vhd"]},
315+
"aws": {
316+
"path": "rhcos-4.11-0-aws.x86_64.vmdk.gz",
317+
"sha256": "4ef7806152bd89ce44326ff746c4f1883ad543885e980bce59821df2d946ea4c"
318+
}},
319+
"azure": {
320+
"image": "rhcos-4.11-0-azure.x86_64.vhd",
321+
"url": "https://example.windows.net/imagebucket/rhcos-4.11-0-azure.x86_64.vhd"},
322+
"amis": [
323+
{"name": "us-gov-west-1",
324+
"hvm": "ami-01"
325+
},
326+
{"name": "us-east-1",
327+
"hvm": "ami-02"
328+
}]}"""
329+
330+
with open(meta_data_path, "w") as rhcos_metadata:
331+
rhcos_metadata.write(meta_data)
332+
items = list(source)
333+
334+
vms_with_custom_meta_data = [
335+
{
336+
"marketplace_name": "aws",
337+
"push_item_class": AmiPushItem,
338+
"custom_meta_data": {"region": "us-gov-west-1", "src": "ami-01"},
339+
"sha256": "4ef7806152bd89ce44326ff746c4f1883ad543885e980bce59821df2d946ea4c",
340+
},
341+
{
342+
"marketplace_name": "aws",
343+
"push_item_class": AmiPushItem,
344+
"custom_meta_data": {"region": "us-east-1", "src": "ami-02"},
345+
"sha256": "4ef7806152bd89ce44326ff746c4f1883ad543885e980bce59821df2d946ea4c",
346+
},
347+
{
348+
"marketplace_name": "azure",
349+
"push_item_class": VHDPushItem,
350+
"custom_meta_data": {
351+
"src": "https://example.windows.net/imagebucket/rhcos-4.11-0-azure.x86_64.vhd"
352+
},
353+
"sha256": "2cd817331af29093e2eaa025139ebddd6008c193970b06b35afbbdbebae0ce3e",
354+
},
355+
]
356+
357+
out = []
358+
for vm_item in vms_with_custom_meta_data:
359+
klass = vm_item.get("push_item_class")
360+
rel_klass = klass._RELEASE_TYPE
361+
release = rel_klass(
362+
arch="x86_64",
363+
date="2022-12-20",
364+
product="RHCOS",
365+
version="4.11",
366+
respin=1,
367+
)
368+
369+
out.append(
370+
klass(
371+
name="rhcos",
372+
description="OpenShift 4",
373+
**vm_item["custom_meta_data"],
374+
boot_mode=boot_mode_enum,
375+
build="rhcos-4.11-1",
376+
build_info=KojiBuildInfo(
377+
id=1234,
378+
name="rhcos",
379+
version="4.11",
380+
release="1",
381+
),
382+
sha256sum=vm_item.get("sha256"),
383+
release=release,
384+
marketplace_name=vm_item["marketplace_name"],
385+
)
386+
)
387+
items = sorted(items, key=lambda metadata: metadata.name)
388+
assert items == out

0 commit comments

Comments
 (0)