Commit graph

181 commits

Author SHA1 Message Date
Christian Kellner
7ac8f41798 stages/systemd: ability to mask services
Add the ability to mask services, which is done e.g. when building
installers. See systemctl(1) for more information about masked
services.
Modify the existing stage test to include a test for it.
2020-06-24 10:05:11 +02:00
Christian Kellner
54dffeaaa0 test/stage/selinux: add check for new label option
Manually set a label for '/usr/bin/cp' to 'isntall_exec_t' and
verify it has been set correctly.
2020-06-15 20:36:48 +02:00
Christian Kellner
15986d9297 test: add selinux stage test
Add a simple check for the selinux check by building the f32-base
image with an added selinux stage. Use the options from a test
json file and verify the labels against a set of labels given in
the aforementioned test file.
2020-06-15 20:36:48 +02:00
Christian Kellner
85cd334945 test/stages: narrow test detection via diff.json
Only generate stage tests for sub-directories in stages_tests
that contain a diff.json. This should allow us to have specialized
stage tests that don't use the current {a, b}.json & diff.json
pattern.
2020-06-15 20:36:48 +02:00
Christian Kellner
00f06dff16 test/assemblers/ostree: check rpm-ostree.inputhash
Verify the rpm-ostree.input hash is set correctly for the repository
itself as well. This will in turn also verify that the repository
is existent and can be accessed.
2020-06-15 13:44:01 +02:00
Christian Kellner
da80259ea0 test: add a test for the ostree.commit assembler
Create a ostree commit and check that it successfully was created
by inspecting the resulting `compose.json`.
2020-06-15 13:44:01 +02:00
Christian Kellner
5a54dfcf9f manifests: install rpm-ostree in the build root
Install rpm-ostree in the (mpp-)f32-build.json build manifest, so
ostree commits can be created using the same build root. Update
all affected manifests.
2020-06-15 13:44:01 +02:00
Christian Kellner
cf03ca0715 test/assemblers: remove the need to use nbd
Using the network block device (nbd) kernel module to test all
the non-raw image formats often caused tests to fail due to nbd
not being stable itself (see below).
Instead convert non-raw images to the raw format via qemu-img
convert and mount those with loop-back devices. All the testing
code itself stays the same.

Example nbd error messages:
  kernel: block nbd15: NBD_DISCONNECT
  kernel: block nbd15: Disconnected due to user request.
  kernel: print_req_error: 89 callbacks suppressed
  kernel: blk_update_request: I/O error, dev nbd15, sector 0 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 0
  kernel: buffer_io_error: 134 callbacks suppressed
  kernel: Buffer I/O error on dev nbd15, logical block 0, async page read
  kernel: blk_update_request: I/O error, dev nbd15, sector 1 op 0x0:(READ) flags 0x0 phys_seg 7 prio class 0
2020-06-15 11:51:31 +02:00
Christian Kellner
21e0475031 test/assemblers: split partition reading and test
Split up the partition table test into reading the partition table
and then asserting it has the correct entries. Prepares the usage
of the partition information later.
2020-06-15 11:51:31 +02:00
Christian Kellner
7a2ad6f0f8 osbuild: replace capture_output in subprocess.run
The `capture_output` argument for subprocess.run was added in 3.7,
but want to support 3.6 as well. Change all the usages of it with
`stdout=subprocess.PIPE` that will have the same effect, at least
for stdout.
2020-06-09 13:42:35 +02:00
Tom Gundersen
10a9f16852 test: move all test manifests to get fedora packages from kernel mirrors
This replaces the round-robin mirror at fedoraproject.org, as that was
proving to be quite unreliable.

This is a short-term fix before add metalink support.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-06-07 22:08:34 +02:00
David Rheinsberg
06af246f38 test/assemblers: use F32 manifest
Switch to the fedora-boot.json manifest, so we automatically use the
latest fedora manifest for assembler-tests.
2020-06-05 09:27:40 +02:00
David Rheinsberg
0010514c4a test: move assembler-tests into ./test/run/
Move the last remaining test into the correct subdir. With this done,
all our tests run in one of the 3 groups:

   * `make test-src`
     Run tests against the source-code, including linters.

   * `make test-mod`
     Run unit-tests on the individual python modules. This needs no
     special permissions (unless noted in each test) or runtime
     environments. It is meant to be fast and easy to run in all
     circumstances.

   * `make test-run`
     Run tests that execute the osbuild pipeline. This requires
     superuser privileges and will likely take a while. Furthermore,
     this might produce large artifacts.
2020-06-05 09:27:40 +02:00
David Rheinsberg
d584a1e225 test: move stage-tests into test/run and test/data
Move the stage-tests over to the new test-infrastructure. This moves
the test invocation into `./test/run/test_stages.py`, so it is invoked
as part of the runtime-tests. Secondly, the test-data is stored in
./test/data/stages/ so the path is relative to
TestBase.locate_test_data().

While at it, this also drops the dynamic class modifications and instead
uses subTest(). This simplifies the code quite a bit and avoids
dynamically creating python code.
2020-06-05 09:27:40 +02:00
David Rheinsberg
e8445da3d9 test: move test_osbuild.py into module tests
Move the `test_osbuild.py` test into the module-test directory. This
test contains just a bunch of basic functionality tests for a selection
of osbuild modules. Hence, it can be run together with the other module
tests.
2020-06-05 09:27:40 +02:00
David Rheinsberg
3cf8b79e80 test: move test_objectstore into module-tests
Move `test_objectstore` into the module-level tests. This allows us to
run it as part of `make test-module.

Make sure to properly guard it as root-only module.
2020-06-05 09:27:40 +02:00
David Rheinsberg
9bb6123963 test: convert test_boot to runtime tests with F32
Move the `test_boot` suite into ./test/run closer to the other runtime
tests, and convert the used manifest over to an MPP based F32 manifest.
2020-06-05 09:27:40 +02:00
David Rheinsberg
6e8562f712 test: make source-tests relative to ./test/data/
This moves the `sources_tests` into ./test/data/sources/ and makes the
entire test use `locate_test_data()` to get relative paths for their
accesses.

This further improves our test cases to support running from
installments rather than local checkouts. We need access to ./test/data
guarded, so we can install packages and still have the tests access the
correct paths.

This also adjusts the HTTP-Server we use in the test to serve data
relative to a path it is handed. I now chose `./test/data`, which will
easily allow us to re-use the same HTTP-Server in the future for other
tests that require it.
2020-06-05 09:27:40 +02:00
David Rheinsberg
4b85f48b12 test: include grub2-pc in f32-build.json
We need the `grub2-pc` RPM to install grub, so make sure we provide it
in our f32-build.json manifest.
2020-06-05 09:27:40 +02:00
David Rheinsberg
240905d4a0 test: make TestBase inherit unittest.TestCase
We want to extend our base-class to support extensions to
unittest.TestCase, so make sure we inherit from it.

Adjust all callers to no longer inherit from TestCase, since this is now
done automatically by TestBase.
2020-06-05 09:27:40 +02:00
David Rheinsberg
06119f7d88 tools: move tree-diff into ./tools
Move the `tree-diff` tool into ./tools, which is our new place for tools
used by the test-suite or during development.

The only hard-coded user is the TestBase, so fix its path to the tool
so the test-suite will continue to find it.
2020-06-05 09:27:40 +02:00
David Rheinsberg
020e78d571 test: import build-pipelines
Extend the `f32-base.json` manifest to use our F32 build-root. Use the
new mpp-import-pipeline preprocessor to include `f32-build.json` as
build-root.
2020-06-05 09:27:40 +02:00
David Rheinsberg
a3d1e3ff50 test: import no-op test into the runtime-tests
Add a new trivial runtime-test which simply runs a no-op pipeline. This
is a fast, trivial test that simply verifies osbuild is properly setup
and accessible.

Remove the explicit no-op test from the CI, now that the test-suite has
it as well.
2020-06-05 09:27:40 +02:00
Christian Kellner
af7ef2ec3e test/stages: replace fau.de mirror with kernel.org
Recently downloading rpms from the fau.de mirror is failing quite
often with timeouts. Replace its only usage in the rpm stages
test with the kernel.org mirror.
2020-06-04 13:50:32 +02:00
Christian Kellner
9930f6ebfb test/osbuild: check the schema of sources
Add 'Source' to the list of module classes that will undergo basic
schema checks, i.e. verify that their embedded schema data is valid
JSON schema.
2020-06-02 09:50:14 +02:00
David Rheinsberg
4a6ee7081b test/pylint: select files via git-ls-tree
We currently run pylint on all files we find in the checkout. This is
particularly annoying when we have osbuild-stores in the checkout, which
then contain lots of python files in their stored trees.

Change the pylint test to use `git ls-tree` to find all files in the
index and then only run pylint against the subset that we are interested
in.
2020-05-29 11:07:44 +02:00
Christian Kellner
131d0264a8 test/osbuild: use new list_modules_for_class
Convert our custom code to list modules to the new ModuleInfo
method list_modules_for_class that does the same thing. This
is then indeed also testing that new function.
2020-05-29 08:37:47 +02:00
Christian Kellner
1718740c6c test: remove test_stageinfo.py
This was superseded by test_osbuild's test_moduleinfo. It also
seems to be non-functional do to assuming `properties` in all
the STAGE_OPTS. Removing this.
2020-05-29 08:37:47 +02:00
Christian Kellner
80858a492b meta: rename StageInfo → ModuleInfo
The are converging on a nomenclature where the sum of Stages,
Assemblers, Sources (and future entities like those) together
are called 'Modules'.
Thus rename StageInfo to ModuleInfo and the corresponding
variables and methods.
2020-05-29 08:37:47 +02:00
David Rheinsberg
39e989245d test: enable pylint warnings
Make pylint complain about warnings, not just errors. There are lots of
useful warnings and we generally do adhere to the coding-styles.
2020-05-28 11:06:05 +02:00
David Rheinsberg
b659aa72ed test: fix wrong indentation
Fix a wrong intendation in TestBase. We used 8spaces instead of 4 in a
subprocess.run() call.
2020-05-28 11:06:05 +02:00
David Rheinsberg
086ad75ba4 test: mark static methods as @staticmethod
Turn some of our methods into static methods and mark them as such,
making pylint even happier.
2020-05-28 11:06:05 +02:00
David Rheinsberg
5d3679f85a test: avoid variable shadowing
Avoid shadowing `unittest` from the global imports. Use a different
identifier and make pylint happier.
2020-05-28 11:06:05 +02:00
David Rheinsberg
46526cf205 osbuild: avoid [] as default value
Using `[]` as default value for arguments makes `pylint` complain. The
reason is that it creates an array statically at the time the function
is parsed, rather than dynamically on invocation of the function. This
means, when you append to this array, you change the global instance and
every further invocation of that function works on this modified array.

While our use-cases are safe, this is indeed a common pitfall. Lets
avoid using this and resort to `None` instead.

This silences a lot of warnings from pylint about "dangerous use of []".
2020-05-28 11:06:05 +02:00
David Rheinsberg
451ec33d9e test: turn test-doc into test-comment
We use comments in all other tests, rather than doc-strings. Convert the
os-release test to do the same. If we wanted doc-strings, we can convert
all tests over. This commit just tries to keep the tests in-sync.

Note that doc-strings cause `unittest` to print the doc-strings to
stdout during test-execution, making it overly verbose (especially for
multiline docs). By converting it to comments, this behavior is
suppressed.
2020-05-28 11:06:05 +02:00
David Rheinsberg
fdff00d039 test: drop unused osbuildtest.py
This is no longer used. All tests were converted to the new OSBuild
Executor. Drop the remainings.
2020-05-28 11:06:05 +02:00
Christian Kellner
1fe1840c2b tests: add test for the new copy stage
Add a test for the new org.osbuild.copy. Fetch a tarball from the
osbuild github repository and copy two files over to the tree.
2020-05-28 10:42:18 +02:00
David Rheinsberg
7dcc946fe2 test: add F32 manifests and a manifest-preprocessor
This adds F32 manifests in ./test/data/. To avoid magically deducing the
package list out of the void, this adds a ManifestPreProcessor (MPP)
called `./tools/mpp-depsolve.py`. What this does is it takes a manifest
on stdin, modifies it, and produces a manifest on stdout.

The `mpp-depsolve.py` preprocessor takes a manifest and modifies all the
`org.osbuild.rpm` stages. It parses a new option to that stage called
`mpp-depsolve`, which contains a package-list, a repo-list, and dnf
metadata. It then drops this `mpp-depsolve` option (since it would be an
invalid manifest otherwise), depsolves the packages, inserts a proper
"packages" option as well as appends the correct paths to the sources
entry.

With this in place, this adds `mpp-f32-base.json` and
`mpp-f32-build.json` in ./test/data/manifests/. These will then be used
as base F32 manifests for our test-suite.

Lastly, this adds `./test/data/README.md` as a place to document the
files we place in `./test/data/`, since most of the files do not allow
for comments.
2020-05-20 18:54:38 +02:00
David Rheinsberg
c84f5280c1 test: convert to new osbuild executor
Convert the pipeline tests to the new osbuild executor. This will remove
the last users of the "output_id" and "tree_id" identifiers from
osbuild.
2020-05-20 14:44:43 +02:00
David Rheinsberg
845148993c test: add tree-diff accessor
The `tree-diff` tool currently requires access to our local checkout,
since we do not install the tool. Provide accessors in `TestBase` so we
do not hard-code the path everywhere.
2020-05-20 14:44:43 +02:00
David Rheinsberg
20beabf431 test: add new osbuild executor
Add a new OSBuild class to `./test/test.py`. This class is an extension
of `./test/osbuildtest.py`, but no longer requires the `output_id` and
`tree_id` identifiers of osbuild.

Furthermore, this new executor uses context-managers to make sure any
temporary object is only accessed for a contained time-frame.
2020-05-20 14:44:43 +02:00
Christian Kellner
1896047bae sources: pass the library dir to the sources
The idea is that source can themselves spawn other modules, esp.
new secrets modules. For this they need to know the library dir,
aka 'libdir' throughout the osbuild source. Therefore change the
SourceServer to directly get the library directory instead of
just the sub-directory to the sources. Then pass the library
directory to via the JSON API to the source.
Adjust all usage of the SourceServer, including the tests.
2020-05-20 14:43:33 +02:00
David Rheinsberg
15e4d0d3a1 test/assemblers: do not fail on modprobe failure
This changes the `modprobe nbd` invocation to be non-fatal on failure,
since it might very well fail on reasonable setups. `modprobe` fails if
it cannot find a module in `/lib/modules`, even if it could reasonably
well figure out whether a module is already loaded. The reason is that
it needs the metadata from the module file to find the required modules
parameters.

If you have `nbd` already loaded but not mapped in `/lib/modules`, the
current call will cause test failures, even though the test would run
smoothly.

Fix this by never requiring `modprobe nbd` to succeed, but instead rely
on the tests failing if accessing `nbd` fails.
2020-05-13 22:00:27 +02:00
David Rheinsberg
ad50259ace test: drop unused 'testing-rpms'
This drops the directory './test/testing-rpms'. The directory was
introduced in:

    commit d975effc42
    Author: Martin Sehnoutka <sehnoutka.martin@gmail.com>
    Date:   Thu Jul 25 11:12:27 2019 +0200

        improve vagrant test and its documentation

It used to be the automatic target directory to store rpms created via
`make copy-rpms-to-test`. This target no longer exists. It was dropped
in:

    commit 59b7b545b2
    Author: Lars Karlitski <lars@karlitski.net>
    Date:   Fri Mar 6 11:07:52 2020 +0100

        Makefile: remove vagrant rules
2020-05-13 22:00:27 +02:00
David Rheinsberg
082b840d94 test: integrate pylint into the test infrastructure
Introduce a third test-group called `src` alongside `mod` and `run.
This will contain tests that run against the source code of osbuild.

This initial commit introduces `test/src/test_pylint.py` which will run
the python linter against all our sources.
2020-05-13 14:26:05 +02:00
David Rheinsberg
b830bb7480 test: convert os-release-tests to test-data
Use the new `locate_test_data()` helper to get access to test-data.
Guard the test with `have_test_data()` to skip it in case test-data
access is not available.
2020-05-13 14:26:05 +02:00
David Rheinsberg
5c0e6f5964 test: convert to shared helpers
Use the `can_modify_immutable()` helper from the TestBase parent class
so we do not duplicate the code in multiple places. Similarly, make use
of the `have_rpm_ostree()` helper.
2020-05-13 14:26:05 +02:00
David Rheinsberg
851d949027 test: add base class for tests
Add a new base class called `TestBase` to our test-suite. This allows
sharing common code between our tests without requiring them to import
each other. Furthermore, it paves the way towards executing all our
tests as part of the `unittest` framework, including pylint and others.

For now, this adds the following features to `TestBase`:

  * Common test-guards that are shared between our tests, like
    `can_modify_immutable()` or `have_rpm_ostree()`.

  * Accessors to the test-checkout. This is `have_test_checkout()` to
    check whether the running test has a repository checkout, and
    `locate_test_checkout()` to get a path to the repository checkout.
    This will allow us to put pylint and friends into the unittest
    framework, guard them properly, and still allow running the tests
    from a global install which might not have access to a checkout.

    For now, we always assume we run from a checkout.

  * Accessors to test-data. If we start installing tests as a module
    into the system, we cannot bundle test-data together with code.
    Therefore, two accessors `have_test_data()` and `locate_test_data()`
    are implemented to guard access to test data. If a checkout is
    available, it will be used to locate test-data.

    In the future, we want to be able to pass a separate path to the
    test-data, thus allowing us to install tests into a system.
2020-05-13 14:26:05 +02:00
David Rheinsberg
8a195d7502 util/ctx: extract suppress_oserror()
Extract the `suppress_oserror()` function from the ObjectManager and
make it available as utility for other code as well.

This also adds a bunch of tests that verify it works as expected.
2020-05-11 18:05:12 +02:00
David Rheinsberg
6e02488a9f test/boot: use -chardev file over -chardev stdio
This changes `-chardev stdio` to `-chardev file` and uses a temporary
file to communicate with QEMU.

This fixes an issue where `-chardev stdio` hangs if `STDIN` is not a
TTY. I could not figure out how to make it work without a TTY, and it
does not print any meaningful diagnostics. Problem is, in CI and other
automated runners, we do not necessarily have a TTY as STDIN.

This just switches to a temporary file, which seems to work under all
circumstances.
2020-05-07 20:27:26 +02:00