Commit graph

2761 commits

Author SHA1 Message Date
Michael Vogt
2290aff94d check-snapshots: add log info when a download fails
When a requests.get() fails the exact nature of the error is
currently discarded. This commit adds a small print() to show
what exactly went wrong.
2024-02-20 14:52:23 -08:00
Michael Vogt
34cda2e1e3 check-snapshots: make exception for snapshot cache more targeted
The code in `check-snapshots` will print "No snapshots cache found
at ..." regardless of the error that happens when trying to open
the file. This can be misleading if e.g. the issue is permissions
to open the file or the file is corrupted. So make the exception
more targeted and only catch FileNotFound error and let python
how the full error for the other cases. Obviously this can be
done in many ways so I'm happy to tweak and e.g. keep catching
all exception but print the value etc.
2024-02-20 14:52:23 -08:00
Michael Vogt
2c86e90d05 tools: make check-snapshots pylint clean 2024-02-20 14:52:23 -08:00
Michael Vogt
5c47be179c tox: add all non shell file in tools/ to lintables
Right now the tools directory is not checked by pylint because
it will not auto-detect what files are python files and instead
just skip the dir if it does not have a __init__.py.

This commit uses `tox-backticks` to run a custom find to ensure
the python files are explicitely added. I'm not sure we can
use tox-backticks or we need it packages for fedora/rhel?

If we cannot use it we need to look into either a custom tox
plugin to support more rich globbing or just move out
`tools/set-env-variables.sh` as it's the only non-python code
in the repo and it will trip up pylint (syntax error).
2024-02-20 14:52:23 -08:00
Tomáš Hozza
be1ba5be08 Stages/grub2: extend default config options
Extend the stage to allow explicitly configuring more grub2 default
config options. Preserve the defaults for options which were previously
hard-coded.

Extend the stage unit test to verify setting of the new grub2 default
config options.

Related to https://issues.redhat.com/browse/RHEL-19583

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-02-20 19:28:43 +01:00
Tomáš Hozza
84fc4c9903 Extend unit test for org.osbuild.grub2 stage
Test the content of the /etc/default/grub config file based on the
provided stage options.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-02-20 19:28:43 +01:00
Tomáš Hozza
7895424b78 Stages/grub2.legacy: extend default config options
Extend the stage to allow explicitly configuring more grub2 default
config options. Preserve the defaults for options which were previously
hard-coded.

Extend the stage unit test to verify setting of the new grub2 default
config options.

Related to https://issues.redhat.com/browse/RHEL-19583

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-02-20 19:28:43 +01:00
Tomáš Hozza
21ebed9305 Add unit test for org.osbuild.grub2.legacy
For now, test the content of /etc/default/grub configuration file.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-02-20 19:28:43 +01:00
Brian C. Lane
b131d3cf57 osbuild-depsolve-dnf5: Fix url substitutions
Substitutions should be set on Base, not per-repo. Discovered this
in lorax's dnf5 code so I am updating it here as well.
2024-02-20 09:42:01 +01:00
Brian C. Lane
4f83cdc434 osbuild-depsolve-dnf5: module_hotfixes wasn't really set
Typo in the previous change, wasn't setting `repo.module_hotfixes`
2024-02-20 09:32:43 +01:00
Michael Vogt
43c83c01e6 stages(org.osbuild.systemd.unit.create): add small unit test
Small unit test for the new `org.systemd.unit.create` stage. It
will do basic schema validation checks and ensures that a simple
service definition is correctly translated to a systemd unit.
2024-02-19 15:12:55 +01:00
Evgeny Kolesnikov
46e1bc1e2b stages/oscap.remediation: Mount host's /proc and /dev earlier
We need /dev/urandom for the first pass as well.
2024-02-17 02:10:58 +01:00
Michael Vogt
90193d007f stages/bootc.install-to-fs: fix root mount handling
The bootc.install-to-filesystem code needs to run against the
root directory of a mounted tree, i.e. with /boot, /boot/efi
mounted. So change the code so that the target dir is the
the "mounts" paths. This is similar to how bootupd works and
the caller need to arrange the right mount setup there.
2024-02-16 18:05:50 +01:00
Sayan Paul
e858dc72c3 stage/systemd-unit:stage to create systemd unit file
Add systemd unit files in osbuild stage

This stage creates systemd unit file in `/usr/lib/systemd/system/`.
The stage accepts filename which must end with `.service`.Section
`Unit` , `Service` , `Install` accepts various parameters as per
the systemd documentaion.`systemd-analyze verify` is be performed
after the .service file is created to check for potential errors.

Signed-off-by: Sayan Paul <paul.sayan@gmail.com>
2024-02-16 11:55:11 +01:00
Achilleas Koutsou
f9e35c25da Schutzfile: Fedora-40 branched
Fedora 40 has branched.  Let's update the repo snapshots in the
Schutzfile.

xref https://github.com/osbuild/rpmrepo/pull/92
2024-02-16 11:55:11 +01:00
schutzbot
c164665db1 Post release version bump
[skip ci]
2024-02-14 08:13:58 +00:00
Michael Vogt
c3af3173eb stages(container-deploy): podman mount failure test/tweaks
This commit adds a test that ensures that the output of
podman mount is part of the error message. While writing
the test I also tweaked the code slightly so that we only
try to `podman umount` if we managed to successfully mount.
2024-02-12 17:41:21 -08:00
Michael Vogt
7b5d6e4bd9 testutil: add new mock_command context manager
The new `testutil.mock_command` context manager can be used to
mock commands in PATH and replace them with arbitrary shell
scripts. This is useful in testing to e.g. simulate exact error
conditions that would be hard to trigger otherwise or to replace
long running commands with faked results.

Example:
```
fake_cmd = textwrap.dedent("""\
do-something
""")
with mock_command("some-cmd", fake_cmd):
   your_code
```
2024-02-12 17:41:21 -08:00
Brian C. Lane
291f5cc29e Revert "osbuild-depsolve-dnf: port weak dependencies"
This reverts commit e023fdec1b.

Ends up this was based on an older version of dnf-json, the correct
behavior is to use the "install_weak_deps" bool.
2024-02-13 00:17:16 +01:00
Dusty Mabe
f334ca92c6 manifests: convert a few more ostree deployments
These were missed in the initial conversion.
2024-02-12 11:25:11 -05:00
Dusty Mabe
3fdb62e548 mount/ostree.deployment: Fix ostree deployment call
We need to pass in the root of the ostree deployment which can
be the tree or the mount. Fixes e1cbf92
2024-02-12 11:25:11 -05:00
Brian C. Lane
8389c6302e osbuild-depsolve-dnf5: Add module_hotfixes support 2024-02-12 17:08:32 +01:00
Simon Steinbeiss
c431e7e340 README: Add OSBuild's principles 2024-02-09 13:59:58 +01:00
Michael Vogt
c0f670f035 test: add manifests for bootc.install-to-filesystem
This commit adds example manifests for a bootc.install-to-filesystem
system. It does not do more with them because running a full test
requires a working podman which is difficult to use inside our
GH runners that are already running inside docker.
2024-02-09 12:03:09 +01:00
Michael Vogt
7dede7746d osbuild-mpp: add bootc.install-to-filesystem to process_containers 2024-02-09 12:03:09 +01:00
Michael Vogt
af360b0d71 stages: add test for bootc.install-to-filesystem 2024-02-09 12:03:09 +01:00
Ondřej Budai
226b50eba5 stages: add new org.osbuild.bootc.install-to-filesystem
Support the `boot install to-filesystem` capability to install a
bootc image to a filesystem.
2024-02-09 12:03:09 +01:00
schutzbot
a85b51bb2c Post release version bump
[skip ci]
2024-02-08 14:03:15 +00:00
Luke Yang
619a64f0bd stages/org.osbuild.qemu: make qcow2 compression optional
Modify the stages/org.osbuild.qemu stage such that compression is
optional. This resolves the image size differences between an image
built with coreos assember vs osbuild, as discussed in:
https://github.com/coreos/fedora-coreos-tracker/issues/1653#issuecomment-1928342241
2024-02-07 20:31:10 -05:00
Dusty Mabe
e1cbf92673 ostree: add convenience function for using default OSTree deployment
This adds a `default: true` option for all cases where OSTree
information is specified in schemas and allows for the information
to be picked up from the filesystem.

This is a safe operation because when building disk images there is
no known case where having two deployments makes sense. In the case
there ever were a case then the osname, ref, and serial options still
exist and can be used.

Co-authored-by: Luke Yang <luyang@redhat.com>
Co-authored-by: Michael Vogt <michael.vogt@gmail.com>
2024-02-07 18:50:38 -05:00
Dusty Mabe
2021b915f1 stages(copy): allow copying from a mount or the tree
It seems like an artifical limitation to prevent copying from a mount
or from one location in the tree to another. It just so happens we need
this functionality when building CoreOS images because we want to take
a file embedded in the OSTree at a location and copy it to another
location in the tree. The particular example here is we want to copy
/usr/share/coreos-assembler/platforms.json -> /boot/coreos/platforms.json
See https://github.com/coreos/coreos-assembler/pull/3709

Allowing to copy from/to the tree we can now do something like:

```
- type: org.osbuild.copy
  options:
    paths:
      - from: tree:///usr/share/coreos-assembler/platforms.json
        to: tree:///boot/coreos/platforms.json
  mounts:
    - name: ostree.deployment
      type: org.osbuild.ostree.deployment
      options:
        deployment:
          ref: ostree/1/1/0
          osname:
            fedora-coreos
```
2024-02-07 18:38:03 -05:00
Diaa Sami
e023fdec1b osbuild-depsolve-dnf: port weak dependencies
ported from d48da99a12
2024-02-08 00:12:32 +01:00
Michael Vogt
705397e7f6 test: add simple zipl_inst tests
Co-authored-by: Nikita Dubrovskii <nikita@linux.ibm.com>
2024-02-07 18:08:44 -05:00
Nikita Dubrovskii
e427289887 stages(zipl.inst): support appending kernel options
In some cases it could useful to add additional kernel options without
modifying BLS config, so any subsequent call to `zipl` would ignore them.
We are going to use this to append `ignition.firstboot` to kernel cmdline
for CoreOS on s390x.
2024-02-07 18:08:44 -05:00
Diaa Sami
c673eab2b5 osbuild-depsolve-dnf: port module_hotfixes support over
from 61e6f75281
2024-02-08 00:03:59 +01:00
Colin Walters
161c19601a container-deploy: Output stderr on failure
This stage was failing for me in bib, with this change I now
get more useful information from podman's stderr, e.g.:

```
RuntimeError: Failed to mount image (125): time="2024-02-06T14:23:06Z" level=error msg="Unmounting /var/lib/containers/storage/overlay/06456126e7c06cf1b21de024e08e64eddead2b8d03779be213e63aeeea9dec94/merged: invalid argument"
Error: creating overlay mount (...snip...)
fuse: device not found, try 'modprobe fuse' first
fuse-overlayfs: cannot mount: No such file or directory
```
2024-02-07 16:11:19 +01:00
Achilleas Koutsou
6e12f08a29 test: add bootupd.gen-metadata stage test
Since the stage depends on quite a specific tree state (ostree prepped
tree with boot files), we can't really unit test it any simpler than
generating a tree with and without running the stage and diffing the
tree.
2024-02-07 12:10:01 +01:00
Achilleas Koutsou
d75f43ff7b stages: add new org.osbuild.bootupd.gen-metadata stage
Runs bootupctl generate-update-metadata in the tree to transform
/usr/lib/ostree-boot into a bootupd-compatible update payload.

This stage should be run on the sysroot of an ostree deployment or
ostree-converted tree.
2024-02-07 12:10:01 +01:00
Dusty Mabe
011cf6851b stages(ostree.config): support setting sysroot.bootprefix
See https://github.com/ostreedev/ostree/pull/2705 and also
https://github.com/osbuild/osbuild/issues/1566.
2024-02-07 11:28:24 +01:00
Dusty Mabe
151b6e48ae stages(sgdisk): support label option
We only support `gpt` here so it would seem this option doesn't
make much sense to add, but it will make it so that the mpp-define-images
from osbuild-mpp can be passed in to `org.osbuild.sgdisk` just as it
can be passed in today to `org.osbuild.sfdisk`.
2024-02-06 17:44:31 +01:00
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
Sanne Raymaekers
25df4d76a6 stages(tar): add unit test 2024-02-06 12:43:53 +01:00
Sanne Raymaekers
df663ada8a stages(tar): add paths option
This adds an optional `paths` option to the tar stage. If specified, the
paths will be included in the tarball in order.

The OVA image needs to have its contents in a specific order in the
archive.
2024-02-06 12:43:53 +01:00
Simon Steinbeiss
0b33adcec1 README: Drop alternative hyperlink markdown 2024-02-03 18:29:12 +01:00
Djebran Lezzoum
cdc410bb00 stages(kickstart): Add missing rootpw, initlabel, nohome
In the context of specific ostree installation we are missing some kickstart options:
1. rootpw option (despite we only need rootpw --lock, implement the full spec found here https://pykickstart.readthedocs.io/en/latest/kickstart-docs.html#rootpw)
2. initlabel a property of clearpart option
3. nohome a property of autopart
FIXES: https://issues.redhat.com/browse/THEEDGE-3835
2024-02-02 18:42:58 +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
Dusty Mabe
bd6b8ffb83 mounts/ostree.deployment: support deployments on mount
Instead of operating directly on the tree for a stage we can operate
on a mount too. This is useful in the case where operating on the
directory tree of files isn't sufficient and the modifications need
to be made directly to the filesystems on the disk image that we are
creating.

One such example of this is we are having a problem right now 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.

In this change here we also add a check in osbuild/mounts.py to not
attempt a umount of the root of the mounts directory if that path
is no longer a mountpoint, which can happen when the umount -R
from the mounts/org.osbuild.ostree.deployment also removes the
overmount.

Here is an example of how this would be used:

```
  - type: org.osbuild.chattr
    options:
      immutable: true
      path: 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: ostree.deployment
        type: org.osbuild.ostree.deployment
        options:
          source: mount
          deployment:
            osname: fedora-coreos
            ref: ostree/1/1/0
```

The initial mount on `/` is the filesystem from the root partition
on the disk. The second mount (of type org.osbuild.ostree.deployment)
then reconfigures things similar to how an OSTree system is set up.
2024-01-31 16:46:01 -05:00