Commit graph

3215 commits

Author SHA1 Message Date
Michael Vogt
d67fa48c17 stages: fix btrfs subvolume creation under subdirectories
The code currently does not support btrfs subvolumes that are not
directly under the root directory. This commit fixes this by adding
`-p` to `btrfs subvolume create` and adding an integration test.

Closes: https://github.com/osbuild/osbuild/issues/1882
2024-09-13 11:23:35 +02:00
Michael Vogt
ed95178b80 test: add test that ensures return value of chroot.run()
Small followup for https://github.com/osbuild/osbuild/pull/1854
which added the return value to `util.Chroot.run`. This commit
now adds a (super trivial) test for this.
2024-09-11 20:19:46 +02:00
schutzbot
6953ea89b4 Post release version bump
[skip ci]
2024-09-11 08:27:12 +00:00
Jonathan Lebon
66a00335c6 stages/dmverity: make device objects more generic
We need to pass loopback devices for these properties, but the schema
says that there will be a `path` property, so osbuild complains.

osbuild is right of course, but this definitely *did* work in an earlier
version, so something changed. Ideally, we'd narrow down here what
happened exactly, but at the same time this approach of just making the
property more generic matches what's done in e.g. the `zipl.inst` stage
where we also use a loopback device.

For reference, this is where we use this stage:

ba45b296ec/src/osbuild-manifests/platform.qemu.ipp.yaml (L100-L119)
2024-09-10 20:11:16 +02:00
Michael Vogt
f3188e841f osbuild: also print what export is availalble when one is not found
The current error message when an export is not found could be
improved by printing what exports are actually availalble to make
it easier for the user to e.g. spot typos.
2024-09-10 10:49:18 -07:00
Lukas Zapletal
09da4fff7b stages: add org.osbuild.pki.update-ca-trust
Adds a new stage that calls update-ca-trust tool with extract argument
to extract CA certificates. It is expected that one or more CAs are
placed in the /etc/pki/ca-trust/source/anchors directory in PEM format.
Filenames do not matter but must be unique enough. See the
update-ca-trust man page for more details on what it does.
2024-09-10 19:10:06 +02:00
Lukas Zapletal
88474fd4d9 util: run returns CompletedProcess 2024-09-10 19:10:06 +02:00
Michael Vogt
ea14713f3a osbuild add new -q, --quiet option
Current osbuild will always print some non output even
when run with `--monitor=JSONSeqMonitor` because of the
unconditional `print/sys.stdout.write()` in `main_cli.py`.

This commit adds a new `-q` option to silence this so that something
like osbuild-composer can run `osbuild -q --monitor=JSONSeqMonitor`
to get pure json-seq output during the build.

The use-case is to run `osbuild --monitor-fd` from e.g. bib and
osbuild-composer so that we get pure json from the monitor-fd
and anything that goes on std{out,err} can be logged as it is
most likely error output.
2024-09-09 18:07:54 -07:00
Michael Vogt
a221d4e68b test: checkpoint "build" stage too during test_stages.py
Quick check to see if checkpointing "build" helps with the
runtime. Note that the cache size is already 20GB, I doubled
it for good measure but we probably can go back to 20, just
want to make sure this is not the bottleneck.

Closes: https://github.com/osbuild/osbuild/issues/1874
2024-09-05 18:17:56 +02:00
schutzbot
a0828f77dc schutzfile: Update snapshots to 20240901 2024-09-05 17:39:41 +02:00
Florian Schüller
0f5db9a283 stages: fix some documentation typos to prepare for spellchecking 2024-09-04 12:17:58 +02:00
Ondřej Budai
2f84ba96c9 stages: add a new mkswap stage
A stage very similar to the existing mkfs ones (actually, I started from
the xfs one). It creates a swap area on a given device.
2024-09-02 15:27:32 +02:00
Achilleas Koutsou
83fcc8a0b1 test: compare full arg_list in chroot context test
- Add an extra call to `/bin/false` and explicitly set the `check`
  argument for both `run()` calls.
- Compare full call_args_list.  This checks that all the options are as
  expected, that the `check` argument is set properly, and that the full
  order of all the calls is as expected, including the chroot path.

Co-authored-by: Michael Vogt <michael.vogt@gmail.com>
2024-08-28 16:45:48 -07:00
Achilleas Koutsou
1093b5eeb2 util/chroot: use subprocess.run() for all commands
For consistency, use subprocess.run() with check=True for the calls that
were previously using subprocess.check_call().

Update the affected tests to match.
2024-08-28 16:45:48 -07:00
Achilleas Koutsou
73464ff119 test: add test for chroot context
Add a test for the chroot context that mocks subprocess.run() and
subprocess.check_call().  The test verifies that the functions are
called the expected number of times with the expected command (first
arg).
2024-08-28 16:45:48 -07:00
Achilleas Koutsou
3dbf389ebf util/chroot: add run() method to context class
Rename the ChrootProcDevSys class to just Chroot and add a run() method.
Calls now can be made using:

  with Chroot(root) as chroot:
      chroot.run(command)
2024-08-28 16:45:48 -07:00
Achilleas Koutsou
931e832944 test/dracut: update subprocess.run() call count 2024-08-28 16:45:48 -07:00
Achilleas Koutsou
149e3ead96 util/chroot: call unmount with check=False
If one of the chroot mounts fails to unmount, keep iterating so that we
don't stop and continue to unmount the rest.
Print an error message with the failed mounts, but don't fail the build.

Since failing to unmount doesn't fail the exiting of the context, and
the context itself doesn't know what will be running in the chroot,
do a lazy unmount.
2024-08-28 16:45:48 -07:00
schutzbot
d893e81004 Post release version bump
[skip ci]
2024-08-28 08:26:06 +00:00
Michael Vogt
b4b865fddf Revert "sources(curl): disable curl --parallel by default"
This reverts commit 9bef57d5a6.
2024-08-28 07:46:37 +02:00
Michael Vogt
a229d46b1e sources(curl): manually keep track of failed URLs
This commit keeps track of individual errors as curl will only report
the last download operation success/failure via it's exit code.

There is "--fail-early" but the downside of that is that abort all in
progress downloads too.
2024-08-28 07:46:37 +02:00
Michael Vogt
a50dbb14c2 sources(curl): use --next for each url in curl config
curl keeps a global parser state. This means that if there are
multiple "cacert =" values they are just overriden and the last
one wins. This is why the `test_curl_download_many_mixed_certs`
test did not work - the second `cacert = ` overwrites the previous
one.

To fix this we need to use `--next` when we need to change options
on a per url (like `cacert`) basis. With `--next` curl starts a
new parser state for the next url (but keeps the options for the
previous ones set). This commit does that in a slightly naive
way by just repeating our options for each url. Technically
we could sort the sources so that we have less repetition but
other then slightly smaller auto-generated files it has no
advantage.

With this commit the `test_curl_download_many_mixed_certs` test
works.
2024-08-28 07:46:37 +02:00
Michael Vogt
6ccd5d5cfe test: add test that download mixed https content
When investigating https://github.com/osbuild/osbuild-composer/pull/4247
we found that it would fail when a download required two sets of
`--cacert` keys. This commits adds a test for this that fails on
the centos9 7.76.1 version.
2024-08-28 07:46:37 +02:00
Michael Vogt
ca558c2479 devices: create /dev/mapper/<logical-volume> as well
When we create the device node inside the buildroot so far it's
very minimal - just `/dev/{vg}-{lv}` with the appopriate major/minor.

However when mount runs it will create a mapper device with the
same major/minor under `/dev/mapper/{escaped(vg)}-{escaped(lv)}`
and use that to mount the actual filesystem. Without this additional
device findmnt will not be able to detect the udev attributes of
the source (as the source is just missing from /dev).

This commit create the right mapper in the same way that we
create the non-mapper device node.
2024-08-27 13:52:59 +02:00
Michael Vogt
f0f9d8677a test: update the test cert to expire in 100y
When generating the original test certs no `-days` paramter was
passed which resulted in a too low `notAfter` value.

This commit fixes this and uses 100y also updates the README:
```
$ openssl x509 -enddate -noout -in test/data/certs/cert1.pem
notAfter=Aug  2 10:42:40 2124 GMT
$ openssl x509 -enddate -noout -in test/data/certs/cert2.pem
notAfter=Aug  2 10:42:45 2124 GMT
```
This fixes a test failure in https://github.com/osbuild/osbuild/pull/1819
for the `test_curl_download_many_mixed_certs` test.
2024-08-27 09:39:17 +02:00
Michael Vogt
3b77eb3625 stages: workaround the two remaining autopep8 issues via noqa
Small followup for https://github.com/osbuild/osbuild/pull/1864

There were two issues from `autopep8` left, both can be just
silenced via the `# noqa` directive.
2024-08-26 23:19:17 +02:00
Paweł Poławski
db08c472f3 general: Fix linter issues across the codebase 2024-08-26 11:59:46 -07:00
Michael Vogt
77a61da760 osbuild: drop libdir from download() methods
The libdir is passed down for sources but it is never used in
any of our sources. As this is confusing and we want to eventually
support multiple libdirs remove this code.

It looks like the libdir for soruces was added a long time ago in 8423da3
but there is no indication if/how it is/was supposed to get used and
AFACT from going over the git history it was very used.

SourceService:dispatch() never sends "libdir" to the actual sources,
so it is not an even technically an API break.
2024-08-26 19:58:55 +02:00
Michael Vogt
a2fed3e0d8 devices: extract get_parent_path(), use for manage_devices_file()
This commit extract a helper `get_parent_path()` that is unit
tested and also uses this generated parent_path for the call
to manage_devices_file to be consistent with the exiting behavior
of only including the device that actually contains the VG.
2024-08-26 14:16:01 +02:00
Achilleas Koutsou
0695911d5c devices: add new vg_partnum parameter
This is needed for bootc where all mounts need to be from the same
physical disk/loop so that bootupd works. The idea is that in the
manifest the new option `vg_partnum` is added and the parent VG
is found via the partition number of the full image similar to
the `partnum` from https://github.com/osbuild/osbuild/pull/1501

A manifest using this feature looks like this:
```json
"devices": {
  "disk": {
    "type": "org.osbuild.loopback",
    "options": {
      "filename": "disk.raw",
      "partscan": true
    }
  },
  "rootlv": {
    "type": "org.osbuild.lvm2.lv",
    "parent": "disk",
    "options": {
      "volume": "rootlv",
      "vg_partnum": 4
    }
  }
}
```

Co-authored-by: Michael Vogt <mvogt@redhat.com>
2024-08-26 14:16:01 +02:00
Michael Vogt
6788a2c840 devices: add pytest conftest infra for devices
This is similar to the other `inputs`, `sources` etc conftest.py
modules and allows us to write unit test for the devices code.
2024-08-26 14:16:01 +02:00
Achilleas Koutsou
6ba0561187 sources/containers-storage: fix load caching
storage_conf was never not None, so the loading was called every time.
This never crashed because conf was always being set, but it wasn't
working properly regardless.
2024-08-22 19:47:28 +02:00
Achilleas Koutsou
af913d91f4 tox: add toml test envs
Add four toml test environments, testing that osbuild.util.toml works
for reading and writing with all our supported toml module combinations.
2024-08-21 19:26:31 +02:00
Achilleas Koutsou
fe1e310f2e test: add read/write tests for util.toml
Add two unit tests for our toml util module.
- Write an object with util.toml, read it with util.toml, and compare
  written and read objects.
- Write an object directly as a string, read it with util.toml,
  comparing with an expected object.

A test that writes with util.toml, reads as string, and verifies the
read string is difficult to do in a general way, because each toml
module we support writes files in a slightly different way.
2024-08-21 19:26:31 +02:00
Achilleas Koutsou
b496732a02 util/toml: disable unspecified-encoding check 2024-08-21 19:26:31 +02:00
Achilleas Koutsou
30fcf37c03 util/toml: add encoding and type hints
- Specify utf-8 encoding when opening files in text mode.
- Add type hints.
- Prefix all the top-level names with _.
2024-08-21 19:26:31 +02:00
Achilleas Koutsou
27e1e9f774 test/bootc_install_config: parse config for result
Different toml libraries write arrays differently, so we can't know
exactly what the file contents will look like.  Some will write an array
in a single line (toml) while others will break it into one element per
line (tomli_w).  Parse the file that's written by the stage so we can
compare the objects instead of the text contents directly.
2024-08-21 19:26:31 +02:00
Achilleas Koutsou
07a597481b util: move get_host_storage() to a separate module
Add a new util module called host which is used for functions that are
meant for interactions with the host.  These functions should not be
used in stages.

The containers.get_host_storage() function is renamed to
host.get_container_storage() for clarity, since it is no longer
namespaced under containers.
2024-08-21 19:26:31 +02:00
Achilleas Koutsou
bce908e4a2 util: replace toml imports with our util module 2024-08-21 19:26:31 +02:00
Achilleas Koutsou
292d4ad0fe stages: replace toml imports with our util module 2024-08-21 19:26:31 +02:00
Achilleas Koutsou
123b23fb66 util/toml: support writing comment headers
The containers.storage.conf stage writes a header explaining what the
configuration is doing and its origin.  It also supports adding extra
comments via stage options, which we need to support.  Add support for
writing comments at the top of the file in the toml.dump_to_file()
function.
2024-08-21 19:26:31 +02:00
Achilleas Koutsou
94cdcecafb util: add new module for reading and writing toml
The toml module situation in Python is a bit of a mess.  Different
distro versions have different modules packaged or built-in, sometimes
with different capabilities (no writing).  Since we need to support
reading and writing toml files both on the host (osbuild internals,
sources, inputs) and in the build root (stages), let's centralise the
import decision making in an internal utility module that covers all
cases.

Two of the modules we might import (tomli and tomllib) don't support
writing, so we need to either import a separate module (tomli_w) or
raise an exception when dump() is called without a write-capable module.

The tomli and tomllib modules require files be opened in binary mode
(not text) while the others require text mode.  So we can't wrap the
toml.load() and toml.dump() functions directly; the caller doesn't know
which module it will be using.  Let's keep track of the mode based on
which import succeeded and have our functions open the files as needed.

The wrapper functions are named load_from_file() and dump_to_file() to
avoid confusion with the load() and dump() functions that take a file
object.

See also #1847
2024-08-21 19:26:31 +02:00
schutzbot
347c0dec4a Post release version bump
[skip ci]
2024-08-21 17:07:31 +00:00
Achilleas Koutsou
69625505cf util/chroot: rename context class to ChrootProcDevSys
Rename the context class to better describe what it's doing.  It doesn't
run anything in a chroot, but it prepares the tree for it.
2024-08-21 18:50:05 +02:00
Achilleas Koutsou
618ec9db2c test/update-crypto-policies: update diff file
With the mounting of /dev (among others) into the chroot for the
update-crypto-policies, the leftover /dev/null is now removed.

This was created by the update-crypto-policies script, running in the
chroot, by multiple output redirects into /dev/null.  Without a /dev fs,
the file was being created in the tree and would remain on the image.
2024-08-21 18:50:05 +02:00
Achilleas Koutsou
8e41ec58a7 stages/update-crypto-policies: use Chroot context
Recently [1], the update-crypto-policies script added a check to verify
that the FIPS policy was automounted by reading the
/proc/self/mountinfo.  The script will fail if the proc filesystem isn't
available.

Use the new Chroot context to set up the environment for the command.

[1] 04ceadccfc
2024-08-21 18:50:05 +02:00
Achilleas Koutsou
9edda1d163 osbuild/util: new module: chroot
New chroot utility module that sets up a tree with the necessary virtual
filesystems needed for running commands in the root tree in a similar
environment as they would run in the build root.

This is needed for some stages, but may also be used for all chroot
calls to unify the setup and teardown of the root environment.

The Chroot context class was previously part of the org.osbuild.dracut
stage, which was the first stage to need this setup.
2024-08-21 18:50:05 +02:00
Michael Vogt
8a9c6aba3c osbuild: add "Conflicts" to avoid breaking older composer
osbuild 126 added a new "solver" field in the osbuild-dnf-json
output and osbuild-composer only supports this since 116.

This broke production (sorry!). This commit helps mitigate it.
2024-08-21 17:17:25 +02:00
schutzbot
658502a226 schutzfile: Update snapshots to 20240819 2024-08-21 12:11:02 +02:00
Achilleas Koutsou
d1dbcc20cf test/depsolve: use strings for pytest.skip()
The pytest.skip() argument must be a string.  Calling it with an
exception produces an error.
2024-08-20 10:47:36 -07:00