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

osbuild: support metal4k; add aleph file stage #3675

Merged
merged 7 commits into from
Dec 4, 2023
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
27 changes: 25 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,35 @@ write_archive_info() {
}

patch_osbuild() {
# A few patches that either haven't made it into a release or
# Add a few patches that either haven't made it into a release or
# that will be obsoleted with other work that will be done soon.

# To make it easier to apply patches we'll move around the osbuild
# code on the system first:
rmdir /usr/lib/osbuild/osbuild
mv /usr/lib/python3.12/site-packages/osbuild /usr/lib/osbuild/
mkdir /usr/lib/osbuild/tools
mv /usr/bin/osbuild-mpp /usr/lib/osbuild/tools/

# Now all the software is under the /usr/lib/osbuild dir and we can patch
cat /usr/lib/coreos-assembler/0001-Mount-boot-from-host-in-host-builder-case.patch \
/usr/lib/coreos-assembler/0001-osbuild-util-fscache-calculate-actual-size-of-files.patch \
/usr/lib/coreos-assembler/0002-util-tweak-_calculate_size-to-_calculate_space.patch \
| patch -p1 -d /usr/lib/python3.12/site-packages/
/usr/lib/coreos-assembler/0001-devices-loopback-make-setting-sector_size-meaningful.patch \
/usr/lib/coreos-assembler/0002-tools-osbuild-mpp-handle-corner-case-in-mpp-format-i.patch \
/usr/lib/coreos-assembler/0003-tools-osbuild-mpp-support-defining-multiple-image-la.patch \
/usr/lib/coreos-assembler/0004-tools-osbuild-mpp-add-sector-size-support-for-image-.patch \
/usr/lib/coreos-assembler/0005-tools-osbuild-mpp-set-part-ID-from-name-if-missing.patch \
/usr/lib/coreos-assembler/0001-osbuild-util-ostree-convert-cli-to-return-the-comple.patch \
/usr/lib/coreos-assembler/0002-osbuild-util-ostree-optimize-deployment_path.patch \
/usr/lib/coreos-assembler/0003-create-org.osbuild.ostree.aleph-stage.patch \
| patch -d /usr/lib/osbuild -p1

# And then move the files back; supermin appliance creation will need it back
# in the places delivered by the RPM.
mv /usr/lib/osbuild/tools/osbuild-mpp /usr/bin/osbuild-mpp
mv /usr/lib/osbuild/osbuild /usr/lib/python3.12/site-packages/osbuild
mkdir /usr/lib/osbuild/osbuild
}

if [ $# -ne 0 ]; then
Expand Down
2 changes: 1 addition & 1 deletion mantle/cmd/kola/testiso.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ StandardError=kmsg+console
ExecStart=/bin/sh -c "journalctl -t coreos-installer-service | /usr/bin/awk '/[Dd]ownload/ {exit 1}'"
ExecStart=/bin/sh -c "/usr/bin/udevadm settle"
ExecStart=/bin/sh -c "/usr/bin/mount /dev/disk/by-label/root /mnt"
ExecStart=/bin/sh -c "/usr/bin/jq -er '.[\"build\"] == \"%s\"' /mnt/.coreos-aleph-version.json"
ExecStart=/bin/sh -c "/usr/bin/jq -er '.[\"version\"] == \"%s\"' /mnt/.coreos-aleph-version.json"
ExecStart=/bin/sh -c "/usr/bin/jq -er '.[\"ostree-commit\"] == \"%s\"' /mnt/.coreos-aleph-version.json"
[Install]
RequiredBy=coreos-installer.target
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
From 0770eb0090a7ad04bb2f5bca938be3453f71fe6e Mon Sep 17 00:00:00 2001
From: Dusty Mabe <[email protected]>
Date: Tue, 21 Nov 2023 17:18:22 -0500
Subject: [PATCH 1/5] devices/loopback: make setting sector_size meaningful

For the org.osbuild.loopback the user can set the sector size, but
it had no effect on the underlying loopback device. Let's make it
meaningful by passing along the given value to the underlying code.
---
devices/org.osbuild.loopback | 1 +
osbuild/loop.py | 8 ++++----
2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/devices/org.osbuild.loopback b/devices/org.osbuild.loopback
index cc104391..0b6591d0 100755
--- a/devices/org.osbuild.loopback
+++ b/devices/org.osbuild.loopback
@@ -82,6 +82,7 @@ class LoopbackService(devices.DeviceService):
setup=self.setup_loop,
offset=offset,
sizelimit=sizelimit,
+ blocksize=self.sector_size,
partscan=False,
autoclear=True)

diff --git a/osbuild/loop.py b/osbuild/loop.py
index 675ea510..7f602191 100644
--- a/osbuild/loop.py
+++ b/osbuild/loop.py
@@ -385,7 +385,7 @@ class Loop:
info = self._config_info(self.get_status(), offset, sizelimit, autoclear, partscan)
fcntl.ioctl(self.fd, self.LOOP_SET_STATUS64, info)

- def configure(self, fd: int, offset=None, sizelimit=None, autoclear=None, partscan=None):
+ def configure(self, fd: int, offset=None, sizelimit=None, blocksize=0, autoclear=None, partscan=None):
"""
Configure the loopback device
Bind and configure in a single operation a file descriptor to the
@@ -427,6 +427,8 @@ class Loop:
sizelimit : int, optional
The max size in bytes to make the loopback device, or None
to leave unchanged (default is None)
+ blocksize : int, optional
+ Set the logical blocksize of the loopback device. Default is 0.
autoclear : bool, optional
Whether or not to enable autoclear, or None to leave unchanged
(default is None)
@@ -437,9 +439,7 @@ class Loop:
# pylint: disable=attribute-defined-outside-init
config = LoopConfig()
config.fd = fd
- # Previous implementation was not configuring the block size.
- # Keep same behavior here by setting the value to 0.
- config.block_size = 0
+ config.block_size = int(blocksize)
config.info = self._config_info(LoopInfo(), offset, sizelimit, autoclear, partscan)
try:
fcntl.ioctl(self.fd, self.LOOP_CONFIGURE, config)
--
2.41.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
From 57f13570023653f85d0920ea64ae3433216c68fc Mon Sep 17 00:00:00 2001
From: Dusty Mabe <[email protected]>
Date: Mon, 27 Nov 2023 16:14:43 -0500
Subject: [PATCH 1/3] osbuild/util/ostree: convert cli to return the completed
process object

And also set stdout=subprocess.PIPE. This will allow for callers to
parse and use the output of the command, but has the side effect of
meaning less gets printed to the screen during run.

Co-authored-by: Luke Yang <[email protected]>
---
osbuild/util/ostree.py | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/osbuild/util/ostree.py b/osbuild/util/ostree.py
index 43dd99c5..09c648fb 100644
--- a/osbuild/util/ostree.py
+++ b/osbuild/util/ostree.py
@@ -199,11 +199,11 @@ def cli(*args, _input=None, **kwargs):
"""Thin wrapper for running the ostree CLI"""
args = list(args) + [f'--{k}={v}' for k, v in kwargs.items()]
print("ostree " + " ".join(args), file=sys.stderr)
- subprocess.run(["ostree"] + args,
- encoding="utf8",
- stdout=sys.stderr,
- input=_input,
- check=True)
+ return subprocess.run(["ostree"] + args,
+ encoding="utf8",
+ stdout=subprocess.PIPE,
+ input=_input,
+ check=True)


def parse_input_commits(commits):
--
2.41.0

43 changes: 43 additions & 0 deletions src/0002-osbuild-util-ostree-optimize-deployment_path.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
From 009813573024d4d42f37e5c1d3752e0c0e07bb06 Mon Sep 17 00:00:00 2001
From: Dusty Mabe <[email protected]>
Date: Mon, 27 Nov 2023 16:24:29 -0500
Subject: [PATCH 2/3] osbuild/util/ostree: optimize deployment_path()

When provisioning disk images there should really not be more than
one deployment on a system. We don't really need any of the parameters
here so let's make them optional and just find the deployment anyway.

Co-authored-by: Luke Yang <[email protected]>
---
osbuild/util/ostree.py | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/osbuild/util/ostree.py b/osbuild/util/ostree.py
index 09c648fb..90821d5b 100644
--- a/osbuild/util/ostree.py
+++ b/osbuild/util/ostree.py
@@ -1,5 +1,6 @@
import collections
import contextlib
+import glob
import json
import os
import subprocess
@@ -217,6 +218,14 @@ def parse_input_commits(commits):
def deployment_path(root: PathLike, osname: str, ref: str, serial: int):
"""Return the path to a deployment given the parameters"""

+ if osname == "" and ref == "" and serial is None:
+ filenames = glob.glob(root + '/ostree/deploy/*/deploy/*.0', recursive=True)
+ if len(filenames) < 1:
+ raise ValueError("Could not find deployment")
+ if len(filenames) > 1:
+ raise ValueError("More than one deployment found")
+ return filenames[0]
+
base = os.path.join(root, "ostree")

repo = os.path.join(base, "repo")
--
2.41.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
From 5207e92cab473627f4a5b5f2bea33c922cbac4d4 Mon Sep 17 00:00:00 2001
From: Dusty Mabe <[email protected]>
Date: Tue, 21 Nov 2023 21:08:39 -0500
Subject: [PATCH 2/5] tools/osbuild-mpp: handle corner case in mpp-format-int

If you do math in mpp-format-int it could end up getting converted
to a float. Of course if you end up with a decimal value that isn't
`.0` that's a problem for an int, but if it is `.0` let's handle it
gracefully.

For example, math like this could end up with a value with `.0`:

mpp-format-int: "{bios_boot_size_mb * 1024 * 1024 / sector_size_bytes}"
---
tools/osbuild-mpp | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/tools/osbuild-mpp b/tools/osbuild-mpp
index cce51a89..2bc33ac6 100755
--- a/tools/osbuild-mpp
+++ b/tools/osbuild-mpp
@@ -1259,6 +1259,11 @@ class ManifestFile:
sys.exit(1)

if res_type == "int":
+ # If the value ends with '.0' it could be because of
+ # some math that ended up converting the value to a
+ # float. Just trim it off in that case.
+ if res.endswith('.0'):
+ res = res.strip('.0')
res = int(res)
elif res_type == "json":
res = json.loads(res)
--
2.41.0

Loading
Loading