Commit graph

861 commits

Author SHA1 Message Date
Gianluca Zuccarelli
8b67b02dfa test/cases: fix users stage
Since the `/etc/shadow` file contains a timestamp we need to add a
`null` value rather than a `sha256` hash to tell the diff tool to ignore
these fields. The issue is that the timestamp will always be different
meaning the tests will pass for a day, but then fail after that.
2024-06-06 14:48:32 +01:00
Tomáš Hozza
1d0952002b Test/stages/users: fix diff.json
I'm not sure what happened, but the test case started failing on the
diff on 'main'. I didn't change anything related to this test case in my
PR. The previous changes adjusted the vars, specifically the Fedora
snapshot date used to generate the manifests, but the test passed on
it.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-06-04 19:39:39 +02:00
Tomáš Hozza
c06fda60b6 Test/stages: update udev.rules test case to not use F34
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-06-04 19:39:39 +02:00
Gianluca Zuccarelli
8985155157 test: test autotailor json import
Add a test to ensure that json tailoring import is supported for the
`oscap.autotailor` stage.
2024-05-31 19:51:46 +01:00
Gianluca Zuccarelli
ad265a519d test: update stage diffs for snapshot 20240514
Since updating the snapshots the diffs for some stage tests have
changed. This commit updates the diffs accordingly.

I followed the same steps used in 1148a6e.
2024-05-31 19:51:46 +01:00
Gianluca Zuccarelli
3f92d91fbf manifest/fedora-vars: update snapshot
We need a minimum version of `oscap-utils-1.3.10` which is available
in the `20240508` updates snapshot.
2024-05-31 19:51:46 +01:00
Tomáš Hozza
13035e6f4e Test/manifests: use SHA256 signed GPG key for c9s
The original CentOS Stream GPG key uses SHA-1 in its signature. However,
SHA-1 is by default not allowed by the c10s / el10 crypto policy. As a
result, running the stage tests which use c9s on c10s / el10 are failing
when rpmkeys tries to import the key.

As part of CS-1616 [1], the CS GPG key has been resigned using SHA256,
however only in c10s for now. Let's use the SHA256 signed GPG key from
c10s for c9s manifests, to make tests pass also on c10s / el10.

[1] https://issues.redhat.com/browse/CS-1616

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-05-30 20:56:33 +02:00
Michael Vogt
ad13333f36 test: tweak test_osbuild_mount_failure_msg() for tmt/fc40
The `test_osbuild_mount_failure_msg` currently fails on fc40 when
run in tmt, see:
https://artifacts.dev.testing-farm.io/c6588a82-a2cb-46df-8ca8-85dd809465f2/

This is because the failure output is slightly different between
a container and a VM/real-machine. The test ensures that we capture
the output of mount and present to the user (for easier debugging).
So this commit updates this test once more for the error string
(that part of the error comes directly from the kernels fsconfig).

If we need another update of the string we should reconsider this
test and e.g. just use `testutil.mock_command()` for this. But
for now it's easier to just add this one more failure string.
2024-05-23 14:56:41 +02:00
Tomáš Hozza
2161798312 Test/buildroot: fix checking /var/tmp mode
The motivation for this change is to fix a failing unit test in c9s
CI. Specifically an instance of:

https://artifacts.dev.testing-farm.io/2d07b8f3-5f52-4e61-b1fa-5328a0ff1058/#artifacts-/plans/unit-tests
https://gitlab.com/redhat/centos-stream/rpms/osbuild/-/merge_requests/135

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-05-16 09:58:38 +02:00
Paweł Poławski
91c6352c80 tests: Update stage tests readme
Readme was pointing to the dead ling with manifest v2 documentation.
I have redirected it to the documentation presented in repo.
2024-05-13 11:19:26 -07:00
Michael Vogt
4f4bddcc75 test: add "functional" test for devices/mounts acceptance
This test ensures that the inputs of devices/mounts we generate for
bootc are actually considered valid by the schema. This is a more
blackbox style test compared to `test_get_schema_automatically_added`
which just checks that we get the expected schema but not that the
expected schema actually parses our inputs.
2024-05-03 11:26:22 +02:00
Michael Vogt
a0d4dfa575 osbuild: fix error match in mount test for fc40
Similar to 4a51baf this fixes another issue in the mount error
checking where the error message changed.
2024-05-02 12:09:44 +02:00
Florian Schüller
8b5e2a67a6 test_clamp_mtime: avoid clashing with chrony
Any sub-second or larger time adjustments by chrony or similar
would corrupt this time sensitive test without a
counter measure like this
2024-04-27 00:00:10 +02:00
Michael Vogt
a3f86a0736 testutil: fix make_container() cleanup
During the work on PR#1752 Florian discovered that make_containers()
is broken for nested containers like:
```
with make_container(tmp_path, {"file1": "file1 from base"}) as base_tag:
    with make_container(tmp_path, {"file1": "file1 from final layer"}, base_tag) as cont_tag:
```
It errors with:
```
Error: 5b947de461ee21b858dd5b4224e80442b2f65b6410189147f2445884d9e4e3d8: image not known
```
The reason is that we work with hashes for the image and then call
`podman image rm` which by default will also remove all dangling
references. Those are defined by not having a tag and not referenced
anymore. So the inner container cleanup also removes the outter.

There are many ways to fix this, I went with re-adding tags to the
test containers because it also makes it easy for the user to see if
we left any containers (accidently) around.
2024-04-25 21:59:40 +02:00
Michael Vogt
4a51bafa46 osbuild: fix error match in mount test for rawhide
Latest util-linux mount uses fsconfig(2) instead of mount(2) so the
error is different.

See https://artifacts.dev.testing-farm.io/53b552b6-5753-47e2-9cd0-43fa8b6e5f9f/

Closes: https://github.com/osbuild/osbuild/issues/1753
2024-04-25 11:07:49 +02:00
Achilleas Koutsou
1f0f18d281 test/stages/systemd: add -.mount unit to test
Create a unit using an inline file called -.mount with the following
content:

  [Unit]
  Before=local-fs.target
  After=blockdev@dev-disk-by\x2duuid-af34257d\x2d3e14\x2d4a51\x2db91d\x2dc430a956dcba.target

  [Mount]
  What=/dev/disk/by-uuid/af34257d-3e14-4a51-b91d-c430a956dcba
  Where=/
  Type=ext4
  Options=rw,noatime

  [Install]
  RequiredBy=local-fs.target

and enable it in the systemd stage to test that we can enable units with
a - prefix.
2024-04-23 19:59:44 +02:00
Michael Vogt
659f1f06f2 meta: automatically allow devices as input in the stages schemas
With the new `bootc install to-filesystem` support many stages
will need a devices/mount setup to bind mount the deployment root
from the bootc deployment root of the generated image. To make
this globally available just allow "devices/mounts" for all stages
in the schema validation.

Note that `mounts` is already globally allowed so this just adds
devices (this was added in `7e776a076` with ostree as the use-case).
Nothing will change for the filesystem stages that already define
"devices" in a more specialized way.
2024-04-16 08:04:43 +02:00
Achilleas Koutsou
420aacb82e test: regenerate test repository metadata
In 599d3a8730 the repository files weren't
all updated and the metadata was inconsistent.
2024-04-16 07:38:18 +02:00
Michael Vogt
599d3a8730 tools: rename "nothing" to "pkg-with-no-deps" to make it a bit clearer
Tweak the package name a bit to more it very explicit what it's about.
2024-04-11 12:45:25 +02:00
Achilleas Koutsou
bc08eed1ef test: add repository metadata for osbuild-depsolve-dnf
Add two test rpm metadata directories that can be served as RPM repos.
One was copied from osbuild/images and contains the repository metadata
for CentOS Stream 9 BaseOS.
The second was created by building a simple spec file into an RPM and
creating the metadata using createrepo.
2024-04-10 16:22:13 -07:00
Michael Vogt
7279c44c53 test: add StageTests.test_zip() to run zip inside a stage too
Similar to the tar test this adds a zip test that runs inside
the stages.
2024-04-04 13:54:34 +02:00
Luke Yang
ac8a2a4f30 stages: add org.osbuild.zip
In CoreOS Assembler, some hyperv artifact we `zip` for compression. This
new stage is modeled after the `org.osbuild.tar` stage with necessary
modifications.
2024-04-04 13:54:34 +02:00
Achilleas Koutsou
7b004a297e test/systemd.unit: Environment option object
Add an org.osbuild.systemd.unit stage using the new format for the
Environment option with two instances to the test manifest.

The contents of the new dropin file at
tree/usr/lib/systemd/system/boltd.service.d/30-boltd-debug.conf are:

[Service]
Environment="G_MESSAGES_DEBUG=all"
Environment="G_MESSAGES_TRACE=none"
2024-04-04 10:36:04 +02:00
Achilleas Koutsou
80c84020dd test/systemd.unit.create: add new options to test
Add the new options to the b.json test and update the diff.

The new file has the following contents:

[Unit]
Description=Create directory
DefaultDependencies=False
ConditionPathExists=|!/etc/myfile
ConditionPathIsDirectory=|!/etc/mydir

[Service]
Type=oneshot
RemainAfterExit=True
ExecStart=mkdir -p /etc/mydir
ExecStart=touch /etc/myfile
Environment="DEBUG=1"
EnvironmentFile=/etc/example.env

[Install]
WantedBy=local-fs.target
RequiredBy=multi-user.target
2024-04-04 10:36:04 +02:00
Achilleas Koutsou
c72f1bc54e test/systemd.unit.create: add empty file to a.json
Add an empty file to the location where the service file will be
created in the b.json version of the test.  This way, we will get a
content hash of the created file which is a slightly better test than
just knowing that it was created.

Note that, in the diff, the "before" checksum is the empty file hash:

    echo -n '' | sha256sum
    e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855  -
2024-04-04 10:36:04 +02:00
Achilleas Koutsou
d1fc2cd6b6 test/systemd.unit.create: fix b.mpp.yaml
In 2d2cdd8097 the file was replaced by
the generated json and it went unnoticed in the PR.  Reverted and
updated the options to match the generated json file.
2024-04-04 10:36:04 +02:00
Achilleas Koutsou
1366976dd8 test: reformat all json files
Reformat all test json files for consistency.

Formatted with `js --indent 2 .`
2024-03-26 01:20:37 +01:00
Michael Vogt
249107a028 stages,test: fix lint errors and add basic unit tests
Add very simple unit tests as a starting point for the new
parsing functions in `util/parsing.py`.
2024-03-25 18:26:53 +01:00
Michael Vogt
345516e867 osbuild: ensure /var/tmp is a real directory
This is a followup for https://github.com/osbuild/osbuild/pull/1649

Instead of symlinking /var/tmp to /tmp which may be on a tmpfs
this commit puts it on a real filesystem.

This should fix:
https://github.com/osbuild/bootc-image-builder/issues/285
2024-03-20 20:36:26 +01:00
Michael Vogt
0528ccc3f0 osbuild: add support to exclude_paths to setfiles()
This is needed because on a mounted `bootc` container `setfiles`
without excluding `/sysroot` will create many warnings like:
```
setfiles: conflicting specifications for /run/osbuild/tree/sysroot/ostree/repo/objects/00/0ef9ada2ee87792e8ba21afd65aa00d79a1253018832652b8694862fb80e84.file and /run/osbuild/tree/usr/lib/firmware/cirrus/cs35l41-dsp1-spk-prot-103c8b8f-r1.bin.xz, using system_u:object_r:lib_t:s0.
```
but simply excluding this dir fixes them.
2024-03-20 18:05:51 +01:00
Simon de Vlieger
6b4bb850a7 meta: ensure caps always a set
When loaded directly from JSON the caps are a list while they're
expected to be a set.
2024-03-19 15:32:45 +01:00
Simon de Vlieger
8f7d029e9f stage: schema allows for any of schema/schema_2
Instead of requiring only one of the properties to be present require at
least one of them being present; some stages specify both schema
versions (`org.osbuild.rpm`)
2024-03-19 15:32:45 +01:00
Sayan Paul
548d2a51ea stage/unit-create:new systemd unit config params
Added new systemd unit config : ConditionPathIsDirectory

Signed-off-by: Sayan Paul <paul.sayan@gmail.com>
2024-03-19 10:19:26 +01:00
Michael Vogt
9393211b8a testutil: tweak mock_command to write a call_log
Instead of just mocking the binary also write a log of the way
it got called so that tests can use this to check if the right
options are passed.

Note that the API should be improved here, instead of returning
a "naked" path to the calllog file there should be a class wrapping
it. And of course there should be tests.
2024-03-18 20:37:21 +01:00
Michael Vogt
fd0167f130 test: return container_id in make_container
The current `make_container()` helper is a bit silly (which is
entirely my fault). It requires a container tag as input but all
tests end up creating a random number for this input. So instead
just remove the input and return the container_id from the podman
build in the contextmanager and use that.
2024-03-18 20:36:19 +01:00
Michael Vogt
a7b4565445 meta: add tests for invalid python json/schema parsing
Based on the feedback from Tomáš in [0] this commit adds tests
that ensure consistent behavior between the python and the json
loader.

It's not 100% because the python is extremly leaniant and does
not even check if the required pieces of the json are there.
I.e. it will load a module without a SCHEMA or SCHEMA_2 variable
and the json loader code will warn about the issue but not
raise an error.

Fwiw, I have no strong opinion here but I do lean slightly towards
staying close to the original code (but both approaches of failing
with an exectption and continue with a warning have good arguments).

[0] https://github.com/osbuild/osbuild/pull/1618#discussion_r1521141148
2024-03-14 13:37:57 +01:00
Michael Vogt
9af7c9b279 meta: add .meta.json schema validation 2024-03-14 13:37:57 +01:00
Michael Vogt
3e11b57815 meta: rename -meta.json to .meta.json
With `.meta.json` it's two "real" file extension. The `-meta.json`
feels less clear.
2024-03-14 13:37:57 +01:00
Michael Vogt
9b09ed9eb4 osbuild: allow json data to come from a {stage}-meta.json file
Instead of always parsing the python stage to load meta information
allow the user of a new `{stage}-meta.json` file. This is a first
step towards allowing modules to be written in a different language
than python. It also has some practical advantages:
- slightly faster as it avoids calling python to output the schemas
- easier to write schemas as this can be done in a real json editor
  now
- more extensible in a future where stages maybe binaries with
  shlib dependencies that are only satisfied in the buildroot
  but not on the host
2024-03-14 13:37:57 +01:00
Michael Vogt
b29aa5e651 Revert "osbuild: ensure loop.Loop() has the required device node"
This reverts commit 158acaac78.

With https://github.com/osbuild/bootc-image-builder/pull/238 the
original reason to call mknod goes away so we can just revert
it. osbuild now requires not only the loop device but also uses
`losetup --partscan` quite a lot now so the mknod approach becomes
impractical and the consumers of osbuild in a container should
just setup devtmpfs.
2024-03-13 22:16:51 +02:00
Michael Vogt
185d88e282 test: fix ruff lint error 2024-03-13 17:27:39 +01:00
Michael Vogt
dd575465db monitor: make origin a setter 2024-03-12 16:44:12 +01:00
Michael Vogt
27ac6dd544 osbuild: use sort_keys=True when calculating the Context.id
Since we support python3.6 we cannot assume that dicts are ordered
in any way. To ensure the `id` is still always valid we pass
sort_keys=True to json.dump().

Thanks to Simon!
2024-03-12 16:44:12 +01:00
Michael Vogt
87015318d3 osbuild: tweak "origin=" values, thanks to Simon! 2024-03-12 16:44:12 +01:00
Michael Vogt
861f48a7e1 test,monitor: fix pep8/pylint issues 2024-03-12 16:44:12 +01:00
Michael Vogt
83e66839bc monitor: log start/stop of stages and pipelines too
Generate log messages with origin "org.osbuild.main" when
pipelines/stages start and finish. This way a higher level
frontend can display high level progress coming from this
origin and filter out e.g. stages based log messages (that
are usually quite technical as they are just stdout/stderr
from the stages).
2024-03-12 16:44:12 +01:00
Michael Vogt
3fbd0b2a73 monitor: tweak/simplify Progress
Tweak the Progress class to be simpler. Given that progress does
not need to support arbitrary depth but only has a single level
the class now just exposes "sub_progress" to the caller.

When the main progress is advanced the sub_progress is now fully
deleted instead of just reset. The rational is that when the main
progress is done and advances a step it is very likely that a
new sub_progress is required and it's most likely an error if
the same sub_progress will get re-used.

This means that `reset()` can be removed as it's not used anymore
(and YAGNI). We can add it back when we have a use-case.

It also change the code so that "total" starts with 0 instead
of `None` (principle of least surprise). This means that now
`progress.incr()` is called in the JSONSeqMonitor() for
`finish()` and `result()` to indicate that the pipeline/stage
is finished.
2024-03-12 16:44:12 +01:00
Michael Vogt
de9ead53a2 montior: remove "unit" from Progress (YAGNI)
Removing "unit" from progress as it is currently unused and we
can always add it back when we have a real use-case.
2024-03-12 16:44:12 +01:00
Michael Vogt
1fa0472a8c monitor: tweak Context() to auto recalculate id, rename methods
This commit tweaks Context a bit so that any write will automatically
reset the `_id`. This ensures that we do not forget to reset `_id`
when the code changes.

It also tweaks the naming a bit, before there was a "setter" for
origin and functions to set "pipeline" and "stage". They are all
functions now with a "set_" prefix for symetry mostly.
2024-03-12 16:44:12 +01:00
Michael Vogt
ac16590838 monitor: refactor class LogLine to log_entry()
The class LogLine() is purely used as a dataclass with no state
and the only function on it is `as_dict()`. This got refactored
into a new function `log_entry()` because there is no need for
this to be a class. The function that takes the same inputs.
2024-03-12 16:44:12 +01:00