Commit graph

844 commits

Author SHA1 Message Date
Michael Vogt
caddf0adfb fscache: add new FsCache._last_used() helper
This helper can be used to implement a strategy to find the oldest
cache entries and evict them when the cache is full.

The implementation uses the `atime` of the per object `cache.lock`
file and ensures in `load()` that it's actually updated.
2023-12-12 22:57:21 +01:00
Michael Vogt
f52cabc3c1 osutil: add Libc.futimens() wrapper for futimens() call
Python has no wrapper for a futime*() call so we need to implement
it in the `util.linux` package.
2023-12-12 22:57:21 +01:00
Brian C. Lane
9eb9f7f7f2 test: Move make_fake_input_tree to testutil
This is useful for other stage tests, move it and add a test.
2023-12-12 19:45:04 +01:00
Michael Vogt
5416028f2d osbuild: include std{out,err} in FileSystemMountService.mount() errors
This commit adds mount output to the error raised by
FileSystemMountService.mount(). This is useful when running into
mount failures during osbuild runs.

The issue was discovered while debugging a mount failure for
osbuild-composer PR#3820. Initially osbuild PR#1490 was meant
to fix it but it turned out there is a third mount helper in
the code that was originally overlooked (sorry for that!).
2023-12-12 16:25:35 +01:00
Alexander Larsson
eea81b660a testutils: Add assert_dict_has
This is a convenient way for tests to assert that some nested dicts
(like a parsed json) has a particular key/value somewhere in it.

For example:
  assert_dict_has(config, "toplevel.subitem.key", True)
2023-12-12 09:54:38 +01:00
Michael Vogt
4026d4dc10 test: add test that ensures mount output is part of the exception
While debugging a failure of osbuild-composer [0] on fc39 it was
noticed that a mount failure does not include the output of
the mount command:
```
  File "/usr/lib/python3.12/site-packages/osbuild/mounts.py", line 78, in mount
    path = client.call("mount", args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/osbuild/host.py", line 348, in call
    ret, _ = self.call_with_fds(method, args)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/osbuild/host.py", line 384, in call_with_fds
    raise error
osbuild.host.RemoteError: CalledProcessError: Command '['mount', '-t', 'xfs', '-o', 'ro,norecovery', '--source', '/dev/rootvg/applv', '--target', '/tmp/tmpjtfmth56/app']' returned non-zero exit status 32.
   File "/usr/lib/python3.12/site-packages/osbuild/host.py", line 268, in serve
    reply, reply_fds = self._handle_message(msg, fds)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/osbuild/host.py", line 301, in _handle_message
    ret, fds = self.dispatch(name, args, fds)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/osbuild/mounts.py", line 111, in dispatch
    r = self.mount(args)
        ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/osbuild/mounts.py", line 160, in mount
    subprocess.run(
  File "/usr/lib64/python3.12/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
```
which makes diagnostic errors harder of course. This commit adds
a test that ensures that mount output is visbile and also changes
the code to include it.

[0] https://github.com/osbuild/osbuild-composer/pull/3820
2023-12-11 11:24:17 +01:00
schutzbot
c53c60e694 Post release version bump
[skip ci]
2023-12-06 08:15:39 +00:00
Dusty Mabe
0770eb0090 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.
2023-11-29 10:37:08 +01:00
Miguel Martín
bc04bfc366 runners: clean up temp files before exiting the runner
Clean up created temp files before exiting the runner.
2023-11-28 11:50:31 +01:00
Miguel Martín
99af178c6d runners: create fake machine id when needed
Create fake machine before executing the runner command to
avoid the "Failed to resolve specifiers in '/var/log/journal/%m'"
errors.
2023-11-28 11:50:31 +01:00
Michael Vogt
b3c6366135 osbuild: improve monitor docstrings/signatures
This is a split out from the work around json
progress in [1].

[1] https://github.com/osbuild/osbuild/compare/main...mvo5:osbuild:json-progress-mvo?expand=1
2023-11-28 09:56:56 +01:00
Michael Vogt
158acaac78 osbuild: ensure loop.Loop() has the required device node
When loop.Loop() is called and a new loop device must be allocated
there is no gurantee that the correct device node is available on
the system. In containers /dev is often just a tmpfs with static
device nodes. So when /dev/loopN is not available when the
container is created the device node will be missing even if
`get_unbound()` create a new loop device for us.

This commit ensures that the device node is available. It creates
it unconditionally and ignores any EEXIST errors to ensure there
is no TOCTOU issue.

Note that the test could have passed a `Loop(dir_fd=open(tmpdir))`
instead of creating/patching loop.DEV_PATH but it seems slightly
nicer to test the flow without a custom dir_path as this is what
the real code that creates a loop device is also using.
2023-11-24 16:05:52 +01:00
Michael Vogt
edbf409a40 osbuild: fix missing initialization of fd in osbuild.loop.Loop
When osbuild.loop.Loop calls `__init__()` it assigns the `self.fd`
on open. However if that open call fails for whatever reason
(not found, permissions) the cleanup in `__del__` will fail in
confusing ways because `self.fd` is not initialized yet. It
also prevents the correct error from getting reported. A tiny
test is added to ensure this does not regress.
2023-11-23 14:01:53 +01:00
Michael Vogt
4b69d2e1c4 util: tweak _calculate_size() to _calculate_space()
Update the naming, docstring and tweak the tests.

Thanks to bcl and dustymabe!
2023-11-22 10:28:08 +01:00
Dusty Mabe
9121360f7b osbuild/util/fscache: calculate actual size of files
In OSBuild we'll often be operating on sparse files. Let's make the
tabulation of the size of files on disk used when determining cache
size for pruning consider the actual size of the file usage on disk
rather than the size the file reports to be.

This means using os.lstat().st_blocks * 512 versus os.lstat().st_size.

See https://stackoverflow.com/a/55203604
2023-11-22 10:28:08 +01:00
Michael Vogt
29e05c689e osbuild. add comment why AST is used and not importlib
Add comment why the `ModuleInfo.load()` code uses open()/ast.parse()
instead of just using `importlib`.

The reason is that while `importlib` is more convenient and much
shorter it would require that all python modules of the osbuild
modules are actually installed on the system just to inspect the
schema/documentation of the stage.
2023-11-22 09:52:47 +01:00
schutzbot
016407284a Post release version bump
[skip ci]
2023-11-22 08:16:02 +00:00
Miguel Martín
9cece6b4a0 Consolidate runners functions
Consolidate runners functions into a sigle file
to avoid code duplication.
2023-11-20 18:02:12 +01:00
Michael Vogt
7b201db5a7 ostuild: fix new pylint error with latest pylint version
The `shutil.rmtree(onerror=...)` kwarg got deprecated with py3.12.
We still need to support older version of python all the way
back to 3.6 so just ignore this pylint error for a while.
2023-11-15 18:31:56 +01:00
Simon de Vlieger
1f51938046 osbuild: testutil provides has_executable
Add a helper function to determine if an executable is on PATH.
2023-11-10 12:03:23 +01:00
schutzbot
fb1bc6fdab Post release version bump
[skip ci]
2023-11-08 08:14:06 +00:00
Michael Vogt
061501d4c2 osbuild: add new testutil.imports module to help test stages
This commit adds `osbuild.testutil.imports.import_module_from_path`
that can be used to import arbitrary python source files. This
allows importing files from the stages directory that have a
non python friendly filename like `org.osbuild.kickstart`.
2023-11-07 15:12:08 +01:00
Alexander Larsson
0c144fc4aa Add selinux-label-version to the org.osbuild.ostree.commit stage
This is a feature that was added in rpm-ostree 2023.10 and is needed
for the new transient /etc feature to work. What it does is change the
labeling of /usr/etc to match those of /etc, so that /usr/etc can be used
directly as a bind-mount or an overlay mount when mounted on /etc.

See https://github.com/coreos/rpm-ostree/pull/4640 for details.
2023-10-28 15:37:56 -04:00
Dusty Mabe
d4b3e3655d objectstore: also mount /etc/containers for "host" buildroot
In the case we are not using a buildroot (i.e. we are using
the host as the buildroot) let's also mount in /etc/containers
into the environment. There are sometimes where software running
from /usr can't operate without configuration in /etc and this
will allow it to work.

An example of software hitting this problem is skopeo. With a
simple config like:

```
version: '2'
mpp-vars:
  release: 38
pipelines:
  - name: skopeo-tree
    # build: name:build
    source-epoch: 1659397331
    stages:
      - type: org.osbuild.skopeo
        inputs:
          images:
            type: org.osbuild.containers
            origin: org.osbuild.source
            mpp-resolve-images:
              images:
                - source: quay.io/fedora/fedora-coreos
                  tag: stable
                  name: localhost/fcos
        options:
          destination:
            type: containers-storage
            storage-path: /usr/share/containers/storage
```

We end up hitting an error like this:

```
time="2023-10-24T18:27:14Z" level=fatal msg="Error loading trust policy: open /etc/containers/policy.json: no such file or directory"
Traceback (most recent call last):
  File "/run/osbuild/bin/org.osbuild.skopeo", line 90, in <module>
    r = main(args["inputs"], args["tree"], args["options"])
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/run/osbuild/bin/org.osbuild.skopeo", line 73, in main
    subprocess.run(["skopeo", "copy", image_source, dest], check=True)
  File "/usr/lib64/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['skopeo', 'copy', 'dir:/tmp/tmp5_qcng99/image', 'containers-storage:[overlay@/run/osbuild/tree/usr/share/containers/storage+/run/containers/storage]localhost/fcos']' returned non-zero exit status 1.
```

This PR adds in a mount for /etc/containers from the host so that
/etc/containers/policy.json can be accessed.
2023-10-25 22:05:54 +02:00
schutzbot
5579257c65 Post release version bump
[skip ci]
2023-10-25 08:14:34 +00:00
Dusty Mabe
8844bc260e osbuild/util/ostree: create setup_remote function
This moves the setup_remote function from the ostree source into
util/ostree. This is prep for sharing this function with an mpp
helper in the future.
2023-10-16 20:26:10 +02:00
schutzbot
f0982873e2 Post release version bump
[skip ci]
2023-10-11 08:14:13 +00:00
Dusty Mabe
c6c9454f6f osbuild/util: create pull_local function in util/ostree
This is prep for sharing this functionality with other stages than
the ostree.pull stage.
2023-10-06 15:55:26 +02:00
Dusty Mabe
4e99e80c4a osbuild/util: hoist ostree code into util/ostree
Prep for sharing with other stages later.
2023-10-06 15:55:26 +02:00
Dusty Mabe
4e5de3808e osbuild/util: add containers_source helper
This will hoist even more code into util out of the skopeo stage.
Now a caller can call:

    with containers.container_source(image) as (image_name, image_source):
        print(f"{image_name}, {image_source}")

to process containers inputs.
2023-09-30 02:29:05 +02:00
Dusty Mabe
4cd9af47d0 osbuild/util: hoist container handling code into util/containers
This hoists container handling code from the skopeo stage into
util/containers. It is prep for adding another stage that accepts
containers as an input. The code is common so we should share it
amongst all stages that use containers as input.
2023-09-30 02:29:05 +02:00
schutzbot
ad2fed1a3b Post release version bump
[skip ci]
2023-09-27 08:13:30 +00:00
schutzbot
4e2f17bfca Post release version bump
[skip ci]
2023-09-13 08:16:15 +00:00
schutzbot
feee1255b0 Post release version bump
[skip ci]
2023-08-30 08:17:13 +00:00
Ondřej Budai
b94048dfd4 mounts/org.osbuild.btrfs: add support for compression
Also, add it to the sample manifest.
2023-08-25 12:35:56 +02:00
Ondřej Budai
0952ae9933 mounts/org.osbuild.btrfs: add support for mounting subvolumes
Co-authored-by: Christian Kellner <christian@kellner.me>
2023-08-25 12:35:56 +02:00
schutzbot
271f5eff31 Post release version bump
[skip ci]
2023-08-23 15:27:18 +00:00
schutzbot
694e956104 Post release version bump
[skip ci]
2023-08-16 08:18:35 +00:00
Brian C. Lane
44c28c8c16 autopep8: Update with changes to make autopep8 -a -a -a happy 2023-08-10 13:04:14 +02:00
Simon de Vlieger
427e82e0c0 osbuild: --checkpoint can now use globs
When developing or rebuilding manifests a lot it is common to want to
checkpoint everything to the store. It seems we all have small shell
scripts hanging around for this.

Let `--checkpoint` take a shell-like glob such as `--checkpoint="*"` to
checkpoint everything.

Note that there's a behavioral change here; previously `osbuild
--checkpoint=a` would error if that specific checkpoint wasn't found.
Now `osbuild` will only error if nothing was selected by the passed
globs.
2023-08-04 19:59:11 +02:00
schutzbot
b8836948c5 Post release version bump
[skip ci]
2023-08-02 08:15:32 +00:00
Simon de Vlieger
d60690ce46 tox: add tox
`tox` is a standard testing tool for Python projects, this allows you to
test locally with all your installed Python version with the following
command:

`tox -m test -p all`

To run the tests in parallel for all supported Python versions.

To run linters or type analysis:

```
tox -m lint -p all
tox -m type -p all
```

This commit *also* disables the `import-error` warning from `pylint`,
not all Python versions have the system-installed Python libraries
available and they can't be fetched from PyPI.

Some linters have been added and the general order linters run in has
been changed. This allows for quicker test failure when running
`tox -m lint`. As a consequence the `test_pylint` test has been removed
as it's role can now be fulfilled by `tox`.

Other assorted linter fixes due to newer versions:
- use a str.join method (`consider-using-join`)
- fix various (newer) mypy and pylint issues
- comments starting with `#` and no space due to `autopep8`

This also changes our CI to use the new `tox` setup and on top of that
pins the versions of linters used. This might move into separate
requirements.txt files later on to allow for easier updating of those
dependencies.
2023-08-01 15:01:13 +02:00
schutzbot
722d023104 Post release version bump
[skip ci]
2023-07-19 08:13:33 +00:00
schutzbot
06072d5d89 Post release version bump
[skip ci]
2023-06-27 12:58:15 +00:00
Ondřej Budai
c90b587dcc inputs: Move arguments for InputService.map to a temporary file
Prior this commit, the arguments for the input service were passed inline.
However, jsoncomm uses the SOCK_SEQPACKET socket type underneath that has
a fixed maximum packet size. On my system, it's 212960 bytes. Unfortunately,
that's not enough for big inputs (e.g. when building packages with a lot
of rpms).

This commit moves all arguments to a temporary file. Then, just a file
descriptor is sent. Thus, we are now able to send arbitrarily sized args
for inputs, making osbuild work even for large image builds.
2023-06-27 10:56:10 +02:00
schutzbot
8a10dc7b5d Post release version bump
[skip ci]
2023-06-21 08:13:27 +00:00
Michael Hofmann
840df1dc92 Restore LOOP_CONFIGURE fallback for kernel < 5.8
The fallback that was initially present in #1253 is needed for the
current GitLab runners which have a Container-Optimized OS [1] with
kernel 5.4 [2] without support for LOOP_CONFIGURE [3].

[1] https://docs.gitlab.com/ee/ci/runners/saas/linux_saas_runner.html
[2] https://gitlab.com/cki-project/containers/-/jobs/4381560305#L31
[3] https://gitlab.com/cki-project/containers/-/jobs/4381560305#L1166

Signed-off-by: Michael Hofmann <mhofmann@redhat.com>
2023-06-20 12:18:15 +02:00
schutzbot
a8bba69935 Post release version bump
[skip ci]
2023-06-07 08:14:17 +00:00
schutzbot
a7b3ef3936 Post release version bump
[skip ci]
2023-05-24 08:13:14 +00:00
schutzbot
4add41d50f Post release version bump
[skip ci]
2023-05-10 08:13:14 +00:00