Commit graph

882 commits

Author SHA1 Message Date
Michael Vogt
f0f9d8677a test: update the test cert to expire in 100y
When generating the original test certs no `-days` paramter was
passed which resulted in a too low `notAfter` value.

This commit fixes this and uses 100y also updates the README:
```
$ openssl x509 -enddate -noout -in test/data/certs/cert1.pem
notAfter=Aug  2 10:42:40 2124 GMT
$ openssl x509 -enddate -noout -in test/data/certs/cert2.pem
notAfter=Aug  2 10:42:45 2124 GMT
```
This fixes a test failure in https://github.com/osbuild/osbuild/pull/1819
for the `test_curl_download_many_mixed_certs` test.
2024-08-27 09:39:17 +02:00
Paweł Poławski
db08c472f3 general: Fix linter issues across the codebase 2024-08-26 11:59:46 -07:00
Michael Vogt
77a61da760 osbuild: drop libdir from download() methods
The libdir is passed down for sources but it is never used in
any of our sources. As this is confusing and we want to eventually
support multiple libdirs remove this code.

It looks like the libdir for soruces was added a long time ago in 8423da3
but there is no indication if/how it is/was supposed to get used and
AFACT from going over the git history it was very used.

SourceService:dispatch() never sends "libdir" to the actual sources,
so it is not an even technically an API break.
2024-08-26 19:58:55 +02:00
Achilleas Koutsou
fe1e310f2e test: add read/write tests for util.toml
Add two unit tests for our toml util module.
- Write an object with util.toml, read it with util.toml, and compare
  written and read objects.
- Write an object directly as a string, read it with util.toml,
  comparing with an expected object.

A test that writes with util.toml, reads as string, and verifies the
read string is difficult to do in a general way, because each toml
module we support writes files in a slightly different way.
2024-08-21 19:26:31 +02:00
Achilleas Koutsou
618ec9db2c test/update-crypto-policies: update diff file
With the mounting of /dev (among others) into the chroot for the
update-crypto-policies, the leftover /dev/null is now removed.

This was created by the update-crypto-policies script, running in the
chroot, by multiple output redirects into /dev/null.  Without a /dev fs,
the file was being created in the tree and would remain on the image.
2024-08-21 18:50:05 +02:00
Tomáš Hozza
a0b44c5c72 Test/stages: check dracut stage output for environment warnings
Extend the dracut stage test case with checks for error / warning
messages complaining about unsupported / incorrect runtime environment.

Messages such as:
```
/dev/fd/63: No such file or directory
```
or
```
/proc/ is not mounted. This is not a supported mode of operation.
Please fix your invocation environment to mount /proc/ and /sys/
properly. Proceeding anyway. Your mileage may vary.
```

The stage will be fixed in the next commit.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-15 19:56:20 +02:00
Michael Vogt
88c35ea306 osbuild: make inputs map() function use fd for reply as well
We recently hit the issue that `osbuild` crashed with:
```
Unable to decode response body "Traceback (most recent call last):
  File \"/usr/bin/osbuild\", line 33, in <module>
    sys.exit(load_entry_point('osbuild==124', 'console_scripts', 'osbuild')())
  File \"/usr/lib/python3.9/site-packages/osbuild/main_cli.py\", line 181, in osbuild_cli
    r = manifest.build(
  File \"/usr/lib/python3.9/site-packages/osbuild/pipeline.py\", line 477, in build
    res = pl.run(store, monitor, libdir, debug_break, stage_timeout)
  File \"/usr/lib/python3.9/site-packages/osbuild/pipeline.py\", line 376, in run
    results = self.build_stages(store,
  File \"/usr/lib/python3.9/site-packages/osbuild/pipeline.py\", line 348, in build_stages
    r = stage.run(tree,
  File \"/usr/lib/python3.9/site-packages/osbuild/pipeline.py\", line 213, in run
    data = ipmgr.map(ip, store)
  File \"/usr/lib/python3.9/site-packages/osbuild/inputs.py\", line 94, in map
    reply, _ = client.call_with_fds(\"map\", {}, fds)
  File \"/usr/lib/python3.9/site-packages/osbuild/host.py\", line 373, in call_with_fds
    kind, data = self.protocol.decode_message(ret)
  File \"/usr/lib/python3.9/site-packages/osbuild/host.py\", line 83, in decode_message
    raise ProtocolError(\"message empty\")
osbuild.host.ProtocolError: message empty
cannot run osbuild: exit status 1" into osbuild result: invalid character 'T' looking for beginning of value
...
input/packages (org.osbuild.files): Traceback (most recent call last):
input/packages (org.osbuild.files):   File "/usr/lib/osbuild/inputs/org.osbuild.files", line 226, in <module>
input/packages (org.osbuild.files):     main()
input/packages (org.osbuild.files):   File "/usr/lib/osbuild/inputs/org.osbuild.files", line 222, in main
input/packages (org.osbuild.files):     service.main()
input/packages (org.osbuild.files):   File "/usr/lib/python3.11/site-packages/osbuild/host.py", line 250, in main
input/packages (org.osbuild.files):     self.serve()
input/packages (org.osbuild.files):   File "/usr/lib/python3.11/site-packages/osbuild/host.py", line 284, in serve
input/packages (org.osbuild.files):     self.sock.send(reply, fds=reply_fds)
input/packages (org.osbuild.files):   File "/usr/lib/python3.11/site-packages/osbuild/util/jsoncomm.py", line 407, in send
input/packages (org.osbuild.files):     n = self._socket.sendmsg([serialized], cmsg, 0)
input/packages (org.osbuild.files):         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
input/packages (org.osbuild.files): OSError: [Errno 90] Message too long
```

The underlying issue is that the reply of the `map()` call is too
big for the buffer that `jsoncomm` uses. This problem existed before
for the args of map and was fixed by introducing a temporary file
in https://github.com/osbuild/osbuild/pull/1331 (and similarly
before in https://github.com/osbuild/osbuild/pull/824).

This commit writes the return values also into a file. This should
fix the crash above and make the function more symetrical as well.

Alternative/complementary version of
https://github.com/osbuild/osbuild/pull/1833

Closes: HMS-4537
2024-08-13 13:13:24 +02:00
Michael Vogt
29f926f305 jsoncom: gracefully report EMSGSIZE errors
When `jsoncomm` fails because the message is too big it currently
does not indicate just how big the message was. This commit adds
this information so that it's easier for us to determine what to
do about it.

We could also include a pointer to `/proc/sys/net/core/wmem_defaults`
but it seems we want to not require fiddling with that so let's
not do it for now.

See also https://github.com/osbuild/osbuild/pull/1838
2024-08-13 09:38:59 +02:00
Tomáš Hozza
f9ddab52f5 Update testing c9s BaseOS repodata snapshot
Use the latest c9s BaseOS repodata snapshot, specifically so that it
contains multiple versions of the same packages. This will allow to test
the `osbuild-depsolve-dnf` 'search' command. The previous metadata
contained only single version of each package.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-08 09:58:41 +02:00
Tomáš Hozza
ffd261bfff test_dnf4_mark(): disable all plugins when inspecting markings
When subscription-manager DNF plugins are enabled (e.g. on RHEL), they
produce messages to the stdout on any DNF command execution. E.g.
"Updating Subscription Management repositories.".

Disable all plugins when inspecting package markings so prevent them
from modifying the output.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-08 09:51:37 +02:00
Tomáš Hozza
12f81e053b Test/dnf4.mark: adjust the test for markings used by DNF5
When I rolled back from using 'dnf4', to check package markings, to
using 'dnf', I didn't verify the test case on Fedora Rawhide with DNF5.
It turns out that the strings reported by DNF5 differ and make the test
case fail. This time I tested the change on Fedora Rawhide with DNF5 and
it works.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-01 10:58:58 +02:00
Michael Vogt
7b16313ce2 main,monitor: fix total steps in progress reporting
The existing code to record progress was a bit too naive. Instead
of just counting the number os pipelines in a manifest to get the
total steps we need to look at the resolved pipelines.

with this fix `bib` will report the correct number of steps left
when doing e.g. a qcow2 image build. Right now the number of
steps is incorrect because the osbuild manifest contains pipelines
for qcow2,vdmk,raw,ami and all are currently considered steps
that need to be completed. With this commit this is fixed.
2024-07-31 23:00:33 +02:00
Michael Vogt
e535877798 test: add new https_serve_directory() and test certs
This commit adds a new `https_serve_directory()` test helper
and some custom self-signed and worthless certs that are used
during testing. They are not dynamically generated to avoid the
extra compuation time during tests (but they could be).

Generated via:
```
$ openssl req -new -newkey rsa:2048  -nodes -x509  \
   -subj "/C=DE/ST=Berlin/L=Berlin/O=Org/CN=localhost"   \
   -keyout "key1.pem" -out "cert1.pem"
```

This will allow us to test `https` download URLs as well in e.g.
the curl source.
2024-07-29 16:51:48 +02:00
Tomáš Hozza
52200c581d Test/dnf4.mark: make failures to parse dnf output easier to debug
The test case still fails on RHEL-10.0 Beta, even when not using dnf5,
with:

```
            for line in r.stdout.splitlines():
>               package, mark = line.strip().split(",")
E               ValueError: not enough values to unpack (expected 2, got 1)
```

Make debugging of failures like this easier by printing the line when
the issue happens.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-07-29 15:01:13 +02:00
Tomáš Hozza
a8f3a1e834 Test/dnf4.mark: make the test compatible with all dnf versions
Let's revert to using plain 'dnf', add an explicit newline in the query
format and skip empty lines when processing the output. This makes the
test case compatible with all DNF versions, even with dnf5 once this
issue gets fixed.

The previous approach didn't work on c9s / el9, because there is no
'/usr/bin/dnf4 -> dnf-3' symlink.

Also see:
https://github.com/osbuild/osbuild/actions/runs/10136827918/job/28026181824

Co-authored-by: Michael Vogt <michael.vogt@gmail.com>
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-07-29 15:01:13 +02:00
Tomáš Hozza
4edbe227d4 Test: fix dnf4.mark stage test with DNF5
DNF5 contains a breaking change in the repoquery --qf output,
specifically it does not include the trailing newline. This breaks the
test case e.g. on the latest Fedora Rawhide [1].

As a fix, explicitly use 'dnf4' for now, until the inconsistency is
fixed in the upstream [2].

[1] https://artifacts.dev.testing-farm.io/3a3a2898-0a6a-42eb-8792-660f03c35c3c/
[2] https://github.com/rpm-software-management/dnf5/issues/709

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-07-25 12:23:53 +02:00
Gianluca Zuccarelli
92bb161501 stages/oscap.autotailor: make profile id required
According to `autotailor(8)` arguments passed in via the cli take
precedence over the JSON tailoring file contents.

Make the `new_profile` a required field for the json tailoring too and
pass it as an option to the `autotailor` command. This approach has some
trade-offs. It allows us to maintain the explicitness of the manifest
that is consumed by `osbuild`. The downside is that it will override the
profile id that is set by the user in the JSON tailoring file.
2024-07-17 13:14:48 +02:00
Gianluca Zuccarelli
2a28acbc85 stages/oscap.autotailor: rename new_profile
Rename the `new_profile` option to `tailoring_profile_id` for clarity.
This also ensures that the change is backwards compatible by falling
back to the `new_profile` option if that was set instead of the
`tailoring_profile` id option.
2024-07-17 13:14:48 +02:00
Michael Vogt
f7d56b3d7e tests: update l2hash for the fc40 move
Similar to what was explained in 2e6d49fbe this commit updates
the l2hash in test_assemblers to the new values from fc40 images.

Sadly it is hard to derive them from first principles (see the
other commit) and given that this is legacy code it is probably
fine this way.
2024-07-02 09:46:45 +02:00
Tomáš Hozza
d15ce4bb11 Test/assemblers: update manifest to use Fedora 40
Fedora 38 is EOL and unfortunately so are our F38 snapshots. Lets
update the manifest to F40.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-07-02 09:46:45 +02:00
Florian Schüller
41f528eeb2 osbuild/monitor.py: improve naming of progress 2024-06-18 16:00:55 +02:00
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