Commit graph

27 commits

Author SHA1 Message Date
Simon de Vlieger
2141168e44 test(stages/skopeo): schema validation
Minor schema validation test.
2023-12-12 23:08:19 +01:00
Michael Vogt
4e3fc6a625 osbuild: pytoml is deprecated, replace with toml
Pytoml is no longer being maintained: https://github.com/avakar/pytoml
The author suggest switching to toml.

We already use the
```
try:
    import toml
except ModuleNotFoundError:
    import pytoml as toml
```
pattern in stages/org.osbuild.containers.storage.conf so use it in the tests too to prefer "toml" instead of pytoml.
2023-12-12 14:06:50 -08:00
Brian C. Lane
77d775b2ba test: Add a test for the org.osbuild.zstd stage 2023-12-12 19:45:04 +01:00
Brian C. Lane
5dd6fb7c4c test: Add a test for the org.osbuild.xz stage 2023-12-12 19:45:04 +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
Alexander Larsson
891bbcec17 Add test for org.osbuild.containers.storage.conf stage 2023-12-12 09:54:38 +01:00
Simon de Vlieger
1b5ab0ee03 stages(kickstart): mutual exclusive ostree options
These options are mutually exclusive, this updates the schema and test
case to ensure this is detected at schema validation time.
2023-12-08 14:29:52 +01:00
Simon de Vlieger
20d8d3a9a8 stages(kickstart): add ostreecontainer
Add support for the `ostreecontainer` kickstart command, see:
https://pykickstart.readthedocs.io/en/latest/kickstart-docs.html#ostreecontainer
2023-12-08 14:29:52 +01:00
Michael Vogt
0767ebccc1 stages(autotailor): add small unit test
Small unit test for PR#1407.
2023-12-04 14:34:17 +01:00
Michael Vogt
d4a0837cf0 stages(erofs): add tests and fix small bug in options handling
This adds tests for the erofs stage. The tests are slightly different
from the existing tests that run the filesystem utils inside the
stages. Depending on what exactly we want to test we may still need
a run inside the stages. However running this inside a container
should be good enough if we just want to validate that the options
are passed correctly and the file is created.
2023-12-01 10:36:06 +01:00
Michael Vogt
0a2e0bb3d2 stages: add org.osbuild.machine-id stage
This is a variation of PR https://github.com/osbuild/osbuild/pull/960
that put the machine-id handling into it's own stage and adds
explicit handling what should happen with it.

For machine-id(5) we essentially want the following three states
implemented:

1. `first-boot: yes` will ensure that /etc/machine-id is
   in the "uninitialized" state. This means on boot the systemd
   `ConditionFirstBoot` is triggered and a new id in `/etc/machine-id`
   is created. This will work for systemd v247+.
2. `first-boot: no` will ensure that /etc/machine-id exists but
   is empty. This will trigger the creation of a new machine-id but
   will *not* trigger `ConditionFirstBoot`.
3. `first-boot: preserve` will just keep the existing machine-id.
   Note that it will error if there is no /etc/machine-id

Note that the `org.osbuild.rpm` will also create a
`{tree}/etc/machine-id` while it runs to ensure that postinst
scripts will not fail that rely on this file. This is an
implementation detail but unfortunately the rpm stage will
leave an empty machine-id file if it was missing. So we cannot
just remove /etc/machine-id because any following rpm stage
would re-create it again (and we cannot change that without
breaking backward compatiblity). Thanks to the special semantic
that a missing /etc/machine-id and an /etc/machine-id with
the `uninitialized` string are equivalent we don't care.

To support systemd versions below v247 we could offer an option
to remove /etc/machine-id. But the downside of this is that
it would only work if the org.osbuild.machine-id stage is after
the rpm stage.

See also the discussion in PR#960.

Thanks to Tom, Christian for the PR and the background.
2023-11-30 13:30:32 +01:00
Michael Vogt
3b7471ab7c stages(kickstart): add validation for the hostname
The hostname is validated according to the rules of `hostname(7)`
and tests are added to validate them.
2023-11-27 15:10:29 +01:00
Michael Vogt
2116803e32 stages(kickstart): add validation for device
This adds basic validation for the network `device` in the kickstart
stage. There are multiple ways that a `device` can written, see
https://pykickstart.readthedocs.io/en/latest/kickstart-docs.html#network
for details.

When written as device name then this is checked by the kernel in
https://elixir.bootlin.com/linux/v6.6.1/source/net/core/dev.c#L1038
and it's very free from. Our validation is stricter, if this becomes
a problem we can relax it more.

When written as a mac address the pattern will ensure it's written
in exactly this way.
2023-11-27 15:10:29 +01:00
Michael Vogt
60e78f5084 stages(kickstart): add ipv4 related regex pattern checks
Check for valid ipv4 addresses via a regex in the schema and
add matching tests. This will ensure that only valid ipv4
addresses can be entereed in "ip", "gateway" or "nameservers".

Note that libc/kernel accept invalid ipv4 addresses and do
"interesting" things with them. So they accept `127.1` and
turn that into `127.0.0.1` or even `127.256` and turn that
into `127.0.1.0` because 256 overflows into the next segment
(thanks to Simon for poiting this out). If this becomes a
problem and customers rely on invalid ipv4 addresses we will
need to relax the rules but let's start strict and help our
users with more guardrails.

Note that no ipv6 validation via regex is done. The regex
on stackoverflow for validating ipv6 is 660 chars long
and that seems a bit too long for our schemas and putting
and error with that in front of our users.
2023-11-27 15:10:29 +01:00
Michael Vogt
3b346a6a30 stages(kickstart): add network support to kickstart
This commit adds `network`support to the kickstart stage [0].

[0] https://docs.fedoraproject.org/en-US/fedora/f36/install-guide/appendixes/Kickstart_Syntax_Reference/#sect-kickstart-commands-network
2023-11-27 15:10:29 +01:00
Michael Vogt
4884dc882d stages(ostree.post-copy): add stage unit test and comment
This commit adds a small stage unit test and most importantly
a comemnt why `devices` is part of the schema (but appears unused).

The reason "devices" is explained by Alex Larsson:
"""
The mounts don't work without devices that have the filesystems.
In sample-images for example, this is typically used like so:
```
type: org.osbuild.ostree.post-copy
devices:
  root:
    type: org.osbuild.loopback
    options:
      filename: disk.img
mounts:
- name: root
  type: org.osbuild.ext4
  source: root
  target: /
```
"""
2023-11-27 13:39:20 +01:00
Michael Vogt
5407f1cef1 stages(kickstart): support autopart
This commit implements the `autopart` kickstart option and adds
matching tests.
2023-11-15 18:21:34 +01:00
Michael Vogt
c9d42865ed stages(kickstart): implement "display_mode" option(s)
This implements the display mode options `text`, `graphical`,
`cmdline` as an enum with the name `display_mode`.

See PR#1442 for the rational/discussion of this over using
three boolean options.

Thanks to Achilleas and Tom!
2023-11-15 09:34:49 +01:00
Michael Vogt
2c41bcde68 stages(kickstart): ensure no extra options under clearpart
Fix an oversight from https://github.com/osbuild/osbuild/pull/1426
2023-11-15 09:34:49 +01:00
Michael Vogt
9f4bd1fc31 stages(kickstart): ensure test inputs pass schema validation
Now that inputs can be relatively easily validated against
the schema this should also be used for all the "good" test
inputs to ensure that all tests test against valid inputs.
2023-11-10 14:44:59 +01:00
Simon de Vlieger
910a4b556b stage/test: kickstart test split
Split out the kickstart tests between checking contents and validating,
this allows to skip the validation tests if ksvalidator isn't available.
2023-11-10 12:03:23 +01:00
Michael Vogt
be85b2342c stages(kickstart): ensure clearpart dict always has an option set 2023-11-10 09:23:33 +01:00
Michael Vogt
cce0eeaba4 stages(kickstart): implement "reboot" option
This commit implements the `reboot` option for kickstart files.

Note that there are two ways this can be enabled via the json.
Either via a boolean or by passing a dict with options.
```
{"reboot": true}
{"reboot": {"eject": true, "kexec": true}
```

Passing the empty dict
```
{"reboot": {}}
```
is not allowed by the schema.
2023-11-10 09:23:33 +01:00
Michael Vogt
b9ad7dd1be stages(kickstart): add test for schema validation
Add functional/regression around the schema validation for the
kickstart stage. The goal is to ensure that the regexp matching
in the schema allows the expected uses and rejects clearly
forbidden ones.
2023-11-09 11:45:11 +01:00
Michael Vogt
2c3f54dc90 stages(kickstart): add unittest test for zerombr/clearpart
Trivial followup for PR#1426 to include unit test output about
the expected kickstart file.
2023-11-09 09:41:44 +01:00
Michael Vogt
ce8bc6dc1f stages(kickstart): run ksvalidator as part of the tests
Run `ksvalidator` as part of the test_kickstart.py tests. This
ensures that the file we write is valid.
2023-11-08 18:49:35 +01:00
Michael Vogt
ed95c10530 stages: add new unit test for kickstart stage
This commit adds a simple and lightweight unit test for the new
kickstart options. It's pretty simple but also cheap and runs
fast.
2023-11-07 15:12:08 +01:00