Commit graph

830 commits

Author SHA1 Message Date
Simon de Vlieger
bc99513c0a stages/test: kickstart different messages
On Python 3.6 we're getting a *different* error message from other
versions in CI. Let's accept both versions.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-06-16 09:31:49 -07:00
Achilleas Koutsou
0968ee8d81 stages/grub2: add compat_version for fixed behaviour
For the terminal_input, terminal_output, and serial variables in the
GRUB_CFG_TEMPLATE, the keys were not set when those variables were not
defined in the options.  This caused the template variables to show up
in the final file itself, which could break the config.  For example,
the following line was being generated for one of our images:

    serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1${terminal_input}${terminal_output}

Setting the keys to an empty string when they're not defined solves the
issue.

Since this is a stage behaviour change, the new behaviour is toggled by
an option that maintains backwards compatibility when not set.
This introduces a new convention of adding a `compat_version` number to
the stage options to control the behaviour.  The value defaults to 1,
which is the old (broken) behaviour.  Manifest generators should always
set it to 2 to get the correct behaviour.
2025-06-13 14:14:57 +02:00
Simon de Vlieger
42281231b0 stages/containers: don't validate keys
In Python 3.14 configparser started validating keys. We use hacky bits
to write duplicate keys which means we have delimiters in our keys which
is now no longer allowed.

Let's explicitly turn off key validation for now as suggested by
mhroncok in [1].

[1]: https://github.com/osbuild/osbuild/issues/2109#issuecomment-2964585958

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-06-12 15:31:34 +02:00
Simon de Vlieger
44cb7934db stages/systemd: don't validate keys
In Python 3.14 configparser started validating keys. We use hacky bits
to write duplicate keys which means we have delimiters in our keys which
is now no longer allowed.

Let's explicitly turn off key validation for now as suggested by
mhroncok in [1].

[1]: https://github.com/osbuild/osbuild/issues/2109#issuecomment-2964585958

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-06-12 15:31:34 +02:00
Brian C. Lane
a828ef95d6 stages/erofs: Add exclude_paths support
Add the ability to exclude files and directories from the erofs
image. This uses the mkfs.erofs --exclude-regex feature, so simple
matches or regexes can be used.
2025-06-11 20:22:23 +02:00
Brian C. Lane
86c89a2421 stages/squashfs: Add exclude_paths support
Add the ability to exclude files and directories from the squashfs
image. This uses the mksquashfs -regex -e FILES... feature, so simple
matches or regexes can be used.

This also adds a new test for squashfs, based on the existing test for
erofs.
2025-06-11 20:22:23 +02:00
Simon de Vlieger
a464815ea8 stages/tar: allow chosen compression
The `org.osbuild.tar` stage only supports auto compression which is
based on the filename. For several (newer) artifacts such as Vagrant
(`.box`) and WSL (`.wsl`) we want to explicitly give the compression
algorithm.

I've chosen a (few) commonly used compression algorithms. If others are
needed they are one-line followups away.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-06-03 18:18:23 +02:00
Achilleas Koutsou
0ac83fd421 stages/kickstart: post-installation scripts
Add a new %post option to the kickstart stage that supports adding
multiple post blocks to a kickstart file, with all the options supported
by the directive.
2025-05-14 09:06:40 +02:00
Nikita Dubrovskii
73e3544e86 stages/coreos.live-artifacts: fix kernel and initrd paths in s390x ISO
The `generic.ins` template uses:
  images/kernel.img
  images/initrd.img

However, kernel and initrd are currently stored as:
  images/pxeboot/vmlinuz
  images/pxeboot/initrd.img

This change ensures correct paths are used.
2025-04-23 08:01:11 +02:00
Tomáš Hozza
7ff3fe0b50 Stages/waagent.conf: support additional options
Extend the stage to support setting new options:
 - Provisioning.UseCloudInit
 - Provisioning.Enabled

Extend the stage test to use them and add a simple stage unit test for
the schema.

Related to https://github.com/osbuild/images/issues/1416

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-04-14 08:18:04 +02:00
Tomáš Hozza
d41d8ecb3f Stages/waagent.conf: fix copy&paste error
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-04-14 08:18:04 +02:00
Tomáš Hozza
bea378f191 Stages/rhsm: add unit test for the stage schema
I forgot to add the file to
https://github.com/osbuild/osbuild/pull/2070.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-04-11 15:39:20 +02:00
Achilleas Koutsou
db9f03ad41 stages: add unit tests for chrony stage
Add unit tests that check the schema and file contents for the chrony
stage.
2025-04-11 09:00:42 +02:00
Achilleas Koutsou
8baf16da06 stages/chrony: support specifying refclocks
The refclock directive can be used to specify one or more hardware
reference clocks to be used as a time source.  Each refclock line must
specify a driver and a mandatory parameter, in the form:

  refclock driver parameter

Drivers can have driver-specific options:

  refclock driver parameter:[driver-option,...]

General refclock options can also be specified:

  refclock driver parameter:[driver-option,...] [general-option]...

The stage options schema is written so that the "driver" property is an
object that must match one of four schemas corresponding to the four
drivers, each with a "name" property matching the driver name.
Each driver defines its required property and any optional
driver-specific options.

There are more general refclock options supported than the ones defined
in this commit, but we can add them if and when we need them in the
future.

Note that the restriction on the top-level stage options schema is now
lifted and any set of options can be specified.  Servers are not
required.  However, at least one top-level property is required still.

Docs: https://chrony-project.org/doc/3.4/chrony.conf.html
2025-04-11 09:00:42 +02:00
Tomáš Hozza
c9639c41f9 Stages/rhsm: support setting 'auto_enable_yum_plugins' option
Support setting the `auto_enable_yum_plugins` option in the `rhsm`
section of `rhsm.conf`.

Add a unit test for the stage schema and also adjust the stage test
manifest.

Related to: https://github.com/osbuild/images/issues/1408

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-04-10 12:29:21 +02:00
Achilleas Koutsou
52a822075e stages/systemd.unit.create: support StandardOutput
Add support for the StandardOutput option in the [Service] section of
systemd units.

https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#StandardOutput=
2025-04-08 12:43:28 +02:00
luizademelo
cda3c43b2c stages: fix description for org.osbuild.containers.unit.create
Fixes #2053
2025-04-03 02:25:31 +02:00
Achilleas Koutsou
5b77ff6f65 stages: add new stage org.osbuild.hmac
The new org.osbuild.hmac stage can be used to calculate hmac digests to
be stored alongside files for verification.
2025-04-02 13:06:47 +02:00
Dusty Mabe
5a19d41f3e stages/coreos.live-artifacts: loosen requirements on modules dir
We originally required there to be only one kernel modules directory
since we typically only have one kernel installed. Change this check
up a bit since some kernel module RPMs aren't delivering a new kernel
but do deliver kmods that were built against a different kernel.

For example v4l2loopback from https://elrepo.org/

```
bash-5.1# rpm -ql kmod-v4l2loopback
/etc/depmod.d/kmod-v4l2loopback.conf
/lib/modules/5.14.0-427.13.1.el9_4.x86_64
/lib/modules/5.14.0-427.13.1.el9_4.x86_64/extra
/lib/modules/5.14.0-427.13.1.el9_4.x86_64/extra/v4l2loopback
/lib/modules/5.14.0-427.13.1.el9_4.x86_64/extra/v4l2loopback/v4l2loopback.ko
/usr/share/doc/kmod-v4l2loopback-0.12.7
/usr/share/doc/kmod-v4l2loopback-0.12.7/GPL-v2.0.txt
/usr/share/doc/kmod-v4l2loopback-0.12.7/greylist.txt
```

This patch now allows an image built from a Containerfile like the
following to work as input to the live artifacts stage.

```
FROM rhcos
RUN <<EOF
    set -eux -o pipefail
    dnf install -y https://www.elrepo.org/elrepo-release-9.el9.elrepo.noarch.rpm
    dnf install -y v4l2loopback
    dnf clean all
    ostree container commit
EOF
```
2025-03-19 22:25:59 +01:00
rverdile
a62276c7dc stages: add insights-client config stage 2025-03-17 19:34:16 +01:00
Michael Vogt
e93cd75e5b test/rpm: add schema validation test for boot_root 2025-03-13 13:47:43 +01:00
Achilleas Koutsou
305a54f1a2 stages/rpm: add new kernel_install_env options
Add support for setting environment variables for kernel-install and its
plugins.  These can be used to control the behaviour of kernel-install
during the kernel rpm installation.  Currently, we only add support for
$BOOT_ROOT, which we need to control the path where the kernel should be
installed.

Normally, kernel-install scripts will detect the correct path based on
the filesystem layout, specifically the ESP path.  However, during our
installation the filesystem is not yet set up, so with this option, we
can control the installation path based on the location we know the ESP
will be mounted in the final image.

This is a very similar override to what we do with the
org.osbuild.fix-bls stage.

The stage option is added under a kernel_install_env object so we can
potentially support more of the known env vars in the future.
2025-03-13 13:47:43 +01:00
Achilleas Koutsou
7be822d6e9 stages/rpm: set encoding for subprocess.run()
Printing 'owner' in an fstring triggers the mypy warning 'str-bytes-safe'

  Error: If x = b'abc' then f"{x}" or "{}".format(x) produces "b'abc'",
  not "abc".

We can't yet use the nicer run() argument, 'text=True', because we still
target the RHEL 7 build root which only has Python 3.6 and 'text' was
introduced in Python 3.7.
2025-03-13 13:47:43 +01:00
Achilleas Koutsou
f2ab07cf85 stages/grub2.inst: grub2-mkimage in tmpdir
Use a temporary directory for the output of grub2-mkimage.

This makes the stage clean up the grub2-core.img from the build root
after its done.  It also has the nice side-effect that unit tests that
call the stage are independent.  Previously, a bug in the stage *might*
have been missed if a certain configuration of the stage was not
creating the grub2-core.img.  One unit test could create an image at the fixed path
(/var/tmp/grub2-core.img) and then another one could call the stage with
the buggy configuration but the `shutil.copyfile()` call at the end of
the stage would succeed because it would find the image from the
previous stage run.

To accommodate for this change, the unit test with the mocked run call
is adjusted to intercept the random tmp output path and use it to create
a fake file for the stage to succeed.
2025-03-08 02:30:32 +01:00
Michael Vogt
dc24a131e9 stages: add mock test for grub-mkimage for regression test
This commit adds a test that mocks subprocess.run() so that we
can regression test the arguments passed to "grub-mkimage".

This is a regression test for
https://github.com/osbuild/osbuild/issues/2037
2025-03-08 02:30:32 +01:00
Achilleas Koutsou
67070cc316 stages/grub2.inst: fix format for non-x86_64 image
When writing the grub2 core image, the format should be set based on the
platform.  This was accidentally changed to be `i386-pc` for all
platforms except when building ISOs.

Set the format to the platform and only change it to `i386-pc-eltorito`
when building ISOs.
2025-03-08 02:30:32 +01:00
Achilleas Koutsou
30d8a16e41 stages/systemd.unit.create: support .swap units
Add support for .swap systemd units.
2025-03-04 20:34:43 +01:00
Achilleas Koutsou
8b2ae24de9 stages: add .socket to systemd.unit.create test
Add .socket unit tests and replace the second .mount example with a
.socket example in the systemd.unit.create stage tests.
2025-03-04 20:34:43 +01:00
Michael Vogt
530ce4f80c stages: ensure dirs for dracut-conf stage are available
If the dracut config stage runs early the directory for the
dracut config may not be available yet. So just create it.
2025-02-24 13:18:33 +01:00
Dusty Mabe
a08736be49 stages/coreos.live-artifacts: use /var/tmp for mkfs.erofs
This helps reduce the memory requirements of mkfs.erofs since
it won't be writing to tmpfs (memory backed) storage, which is
what is mounted on /tmp/.
2025-02-17 20:39:38 +01:00
Michael Vogt
0c1a8c802f stages: add basic qemu cmdline test
This commit adds a basic fake commandline test for the qemu
stage.
2025-02-17 13:21:40 +01:00
Dusty Mabe
4e033c305e stages: add more options to qemu vmdk disk type
The CoreOS team uses the compat6 and adapter_type options when creating
a VMDK for AWS.

e1943d6adb/src/cosalib/qemuvariants.py (L48)
2025-02-17 03:41:11 -05:00
Sanne Raymaekers
441fbf70d6 org.osbuild.cloud-init: add new datasources and network section
Adds WSL and NoCloud datasources. The network section only allows you to
disable network configuration by cloud-init for now.
2025-02-15 10:38:12 +01:00
Nikita Dubrovskii
035ced543b stages/coreos.live-artifacts: update comments/names to reflect erofs related changes 2025-02-13 13:40:20 +01:00
Michael Vogt
1a2637b1a3 stages: replace "logger" binary in the dracut chroot
This commit replaces the `/usr/bin/logger` binary in the dracut
chroot with a bind mount to `/usr/bin/true` to silence the spam
that we get from dracut during initramfs generation:
```
logger: socket /dev/log: No such file or directory
```

Unfortunately I could not find a nicer way, it seems it is
not possible to simply pass `sysloglvl=0` via the commandline
or an environment.

The extra complication here is that the dracut stage mounts
`devtmpfs` which will likely include:
```
/dev/log -> /run/systemd/journal/dev-log
```
but of course inside this chroot there is no `/run` which
leads to these messages.

Closes: https://github.com/osbuild/osbuild/issues/1976
2025-02-12 15:44:04 +00:00
Paweł Poławski
ed732b36d8 stages: add tests to org.osbuild.ovf
Add some tests for org.osbuild.ovf.

Extracted from https://github.com/osbuild/osbuild/pull/1751
2025-02-12 11:24:47 +01:00
Nikita Dubrovskii
ab1f48795b stages/coreos.live-artifacts: add erofs support 2025-02-11 17:41:35 -05:00
Albert Esteve
a6b64860b3 stages/kernel-cmdline: add max cmdline option
Add an additional option called `kernel_line_size`
to allow setting a maximum cmdline size check
value for custom kernels or other restrictions.

This will override the arch defaults, if not set,
then the size map is checked, and if the current
architecture is not in the map, fallback to
4096, which is the max value allowed for
COMMAND_LINE_SIZE.

Signed-off-by: Albert Esteve <aesteve@redhat.com>
2025-02-11 09:16:17 +00:00
Albert Esteve
7645d717e6 stages/kernel-cmdline: fix link in comment
Signed-off-by: Albert Esteve <aesteve@redhat.com>
2025-02-11 09:16:17 +00:00
Albert Esteve
bd316ddb8f kernel-cmdline: add size check
Add check to ensure that the size of
the parameters does not exceed the
maximum kernel cmdline size.
Otherwise, the parameters will
be truncated and the command line
will fail.

The size is arch-dependant. In
order to not to over-complicate
the search of the value in the
kernel files (which will probably
not be installed in most cases),
it uses a map with some values
for common architectures.

If architecture is not found in
the map, defaults to 4096, which
is the maximum posible size for
COMMAND_LINE_SIZE.

Signed-off-by: Albert Esteve <aesteve@redhat.com>
2025-02-07 15:18:45 +01:00
Achilleas Koutsou
45c6006cfc stages: Where is mandatory in systemd.unit.create
`systemd.mount(5)` describes both `What` and `Where` as mandatory
options for the `Mount` section of a unit.
2025-02-04 22:24:02 +01:00
Michael Vogt
752f4af6b3 stages: add test for the new org.grub2.iso.legacy stage
This commit adds a small smoke test that ensures our new
org.osbuild.grub2.iso.legacy stages does not regress easily.
2025-01-30 08:29:43 +01:00
Simon de Vlieger
d92be415f8 stage/dnf.module-config: remove path
Instead of passing in the path we name the file according to the module
name. Path can be reintroduced later if absolutely necessary.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-01-22 18:03:21 +01:00
Simon de Vlieger
0d25c845f8 stages: introduce dnf.module-config
A new stage that allows writing a DNF module configuration file to a
given path.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-01-22 18:03:21 +01:00
Albert Esteve
55d53f58fd stages/mkfs.ext4: disable lazy_init
This helps to clear a risk concern for
automotive.

Add optional flag to org.osbuild.mkfs.ext4 stage
to enable/disable both lazy_itable_init and
lazy_journal_init extended options. Both mke2fs
options are controled by the same flag, namely
`lazy_init`.

Signed-off-by: Albert Esteve <aesteve@redhat.com>
2025-01-17 19:11:38 +01:00
Michael Vogt
1eb8138ab5 test: tweak test_grub2_inst.py to support running on Debian/Ubuntu
This commit adds support to run the tests on Debian/Ubuntu systems.
Here the binary is called `grub-mkimage` instead of `grub2-mkimage`,
in addition the "grub-pc-bin" package must be installed there.
2025-01-13 22:53:02 +01:00
Brian C. Lane
3bed7c7ace grub2.inst: Add support for creating iso9660 boot image
Don't include the "location" offset, and use just a path for the prefix
section to set the path of the grub2 modules on the iso. eg.

{
    "filename": "eltorito.img",
    "platform": "i386-pc",
    "core": {
        "type": "mkimage",
        "partlabel": "gpt",
        "filesystem": "iso9660"
    },
    "prefix": {
        "path": "/boot/grub2/"
    }
}
2025-01-13 22:53:02 +01:00
Brian C. Lane
41c0550a1f tests: Add simple test for org.osuild.grub2.inst stage
Tests that grub2-mkimage ran without errors, and that the image file
actually has something written to it.
2025-01-13 22:53:02 +01:00
Brian C. Lane
fd19ab41fb org.osbuild.xorriso: Add support for grub2 bootable iso
This creates an iso matching the current method used in Fedora where it
uses grub2 for BIOS and UEFI booting. Pass the path to the grub2 hybrid
mbr to the stage in the 'grub2mbr' field. eg.
    "grub2mbr": "/usr/lib/grub/i386-pc/boot_hybrid.img"
2025-01-06 21:23:23 +01:00
Tomáš Hozza
6a4a7c31c6 Stages/test/tuned: handle "improved" jsonschema messages
python-jsonschema improved the error messages for some special cases
since v4.21.0 [0], which means that we need to handle multiple versions
of the error message in unit tests.

[0] 8875c2ecb1 (diff-c21226b904760a669a70785494cd8ecf5fb1e7415fd25765dd02f0ad00394099R231)

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-01-06 11:53:46 -08:00