Commit graph

784 commits

Author SHA1 Message Date
Nikita Dubrovskii
fc185dae8c support user-defined partition numbers for GPT disks
Partitions by default are indexed starting at 1, but in
some cases, such as CoreOS for IBM Z, it may be usefull
to set the 'partnum' for GPT disks explicitly, without
creating dummy partitions.

Now user can define an image:

```
    mpp-define-images:
      - id: image
        size: 10737418240
        table:
          uuid: 00000000-0000-4000-a000-000000000001
          label: gpt
          partitions:
            - name: boot
              type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4
	      partnum: 3
              size: 786432
            - name: root
              type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4
	      partnum: 4
              size: 4194304
```

So target disk would look like:

```
    Disklabel type: gpt
    Disk identifier: 00000000-0000-4000-A000-000000000001
    Device        Start     End Sectors  Size Type
    /dev/loop0p3   2048  788479  786432  384M Linux filesystem
    /dev/loop0p4 788480 4982783 4194304    2G Linux filesystem
```

This patch updates the osbuild-mpp tool and the sgdisk and sfdisk
stages to support this.

Co-authored-by: Dusty Mabe <dusty@dustymabe.com>
2024-02-06 17:44:31 +01:00
Michael Vogt
6b8c1872f6 fscache: use remove_lru() to reclaim space when the cache is full
This commit adds code that will remove the least recently used
entries when a store() operation does not succeeds because the
cache is full. To be more efficient it will try to free
twice the requested size (this can be configured in the code).
2024-02-06 17:16:48 +01:00
Michael Vogt
6096f999f3 fscache: add FsCache._remove_lru() to remove entries
The FsCache._remove_lru() removes the least recently used entry
from the cache.
2024-02-06 17:16:48 +01:00
Michael Vogt
b2a82beb75 fscache: add new `FsCache._last_used_objs()' helper
This commit adds a helper that can be used to get a sorted list
of cache entries. The list includes the name and the last_used
information.
2024-02-06 17:16:48 +01:00
Luke Yang
477a21043e Create stages/org.osbuild.chattr stage
Add or remove the immutable bit to the specified mount directory.

The need we have for this right now is for the CoreOS builds where
the immutable bit being set on an OSTree deployment root doesn't
survive the `cp -a --reflink=auto` in the org.osbuild.copy stage when
being copied from the directory tree into the mounted XFS filesystem
we created on the disk image. Thus we have to workaround this loss
of attribute by applying the attribute directly on the mounted
filesystem from the disk.
2024-01-31 16:46:01 -05:00
Michael Vogt
a56afcb280 test: add new testutil.assert_jsonschema_error_contains() helper
This commit adds a new helper `assert_jsonschema_error_contains()`
to `testutil` and uses it everywhere where we check errors from
jsonschema.
2024-01-23 12:00:59 +01:00
Dusty Mabe
408b101799 manifests: support container_imgref var in FCOS manifest
This makes it easier to see/change the value globally.
2024-01-19 17:15:23 -05:00
Michael Vogt
f5d6d11f1d osbuild: error when {Device,Mount} is modified after creation
This is a drive-by change after spending some quality time with the
mount code. The `id` field of `Mount` is calculated only once and
only when creating a `Mount`. This seems slightly dangerous as
any change to an attribute after creation will not update the
id. This means two options:
1. dynamically update the `id` on changes
2. forbid changes after the `id` is calculcated

I went with (2) but happy to discuss of course but it seems more
the spirit of the class.

It also does the same change for "devices.Device"
2024-01-19 02:54:26 +01:00
Michael Vogt
fd2079be60 test: fix test_libc_futimes_works
The test_libc_futimes_works() is failing under RHEL/Centos right
now. To make it more robust a tiny sleep and rounding of the
timestamps is introduced to ensure that we are not run into
floating point comaparison funnines.

The second part of the fix is to open the stamp_file in read-only
mode to ensure that the mtime is not modified by the open itself
which is what lead to the actual test failure.
2024-01-18 08:44:25 +01:00
Michael Vogt
94d8a1357f test: check that mkfs.fat has the -g option in test_fat
Older versions of RHEL/Centos do not have `mkfs.fat -g` yet so
this test will fail. Detect this and skip the test if mkfs.fat
is too old (see 7af2f1a for the original commit).
2024-01-18 08:44:15 +01:00
Michael Vogt
ff10cdb4db test: export schemas in testing_libdir_fixture
When constructing a minimal environment for osbuild the exported
dirs lacked "schemas" so the test_exports.py test failed on RHEL8.

This commit adds it (and also "assemblers" for good measure). With
that the test will pass.
2024-01-18 08:44:07 +01:00
Michael Vogt
e0bbb3397d test: update test_mount.py for lsblk --json differences
Older version of `lsblk --json` will not have the plural `mountpoints`
but only a singular `mountpoint`. But newer version lost the
singular `mountpoint` in the json. Adjust the test accordingly.
2024-01-16 13:51:30 +01:00
Michael Vogt
d96f94fede test: fix new mount tests under rhel8
The new `create_image_with_partitions()` helper fails under rhel8
currently. The reason is that `mkfs.ext4 -E offset=` will warn
in older versions about a partition table and require user input.

This got fixed `e2fsprogs` 1.46.3 in Jul 2021 but RHEL8 still
has 1.45.

[0] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=989612
2024-01-16 13:51:30 +01:00
Dusty Mabe
7d73c0e741 manifests: move osname to a var in fcos manifest
This makes it easier to see/change the value globally.
2024-01-15 11:53:21 +01:00
Dusty Mabe
d9fe4221b0 manifests: move boot/root fs uuid/label to var in fcos manifest
This makes it easier to see the important unique values in our
manifest.
2024-01-15 11:53:21 +01:00
Dusty Mabe
ac8a57c5a3 manifests: set sysroot.readonly config to true in fcos manifest
This is set in Fedora CoreOS today. Let's make it match here.
2024-01-15 11:53:21 +01:00
Dusty Mabe
7cf98cfbf1 manifests: remove partition UUIDs from fcos container manifest
We don't set the UUIDs today in COSA/create_disk.sh so let's not
statically set them here either. This means they'll get set to
something random.
2024-01-15 11:53:21 +01:00
Luke Yang
d089b429a7 stages/org.osbuild.ostree.config: support bls-append-except-default
Support setting the sysroot.bls-append-except-default value in the
OSTree config. This is used by CoreOS to support configuration used
for GRUB password support https://github.com/coreos/fedora-coreos-tracker/issues/1333
2024-01-11 12:55:12 -05:00
Michael Vogt
73ec3122f2 stages,test: update tests for new selinux.setfiles() calling 2024-01-11 10:23:25 +01:00
Michael Vogt
962b7f4d4b test: add test for export option 2024-01-10 11:24:01 +01:00
Dusty Mabe
fdd5d25c1e tests/fedora-coreos-container: switch to testing FCOS
The stable stream currently doesn't have a new enough bootupd to pass
the tests for the bootupd stage. Let's update to `:testing` for now
and we'll switch back to `:stable` later.
2024-01-10 01:15:18 +01:00
Renata Ravanelli
cdcb4598bb create org.osbuild.bootupd stage
Add the bootupd stage to install GRUB on both BIOS and UEFI systems,
ensuring that your bootloader stays up-to-date.

Signed-off-by: Renata Ravanelli <rravanel@redhat.com>
2024-01-10 01:15:18 +01:00
Michael Vogt
ad8fd2f532 testutil: extrace new make_fake_tree() helper
Extract a new helper `make_fake_tree()` that generalizes the existing
helper `make_fake_input_tree()`. The later will always create the
content under `{basedir}/tree` which is convinient for input tree
based tests but too specialized when using it in different contexts.

The existing `make_fake_input_tree()` is preserved unchanged and
becomes just a tiny wrapper.
2024-01-03 11:25:48 -08:00
Michael Vogt
8c95bd9dd7 test: fix autopep8 issues 2024-01-02 19:31:31 +01:00
Michael Vogt
530afa566f test: fix isort issues 2024-01-02 19:31:31 +01:00
Michael Vogt
57b5c7994e test: fix all pylint issues 2024-01-02 19:31:31 +01:00
Michael Vogt
4a86688870 test: deal with missing sfdisk correctly 2024-01-02 18:40:31 +01:00
Michael Vogt
1b297ad0ba test: add more output when ensure_mtime() assert fails 2023-12-22 19:46:48 +01:00
Michael Vogt
8b475bb3f2 test: extend test_mount.py to mount 2 partitions 2023-12-22 10:18:29 -05:00
Michael Vogt
e76e0e92d6 osbuild: take partition into account in calc_id and add test 2023-12-22 10:18:29 -05:00
Michael Vogt
9cf68394d9 test: add mount service test with partitions 2023-12-22 10:18:29 -05:00
Michael Vogt
651a0ff047 test: add test that checks that partition are added to mount stage 2023-12-22 10:18:29 -05:00
Michael Vogt
827b238764 format/v2: add new "partition" field to "describe_mount" 2023-12-22 10:18:29 -05:00
Dusty Mabe
ce8408a9c6 mounts: support mounting partitions
This allows us to map in a whole disk as a loopback device with parition
scanning rather than slicing up the disk and creating several loopback
devices. Something like this:

```
      - type: org.osbuild.copy
        inputs:
          tree:
            type: org.osbuild.tree
            origin: org.osbuild.pipeline
            references:
              - name:tree
        options:
          paths:
            - from: input://tree/
              to: mount://root/
        devices:
          efi:
            type: org.osbuild.loopback
            options:
              filename: disk.img
              start:
                mpp-format-int: '{image.layout[''EFI-SYSTEM''].start}'
              size:
                mpp-format-int: '{image.layout[''EFI-SYSTEM''].size}'
          boot:
            type: org.osbuild.loopback
            options:
              filename: disk.img
              start:
                mpp-format-int: '{image.layout[''boot''].start}'
              size:
                mpp-format-int: '{image.layout[''boot''].size}'
          root:
            type: org.osbuild.loopback
            options:
              filename: disk.img
              start:
                mpp-format-int: '{image.layout[''root''].start}'
              size:
                mpp-format-int: '{image.layout[''root''].size}'
        mounts:
          - name: root
            type: org.osbuild.xfs
            source: root
            target: /
          - name: boot
            type: org.osbuild.ext4
            source: boot
            target: /boot
          - name: efi
            type: org.osbuild.fat
            source: efi
            target: /boot/efi
```

now becomes a little more simple:

```
      - type: org.osbuild.copy
        inputs:
          tree:
            type: org.osbuild.tree
            origin: org.osbuild.pipeline
            references:
              - name:tree
        options:
          paths:
            - from: input://tree/
              to: mount://root/
        devices:
          disk:
            type: org.osbuild.loopback
            options:
              filename: disk.img
              partscan: true
        mounts:
          - name: root
            type: org.osbuild.xfs
            source: disk
            partition:
              mpp-format-int: '{image.layout[''root''].partnum}'
            target: /
          - name: boot
            type: org.osbuild.ext4
            source: disk
            partition:
              mpp-format-int: '{image.layout[''boot''].partnum}'
            target: /boot
          - name: efi
            type: org.osbuild.fat
            source: disk
            partition:
              mpp-format-int: '{image.layout[''EFI-SYSTEM''].partnum}'
            target: /boot/efi
```

Fixes https://github.com/osbuild/osbuild/issues/1495
2023-12-22 10:18:29 -05:00
Michael Vogt
2d72dc125d test: rename TestFileSystemMountService->FakeFileSystemMountService
The rename avoids warnings from pytest. It confuses this for
a unittest class apparently. And it's really a `Fake` service
anyway.
2023-12-21 16:07:35 +01:00
Michael Vogt
e35d841509 objectstore: add new skip_preserve_owner to Object.export()
This commit allows to exclude preserving ownership from an object
export. This is required to fix the issue that on macOS the an
podman based workflow cannot export objects with preserving
ownerships.

Originally this was a `no_preserve: Optional[List[str]] = None)`
to be super flexible in what we pass to `cp` but then I felt like
YAGNI - if we need more we can trivially change this (internal)
API again :)
2023-12-20 09:28:39 +01:00
Luke Yang
5fc3b565a2 create org.osbuild.ostree.aleph stage
Similar to the aleph file created for builds of FCOS based on ostree
commit inputs, this adds an aleph file that contains information about
the initial deployment of data when the disk image was built

A new stage is preferred here as both the org.osbuild.ostree.deploy
and org.osbuild.ostree.deploy.container stages need an aleph file and
use of the aleph file may depend on the project/product. For example,
right now CoreOS is the only project that uses an aleph file, but others
may want it in the future.
2023-12-19 17:58:39 +01:00
Dusty Mabe
96ee2e4bc8 test: update stage diffs for F39 bump
Diffs for stage tests have changed after the sources were updated.
Update them to match expected behaviour. This was mostly done with
some form of:

```
foo=update-crypto-policies;
sudo tools/gen-stage-test-diff --libdir . --store /var/osbuild/store/ test/data/stages/$foo > test/data/stages/$foo/diff.json
```

For the dracut one I had to figure out what new kernel was used
and the new modules and update the vanilla.json file to get the
test to pass.

For the rpm one I had to also update the metadata.json with something
like:

```
sudo python3 -m osbuild --libdir .  --store /var/osbuild/store/ --export tree \
    --output-directory /var/osbuild/out/ test/data/stages/rpm/b.json --json   \
        | jq .metadata >test/data/stages/rpm/metadata.json
```
2023-12-19 17:58:39 +01:00
Dusty Mabe
e077a4ceba manifests/fedora-vars: update to fedora 39
For https://github.com/osbuild/osbuild/pull/1475 we need to pick up
https://bodhi.fedoraproject.org/updates/FEDORA-2023-a3737d3bee so let's
bump to the latest Fedora 39 snapshot.
2023-12-19 17:58:39 +01:00
Alexander Larsson
69028fc016 org.osbuild.systemd: Support masking generators
This adds a new key masked_generators, similar to masked_services,
which masks systemd generators from running at boot, by creating
symlinks to /dev/null in /etc/systemd/systemd-generators, as
described in:
 https://www.freedesktop.org/software/systemd/man/latest/systemd.generator.html#Description

This will be useful for the automotive project, as it allows disabling
of unsupported things like sysv or rc.local legacy support, while
improving boot performance.
2023-12-15 10:01:00 -08:00
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
Michael Vogt
ca9f4038c8 util: add test that validates cache update strategy 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
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
Gianluca Zuccarelli
6d9c6e0bde stages:oscap.autotailor: add key/value overrides
This commit extends the current support for OpenSCAP
tailoring by accepting an array of key/value overrides.
Users will be able to specify override values for specific
rules that will update the value when remediating the
image.
2023-12-04 08:49:47 +01:00
Ondřej Budai
7882db2543 test/data/manifests: add erofs-utils to Fedora buildroot
The next commit will add a stage test that requires erofs-utils. Let's add it
into the buildroot in a separate commit, so the history is more readable.
2023-12-01 10:36:06 +01:00
Michael Vogt
627199543f test: add erofs stage test
Add a simple stage test for the erofs stage. It uses dump.erofs
instead of mounting the file because the kernel in the GH runners
do not support mounting erofs just yet.
2023-12-01 10:36:06 +01:00
Dusty Mabe
e191dc1d0d tools/osbuild-mpp: set part ID from name if missing
For our Fedora CoreOS disk images we set the partition labels (name)
for the partitions. This is also supported using the primitives here
in OSBuild, but it wasn't obvious that I needed to set the name in
the mpp-define-images definition. Let's set the name there, but let's
also allow osbuild-mpp to set the `id`, which is what is used later
to access that partition from the `name` too if `id` isn't set.

This means we allow something like:

   - name: BIOS-BOOT
     type: 21686148-6449-6E6F-744E-656564454649
     bootable: true
     uuid: FAC7F1FB-3E8D-4137-A512-961DE09A5549
     size: 100

rather than requiring something like:

   - id: BIOS-BOOT
     name: BIOS-BOOT
     type: 21686148-6449-6E6F-744E-656564454649
     bootable: true
     uuid: FAC7F1FB-3E8D-4137-A512-961DE09A5549
     size: 100
2023-11-29 10:37:08 +01:00