Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

external: add new get-dnf4-package-info external #226

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ format:
.PHONY: test
test: external
cp $(shell (which "osbuild-gen-depsolve-dnf4")) ./external/
cp $(shell (which "osbuild-get-dnf4-package-info")) ./external/
cp $(shell (which "osbuild-make-depsolve-dnf4-rpm-stage")) ./external/
cp $(shell (which "osbuild-make-depsolve-dnf4-curl-source")) ./external/
@pytest
Expand Down
8 changes: 6 additions & 2 deletions example/centos/centos-9-aarch64-ami.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ otk.define:
filesystem:
modifications:
filename: "image.raw"
kernel:
cmdline: console=ttyS0,115200n8 console=tty0 net.ifnames=0 nvme_core.io_timeout=4294967295 iommu.strict=0
packages:
build:
otk.external.osbuild-gen-depsolve-dnf4:
Expand Down Expand Up @@ -96,6 +94,12 @@ otk.define:
- plymouth
- dracut-config-rescue
- qemu-guest-agent
kernel:
cmdline: console=ttyS0,115200n8 console=tty0 net.ifnames=0 nvme_core.io_timeout=4294967295 iommu.strict=0
package:
otk.external.osbuild-get-dnf4-package-info:
packageset: ${packages.os}
packagename: "kernel"

otk.include: "common/partition-table/aarch64.yaml"

Expand Down
12 changes: 8 additions & 4 deletions example/centos/centos-9-aarch64-qcow2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ otk.define:
filesystem:
modifications:
# empty
kernel:
cmdline: console=tty0 console=ttyS0,115200n8 no_timer_check net.ifnames=0
packages:
build:
otk.external.osbuild-gen-depsolve-dnf4:
architecture: x86_64
architecture: aarch64
module_platform_id: c9s
releasever: "9"
repositories:
Expand All @@ -31,7 +29,7 @@ otk.define:
exclude: []
os:
otk.external.osbuild-gen-depsolve-dnf4:
architecture: x86_64
architecture: aarch64
module_platform_id: c9s
releasever: "9"
repositories:
Expand Down Expand Up @@ -103,6 +101,12 @@ otk.define:
- plymouth
- rng-tools
- udisks2
kernel:
cmdline: console=tty0 console=ttyS0,115200n8 no_timer_check net.ifnames=0
package:
otk.external.osbuild-get-dnf4-package-info:
packageset: ${packages.os}
packagename: "kernel"

otk.include: "common/partition-table/aarch64.yaml"

Expand Down
2 changes: 1 addition & 1 deletion example/centos/fragment/grub2/aarch64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ options:
uefi:
vendor: centos
unified: true
saved_entry: ffffffffffffffffffffffffffffffff-8-2.fk1.aarch64
saved_entry: ffffffffffffffffffffffffffffffff-${kernel.package.version}-${kernel.package.release}.${kernel.package.arch}
write_cmdline: false
config:
default: saved
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ otk = "otk.command:root"
osbuild-gen-depsolve-dnf4 = "otk_external_osbuild.command.gen_depsolve_dnf4:main"
osbuild-make-depsolve-dnf4-rpm-stage = "otk_external_osbuild.command.make_depsolve_dnf4_rpm_stage:main"
osbuild-make-depsolve-dnf4-curl-source = "otk_external_osbuild.command.make_depsolve_dnf4_curl_source:main"
osbuild-get-dnf4-package-info = "otk_external_osbuild.command.get_dnf4_package_info:main"

[project.optional-dependencies]
dev = [
Expand Down
18 changes: 12 additions & 6 deletions src/otk_external_osbuild/command/gen_depsolve_dnf4.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,26 @@ def transform(packages):
return data


def mockdata(packages):
def mockdata(packages, architecture):
"""Mockdata as used by tests, we don't actually execute the depsolver
but return a map that's similar enough in format that the rest of the
compile can continue."""

# see https://github.com/osbuild/images/pull/937
def ver(pkg_name):
return str(ord(pkg_name[0]) % 9)

def release(pkg_name):
return str(ord(pkg_name[1]) % 9)
return [
{
"name": p,
"checksum": "sha256:" + hashlib.sha256(p.encode()).hexdigest(),
"remote_location": f"https://example.com/repo/packages/{p}",
"version": "0",
"epoch": "",
"release": "0",
"arch": "noarch",
"version": ver(p),
"epoch": "0",
"release": release(p) + ".fk1",
"arch": architecture,
}
for p in packages["include"] + [f"exclude:{p}" for p in packages["exclude"]]
]
Expand All @@ -42,7 +48,7 @@ def root(input_stream: TextIO) -> None:
data = json.loads(input_stream.read())
tree = data["tree"]
if "OTK_UNDER_TEST" in os.environ:
packages = mockdata(tree["packages"])
packages = mockdata(tree["packages"], tree["architecture"])
sys.stdout.write(json.dumps(transform(packages)))
return

Expand Down
39 changes: 39 additions & 0 deletions src/otk_external_osbuild/command/get_dnf4_package_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import json
import sys
from typing import List, Optional, TextIO


def find_pkg_by_name(packages: List[dict], pkg_name: str) -> Optional[dict]:
for pkg in packages:
if pkg["name"] == pkg_name:
return pkg
return None


def root(input_stream: TextIO) -> None:
data = json.load(input_stream)
pkg_name = data["tree"]["packagename"]
packages = data["tree"]["packageset"]["const"]["internal"]["packages"]

pkg = find_pkg_by_name(packages, pkg_name)
if not pkg:
raise KeyError(f"cannot find package {pkg_name}")
sys.stdout.write(
json.dumps(
{
"tree": {
"version": pkg["version"],
"release": pkg["release"],
"arch": pkg["arch"],
}
}
)
)


def main():
root(sys.stdin)


if __name__ == "__main__":
main()
16 changes: 8 additions & 8 deletions test/test_gen_depsolve_dnf4.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ def test_gen_depsolve_dnf4_under_test_mock_data(monkeypatch, capsys):
"checksum": "sha256:3d7b91c2dd3273400f26d21a492fcdfdc3dde228cd5627247dfef745ce717755",
"name": "pkg1",
"remote_location": "https://example.com/repo/packages/pkg1",
"version": "0",
"release": "0",
"arch": "noarch",
"epoch": "",
"version": "4",
"release": "8.fk1",
"arch": "x86_64",
"epoch": "0",
}, {
"arch": "noarch",
"arch": "x86_64",
"checksum": "sha256:93941c24b2276b2050d001b61bab64c58a8df5242bf491fa888f061cca12b51a",
"epoch": "",
"epoch": "0",
"name": "exclude:not-pkg2",
"release": "0",
"release": "3.fk1",
"remote_location": "https://example.com/repo/packages/exclude:not-pkg2",
"version": "0",
"version": "2",
},
],
},
Expand Down
43 changes: 43 additions & 0 deletions test/test_get_dnf4_package_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import json
from io import StringIO

from otk_external_osbuild.command.get_dnf4_package_info import root


fake_input = {
"tree": {
"packagename": "foo",
"packageset": {
"const": {
"internal": {
"packages": [
{
"name": "foo",
"version": "1",
"release": "fc30",
"arch": "c64",
},
{
"name": "bar",
"version": "2",
"release": "fc40",
"arch": "c128",
},
]
}
}
}
}
}


def test_make_depsolve_dnf4_curl_source(capsys):
root(StringIO(json.dumps(fake_input)))
output = json.loads(capsys.readouterr().out)
assert output == {
"tree": {
"version": "1",
"release": "fc30",
"arch": "c64",
}
}
Loading