Commit graph

829 commits

Author SHA1 Message Date
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
David Rheinsberg
9dfa0e8a61 pipeline: only copy output if there is any
Make sure to verify that the pipeline actually produced any output
before attempting to copy it out. This fixes osbuild running with
`--output-directory` but without assembler.
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
Major Hayden
5620d5080a CI: Remove old jenkins.osbuild.org configuation
Signed-off-by: Major Hayden <major@redhat.com>
2020-05-18 09:30:39 -05:00
Major Hayden
05802951eb CI: Add image testing on Fedora 32
Signed-off-by: Major Hayden <major@redhat.com>
2020-05-18 09:30:39 -05:00
Major Hayden
96d3b7aa9d Bring jenkinsfile in line with osbuild-composer
Add the artifact preservation bits from the osbuild-composer jenkinsfile
and use the shared `run_tests()` function to avoid repeating ourselves.

Signed-off-by: Major Hayden <major@redhat.com>
2020-05-15 17:50:45 +02:00
Major Hayden
9f060bdc83 Enable testing on RHEL 8.2
Signed-off-by: Major Hayden <major@redhat.com>
2020-05-15 17:50:45 +02:00
David Rheinsberg
5d1519758f news: reformat according to markdown
The NEWS file currently uses non-markdown indentation, but uses the
markdown file-format. Since both GitHub-Repository-Viewer and the
Release Pages can display proper markdown, lets just re-indent the file
according to the markdown specs.

While at it, also switch out the list-indicator in front of the
timestamp to a proper hyphen, to avoid it being rendered as list.
2020-05-15 09:34:44 +02:00
Major Hayden
7e8ff16d7c CI: Use Jenkins' merged repo for testing
When Jenkins clones a repository for testing, it does the base clone
first and then merges the code from the PR afterwards. This ensures that
the code merges properly and is tested properly, but it also makes a SHA
that only exists inside Jenkins. 😢

Tell ansible-osbuild to use the repository that Jenkins made so that the
SHA is valid.

Signed-off-by: Major Hayden <major@redhat.com>
2020-05-14 09:01:45 -05:00
Major Hayden
6b9cd099f5
Quick fix: switch jenkins > schutzbot in CI
The `jenkins/` directory has been removed in `osbuild-composer`.
2020-05-13 16:36:32 -05:00
Major Hayden
b613afb168 CI: Build RPMs in a mock chroot
Tell ansible-osbuild to build osbuild/osbuild-composer RPMs in a mock
chroot and install them from there instead of building them with
Ansible.

This brings us closer to how koji and brew build RPMs.

Signed-off-by: Major Hayden <major@redhat.com>
2020-05-13 16:19:32 -05:00
David Rheinsberg
134376d8da ci: move test_boot to github-actions
Move the `test_boot` test from Travis over to the Github-Actions based
CI. This is the last test on Travis, and the Travis CI can now be
disabled, if we so wish.

This test leaves a valid `travis.yml` file around, since Travis will
still be enabled on the repository. We should first disable Travis and
then drop this file, if we want to get rid of it.
2020-05-13 22:00:27 +02:00
David Rheinsberg
cd95a8a167 ci: use osbuild/containers images
Use the images provided by `osbuild/containers` tagged as GHCI (GitHub
CI). These images are fully under our control, cached on the GitHub
infrastructure, and prepared to run `systemd-nspawn` and friends in a
docker container.

The GHCI infrastructure is versioned. New updates to the CI
infrastructure are not automatically picked up. Instead, the `v1` tag
has to be explicitly redirected to new image builds to deploy them. If
a new deployment causes CI failures, we can simply redirect the `v1` tag
back to the previous image builds and get the previous behavior back.

The `osbuild/containers` repository contains the required
infrastructure for this logic. If new dependencies are required in the
CI environment, the respective Dockerfiles must be updated. As a
temporary workaround (e.g., as part of a PR that introduces this), you
can simply add `dnf install -y <package>` to the required entries in
`.github/workflows/*`.
2020-05-13 22:00:27 +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
d4f40362ec buildroot: drop kwargs from buildroot.run()
Drop the `kwargs` forwarding from buildroot.run() to subprocess.run().
We do not use it other than for `stdin=subprocess.DEVNULL`. Set that
option directly instead.

Doing the kwargs forwarding mixes the argument namespaces and is very
hard to read. It is not clear from the call-site which argument goes to
buildroot.run() and which to subprocess.run().

Lastly, it requires us to manually fetch `check` just to make pylint
happy. Lets just drop this dance and make the API explicit.
2020-05-13 14:17:30 +02:00
Christian Kellner
016d520dda meta: use draft 4 of jsonschema to validate
We currently don't seem to use anything that requires us to use
the draft 7 of the specification. The minimum version that we
need is draft 4, which is also supported by the python-jsonschema
version in RHEL 8.2 (which is 2.6.0).
2020-05-12 22:00:38 +02:00
Christian Kellner
20a4ba45c6 schema/osbuild1.json: convert to draft4 standard
The 'required' array with an empty is the only thing that requires
this to be draft6 (or higher) [1]. Remove that and downgrade the
schema to draft4 [2].
[1] https://json-schema.org/draft-06/json-schema-release-notes.html
[2] https://json-schema.org/specification-links.html#draft-4
2020-05-12 22:00:38 +02:00
David Rheinsberg
bc437520cd tmpfs: drop unused module
The osbuild/tmpfs.py module is unused. Drop it.
2020-05-12 11:14:16 +02:00
Major Hayden
6e2865fc63 Test with internal Jenkins in parallel
Attempt osbuild testing on the internal Jenkins deployment with
nodes that are destroyed after each use. The internal Jenkins looks for
a Jenkinsfile inside the `schutzbot` directory.

Let's not remove the `jenkins` directory (used by jenkins.osbuild.org)
yet until we know the internal Jenkins is stable and performs well.

Signed-off-by: Major Hayden <major@redhat.com>
2020-05-12 08:09:44 +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
David Rheinsberg
19c74c3e8d cli: drop --build-env argument
Drop the --build-env command-line argument. It is not used by anything.
Furthermore, our manifests now allow embedding build-environments, so
there is little reason to continue supporting this.
2020-05-07 19:52:33 +02:00
Christian Kellner
f2a3423caa 14
This completes the development of osbuild version 14.
2020-05-06 20:18:15 +02:00
Christian Kellner
f4470ace84 NEWS.md: prepare for osbuild release 14
Major changes are the schema validation, the `--inspect` command
line option and the way the osbuild module is being found inside
the container.
2020-05-06 20:18:15 +02:00
Christian Kellner
4b7c68fcdf spec: simplify module inclusion code
Now that as a result of commit 4d2f15f all symlinks have been
dropped from the individual module paths, the search for module
contents can be simplified again.
2020-05-06 20:18:15 +02:00
Christian Kellner
9fce523f76 main_cli: pass proper libdir to meta.Index
In case `--libdir` is not specified on the command line, and thus
`args.libdir` is `None`, pass the standard `/usr/lib/osbuild` path
to the meta.Index constructor. Otherwise no schema information can
be found.
2020-05-06 20:18:15 +02:00
Major Hayden
5516102fdb 🚽 Use Jenkins pipeline for better flow
By using a small Jenkins pipeline in the repository, we can define
almost all of our testing parameters in the repo itself and not inside
Jenkins. 🥳

This also allows us to use the GitHub Branch Source plugin and
auto-discover new repositories without `ok to test` bombs in
pull requests.

Signed-off-by: Major Hayden <major@redhat.com>
2020-05-06 12:06:12 -05:00
Christian Kellner
f3a4b2dfbf test/osbuild: add checks for Schema class
Basic checks that `Schema`, initialization with no, an invalid
and a valid schema. Check the latter can be used to do validation.
2020-05-06 15:42:23 +02:00
Christian Kellner
1fa3b88ab1 meta: truth value of Schema includes schema check
The truthiness of the `Schema` object itself now contains the
schema validation as well, i.e. schema is only valid if schema
information is present and said information passes validation.
2020-05-06 15:42:23 +02:00
Christian Kellner
26ca79ec25 test/osbuild: also validate the schema of stages
Up until now it was verified that loading the `STAGE_OPTS` data
works, i.e. that it contains valid JSON, but the schema itself
was not verified. Use the new `Schema.check` method to do that.
2020-05-06 15:42:23 +02:00
Christian Kellner
9d08f4faf2 meta: add Schema.check method to check the schema
The _validator member of `Schema` is used as an indicator whether
the provided schema is valid. The `check` method will, in case
that _validator is not set attempt to validate the schema data,
if present and set the _validator member if schema data is set and
validation has passed. On failure, i.e. missing schema information
or invalid schema data, the ValidationResult will contain the
respective error.
2020-05-06 15:42:23 +02:00
Christian Kellner
cb0db496dc ci: validate the samples
Use the new `--inspect` feature of osbuild to validate all our
samples.
2020-05-06 15:42:23 +02:00
Christian Kellner
e3fa1e8e73 osbuild: add --inspect command line option
This option will print the manifest in JSON, including all the ids,
to stdout. It will not build the pipeline, but the input manifest
will be validated and if that fails the validation result will be
return in JSON.
2020-05-06 15:42:23 +02:00
Christian Kellner
4057bfe896 pipeline: description() can optionally include ids
Add a option to all description methods to include the respective
ids in the description. Defaults to False to preserve the original
output which is used in the tests.
2020-05-06 15:42:23 +02:00
Christian Kellner
01ce01b1c7 stages & assemblers: don't allow additional props
Change all the schemata to not allow additional properties. This
should help with misspelled properties as well as missing schema
information in the stage itself.

Done via a small python3 script:

   --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< ---

import os
import sys

def list_stages(base):
    return [(base, f) for f in os.listdir(base) if f.startswith("org.osbuild")]

stages = list_stages("stages")
stages += list_stages("assemblers")

def find_line(lines, start):
    for i, l in enumerate(lines):
        if l.startswith(start):
            return i
    return None

NOADD = '"additionalProperties": false'

for stage in stages:
    with open(f"{stage[0]}/{stage[1]}", "r") as f:
        print(f"{stage[0]}/{stage[1]}", file=sys.stderr)
        data = f.readlines()
        i = find_line(data, 'STAGE_OPTS = """')
        if i:
            data.insert(i+1, NOADD + ",\n")
        else:
            i = find_line(data, 'STAGE_OPTS = ""')
            if i:
                data[i] = f'STAGE_OPTS = """\n'
                data.insert(i+1, NOADD + "\n")
                data.insert(i+2, '"""\n')

    with open(f"{stage[0]}/{stage[1]}", "w") as f:
        f.writelines(data)
2020-05-06 15:42:23 +02:00
Christian Kellner
554d8dc868 test/stages/groups: fix gid to be a number
According to the schema the "gid" option is a number not a string.
2020-05-06 15:42:23 +02:00
Christian Kellner
3f0ced73ed test/osbuild: use StageInfo to verify stage opts
Instead of manually loading the schema information of the stages
and assemblers, use the new osbuild.meta.StageInfo class.
2020-05-06 15:42:23 +02:00
Christian Kellner
e036f86119 test: fix freq, passno types everywhere
Both 'freq' and 'passno' org.osbuild.fstab2 stage options need to
be of type int, not string.
2020-05-06 15:42:23 +02:00
Christian Kellner
f81ae9c4c3 test/assemblers: omit None compression option
In the "test_tar" test the compression can be None, which in turn
will be serialized as "compression: null" in the options dict.
However, this is not a valid option according to the schema. The
schema could be adapted to allow for this but it is probably
better to just omit empty or null values.
2020-05-06 15:42:23 +02:00
Christian Kellner
b7367c037e assemblers/qemu: add 'raw.xz' to format schema
It is a valid option and even used in the tests, but was missing
in the schema.
2020-05-06 15:42:23 +02:00
Christian Kellner
702e7c3423 stages/chrony: fix schema to require 'timeservers'
It is required in the code, that should be reflected in the schema
as well.
2020-05-06 15:42:23 +02:00
Christian Kellner
2383e08523 stages/zipl: add schema for timeout option
Add the missing schema information for the timeout option.
2020-05-06 15:42:23 +02:00
Christian Kellner
91a4810808 stages/ostree: add schema for osname, commit
Add missing schema information for the `osname` and `commit`
options.
2020-05-06 15:42:23 +02:00