Commit graph

262 commits

Author SHA1 Message Date
Lars Karlitski
f7949d9993 test: add test for osbuild executable
Add two simple tests to check that the osbuild executable fails with the
right exit codes when passed an invalid manifest or checkpoint.

This reuses test.OSBuild, which is extended to raise CalledProcessError
if needed.
2020-10-27 22:04:09 +01:00
Christian Kellner
452e9ddb9e stages/rpm: include sigpgp, siggpg in metadata
Return the SIGPGP, SIGGPG fields, if available, in the packages
metadata. This is needed for the koji integration.
2020-10-22 22:47:22 +01:00
Christian Kellner
d7d84a8eb1 test/mod: use proper host runner
Instead of hard-coding the use of the "org.osbuild.linux" runner,
use the new `osbuild.pipeline.detect_host_runner` function to
dynamically detect the runner for the host system. That should fix
the tests on RHEL systems, where python3 is by default not present
and even if it is manually installed, is an indirection via
alternatives (i.e. a link to /etc/alternatives), which must be
explicitly configured in the build root container for the host.
2020-10-21 11:13:28 +02:00
Christian Kellner
25662fbfbc test/buildroot: more lenient output test checking
In `test_output`, require that the test string is found in the
output, not equal to the output. Other warnings or log messages
might be printed by the runner.
2020-10-21 11:13:28 +02:00
Christian Kellner
9ef642228f test: adapt 'libdir' argument for BuildRoot's ctor
As of commit 1e3c0ae "unified libdir handling", the libdir argument
for the BuildRoot constructor is not a keyword argument anymore.
Adapt the argument accordingly.
2020-10-21 11:13:28 +02:00
Lars Karlitski
88aed72933 test/run/test_stages: respect OSBUILD_TEST_STORE
This environment variable is already used in test_objecttore.py. It's
useful for quick iteration while testing locally.
2020-10-19 17:37:46 +01:00
Lars Karlitski
78c251d332 test/data/stages/zipl: use mpp to generate manifests
Also, upgrade the test to fedora-32 from https://osbuild.org/rpmrepo.

Changed a.json to not include a zipl stage with empty options. This
breaks the test, because the osbuild run of b.json is relying on a
checkpoint of the result of a.json. If that's not present, the rpm
database (and other generated files) are marked as differing, because
the whole pipeline is generated again. This might have worked before,
because the previous package list happened to be deterministic.
2020-10-19 17:37:46 +01:00
Lars Karlitski
ec07482040 test/data/stages/users: use mpp to generate manifests
Also, upgrade the test to fedora-32 from https://osbuild.org/rpmrepo.
2020-10-19 17:37:46 +01:00
Lars Karlitski
8acadfc23e test/data/stages/systemd: use mpp to generate manifests
Also, upgrade the test to fedora-32 from https://osbuild.org/rpmrepo.
2020-10-19 17:37:46 +01:00
Lars Karlitski
064dd5fee0 test/data/stages/rpm: use mpp to generate manifests
Also, upgrade the test to fedora-32 from https://osbuild.org/rpmrepo.
2020-10-19 17:37:46 +01:00
Lars Karlitski
6f8f623918 test/data/stages/timezone: use mpp to generate manifests
Also, upgrade the test to fedora-32 from https://osbuild.org/rpmrepo.
2020-10-19 17:37:46 +01:00
Lars Karlitski
147a6a29fb test/data/stages/locale: use mpp to generate manifests
Also, upgrade the test to fedora-32 from https://osbuild.org/rpmrepo.
2020-10-19 17:37:46 +01:00
Lars Karlitski
a4da6e0041 test/data/stages/keymap: use mpp to generate manifests
Also, upgrade the test to fedora-32 from https://osbuild.org/rpmrepo.
2020-10-19 17:37:46 +01:00
Lars Karlitski
7aa8500174 test/data/stages/kernel-cmdline: use mpp to generate manifests
Also, upgrade the test to fedora-32 from https://osbuild.org/rpmrepo.

Changed a.json to not include a kernel-cmdline stage with empty options.
This breaks the test, because the osbuild run of b.json is relying on a
checkpoint of the result of a.json. If that's not present, the rpm
database (and other generated files) are marked as differing, because
the whole pipeline is generated again. This might have worked before,
because the previous package list happened to be deterministic.
2020-10-19 17:37:46 +01:00
Lars Karlitski
c2cec04b7c test/data/stages/hostname: use mpp to generate manifests
Also, upgrade the test to fedora-32 from https://osbuild.org/rpmrepo.
2020-10-19 17:37:46 +01:00
Lars Karlitski
ac02b79222 test/data/stages/groups: use mpp to generate manifests
Also, upgrade the test to fedora-32 from https://osbuild.org/rpmrepo.
2020-10-19 17:37:46 +01:00
Lars Karlitski
3554575659 test/data/stages/fstab: use mpp to generate manifests
Also, upgrade the test to fedora-32 from https://osbuild.org/rpmrepo.
2020-10-19 17:37:46 +01:00
Lars Karlitski
8904398b50 test/data/stages/firewall: use mpp to generate manifests
Also, upgrade the test to fedora-32 from https://osbuild.org/rpmrepo.
2020-10-19 17:37:46 +01:00
Lars Karlitski
49d1c09653 test/data/stages/copy: use mpp to generate manifests
Also, upgrade the test to fedora-32 from https://osbuild.org/rpmrepo.
2020-10-19 17:37:46 +01:00
Lars Karlitski
abaa49b8ae test/data/stages/chrony: use mpp to generate manifests
Also, upgrade the test to fedora-32 from https://osbuild.org/rpmrepo.
2020-10-19 17:37:46 +01:00
Lars Karlitski
2066d0fb3b test: switch to rpmrepos' repository snapshots
These are more stable, and closer to where the tests are run (in the
same AWS region).

https://www.osbuild.org/rpmrepo/
2020-10-19 17:37:46 +01:00
Lars Karlitski
d9ef44eb6d test: rename mpp-*.json to *.mpp.json
This simplifies the `test-data` rules in `Makefile` considerably. Also,
it allows adding `*.mpp.json` files in other directories without needing
to copy rules. (make's pattern-based rules only allow a single `%`).

Adjust test/data/README.md accordingly.
2020-10-19 17:37:46 +01:00
Christian Kellner
3318480460 test/stages: re-use downloaded files between runs
Create a cache directory with the scope of the stage test suit and
after each test is run cache the downloaded files for the `files`
source via the new `OSBuild.copy_source_data` method. Initialize
OSBuild with that cache directory, so previously downloaded files
get used between different stage tests.
2020-10-09 15:32:31 +02:00
Christian Kellner
9e5e179128 test: add method to copy source data from cache
Add a new method that will copy the downloaded data for a specified
source to a directory, creating a directory structure so that the
target directory can then be used to initialize the osbuild cache,
i.e. the target directory be used for the `cache_from` parameter in
the `test.OSBuild` constructor.
The main reason why this is done per source, and not for all sources,
is that not all source can be copied via a plain `cp` operation or
easily added to, in case that the `target` directory already contains
data. The `org.osbuild.ostree` source is such an example.
2020-10-09 15:32:31 +02:00
Christian Kellner
71f7bf8930 test/api: assert return code for api.exception
Check that the exit code for `api.exception`, called via the
`api.exception_handler` helper, is the correct one.
2020-10-09 10:47:44 +02:00
Christian Kellner
aaa51e22a6 api: properly serialize the exception's traceback
Use `traceback.print_tb()` to serialize the exceptions' backtrace.
The previously used expression `str(e.__traceback__)` will just
give `<traceback object at 0x…>`, which is not very helpful.
Add a test to check that the method name that raises the exception,
also called `exception`, is in the traceback.
2020-10-09 10:47:44 +02:00
Christian Kellner
7a112c27cb test/api: fix white-space error
No double space between class methods, so say the scriptures.
2020-10-09 10:47:44 +02:00
Christian Kellner
f8de164413 api: properly encode exception type
When using `str(type(exception))` this ends up to be something like
`<class 'ValueError'>` for a `ValueError` exception. Get the vanilla
name of the exception type via `type(exception).__name__`.
Add a test to ensure that we encode this properly.
2020-10-09 10:47:44 +02:00
Christian Kellner
f5d00dd043 api: use more generic error member for exceptions
Rename the `API.exception` member to `API.error`, to make it more
generic, so it can also be used for other sort of errors in the
future. Also add a layer of additional structure with `type` and
`data` members so different types of errors apart. Currently only
`exception` is used.
Adapt the tests in test/mod/test_api.py to check for the new
structure and its content.
2020-10-09 10:47:44 +02:00
Christian Kellner
17fbe41b03 test/api: check api.exception exits the process
The `api.exception` method, which is internally also used by
`api.exception_handler` helper, calls `sys.exit` and this no
statement after a call to either method should be reached.
Add an assertion to make sure of that.
2020-10-09 10:47:44 +02:00
Christian Kellner
cbcb335b3e osbuild: fix spelling mistakes found by codespell
Run codespell on the source ('codespell -f -L msdos -S coverity
-S rpmbuild -S samples') and fix all uncovered mistakes.
2020-10-06 14:41:00 +02:00
Chloe Kaubisch
5dc5ddcf29 api: add exception endpoint
Create a new api endpoint called exception, that communicates
exception backtraces separately back to osbuild, as opposed to
dumping them into the normal log. Additionally, add a corresponding
test to check that a call to api.exception correctly sets
API.exception.
2020-10-02 17:49:45 +02:00
chloenayon
01aae91949 api: remove setup_stdio
API.setup_stdio was replaced in PRs 506 and 507,
remove setup_stdio functions and call sites.
2020-09-09 12:52:50 +02:00
Christian Kellner
fc0c75f40e test/api: race-free api.metadata access
Access metadata.api only after `api` has exited the context and
thus the event loop has stopped and all incoming messages, like
the one setting the metadata, have been processed.
See commit 803433fb62 for a lecture
about the internals and all the details involved.
2020-08-31 15:06:36 +02:00
Christian Kellner
a3934ab947 test/buildroot: check BuildRoot.output
Now that the `org.osbuild.linux` runner does not use `api.setup_stdio`
anymore, the output of the binary run from the BuildRoot must end up
in `BuildRoot.output`. Check for that.
2020-08-31 15:06:36 +02:00
Christian Kellner
10579ee6f5 buildroot: return a new CompletedBuild with output
Create a new CompletedBuild object that wraps and is very similar
to the subprocess.CompletedProcess, i.e. it has a process member
but also has shortcuts for returncode. Additionally, the output
of the process is not only forwarded to the monitor, but also
captured and then handed to CompletedBuild, so its output member
will actually contain the full build output. To be compatible
with the previously returned CompletedProcess, `stderr`, `stdout`
members exist on CompletedBuild that also return `output`.
2020-08-31 15:06:36 +02:00
Christian Kellner
ba94409d23 test/buildroot: check we log bwrap's error output
Check that any errors that bubblewrap spits out on stderr make it
to the log. A common case of bubblewrap failing is a runner failing
to execute.
2020-08-27 08:07:14 +02:00
Christian Kellner
96a5499ed9 buildroot: log bubblewrap's output
In case that bubblewrap fails to, e.g. because it fails to execute
the runner, it will print an error message to stderr. Currently,
this output is not capture and thus not logged. To fix that, the
`BuildRoot.run` method now takes a monitor object and will stream
stdout/stderr to the log via the monitor.
2020-08-27 08:07:14 +02:00
Christian Kellner
fc5e0070c5 test/api: check for 'get-arguments'/api.arguments
Simple check for the new server side method, `get-arguments`, and
client side counterpart, `api.arguments`, that compares that using
the later we get the supplied input (arguments) to API.
2020-08-25 18:51:55 +02:00
David Rheinsberg
803433fb62 api: prevent early output retrieval
Change the API endpoint to prevent retrieving monitor-output from a
running instance. Instead, we require the caller to exit the API context
before querying the monitor-output. This guarantees that the api-thread
was synchronously taken down and scheduled any outstanding events.

This fixes an issue where a side-channel notifies us of a buildroot
exit, but the api-thread has not yet returned from epoll, and thus might
not have dispatched pending I/O events, yet. If we instead wait for the
thread to exit, we have a synchronous shutdown and know that all
*ordered* kernel events must have been handled.

In particular, imagine a build-root program running (like `echo` in the
test_monitor unittest) which writes data to the stdout-pipe and then
immediately exits. The syscall-order guarantees that the data is written
to the pipe before the SIGCHLD is sent (or wait(2) returns). However, we
retrieve the SIGCHLD from our main-thread usually (p.join() in our test,
and BuildRoot() in our main code), while the pipe-reading is done from
an API thread. Therefore, we might end up handling the SIGCHLD first
(just imagine a single-threaded CPU that schedules the main task before
the thread). To avoid this race, we can simply synchronize with the
api-thread. Since we already have this synchronization as part of the
api-thread takedown, it is as simple as stopping the api-thread before
continuing with operations.

Lastly, if a write operation to a pipe was issued, we are guaranteed
that a SIGCHLD synchronization across processes is ordered correctly.
Furthermore, the python event-loop also guarantees that stopping an
event-loop will necessarily dispatch all outstanding events. A read is
guaranteed to be outstanding in our race-scenario, so the read will be
dispatched. The only possible problem is `_output_ready()` only
dispatching a maximum of 4096 bytes. This might need to be fixed
separately. A comment is left in place.
2020-08-13 14:02:27 +02:00
Christian Kellner
818daef6cb test/stages: metadata checks for the rpm stage
Use the new metadata checking capability of the stage tests to
check the metadata set by the rpm stage.
2020-08-13 10:50:34 +02:00
Christian Kellner
cf48fe8afe test/assembler: check metadata for ostree asm
Check the metadata is in the result and that it has the 'compose'
entry, which should match what is in `compose.json`.
2020-08-13 10:50:34 +02:00
Christian Kellner
f9fc99fe8f test/stages: support for metadata checking
If the stage test folder contains a `metadata.json` file, it will
contain a dictionary where the keys are stage ids and the values
are dictionaries containing the metadata to verify. For each of
those the stage will be looked up in the pipeline result of 'b'
and verified that the metadata matches.
2020-08-13 10:50:34 +02:00
Christian Kellner
19f9fb02bf test: make OSBuild.compile return the result
Load the result data as json and return it to the caller.
2020-08-13 10:50:34 +02:00
Christian Kellner
30ad32b174 test/api: checks for metadata passing
Add a simple check to make sure that metadata passing via the api
client and api endpoint is working.
2020-08-13 10:50:34 +02:00
Christian Kellner
e0b7361b26 test/buildroot: check selinuxfs is read-only
This is a crucial pre-condition for the org.osbuild.selinux stage
to work properly, especially that it can set labels that are not
present in the policy on the host. If /sys/fs/selinux is writable,
setfiles will try to verify the labels via /sys/fs/selinux/context
and fail for unknown labels.
2020-08-12 16:52:27 +02:00
Christian Kellner
e2231a8bd2 test/buildroot: simple check for bind mounts
Check that bind-mounting works and read only bind mounts are indeed
read-only and "normal" bind mounts are read-write.
2020-08-12 16:52:27 +02:00
Christian Kellner
bcfc2ca29a test/data: add mount_flags.py helper script
Add a new helper script to check if a mount / file-system was
mounted with specific flags. Currently only "ro", "nosuid",
"nodev" and "noexec" flags are supported. This script is in
test/data since it will be used from other tests and is itself
not a test per se.
2020-08-12 16:52:27 +02:00
Christian Kellner
28cea491bd test: move api buildroot test to test_buildroot.py
Create a new test suite for BuildRoot related test and move the
the combined api and buildroot check there.
2020-08-12 16:52:27 +02:00
Christian Kellner
fdded58cdd test/assembler: check for ostree version metadata
Set the OS version of the commit via the new `os_version` option
and make sure that it is in the compose info as well as in the
commit metadata.
2020-08-12 08:08:17 +02:00