Commit graph

711 commits

Author SHA1 Message Date
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
Christian Kellner
685650cda2 stages/fix-bls: add missing schema for prefix
Add the missing schema information for the `prefix` option. While
there also add some description of it in the STAGE_INFO field.
2020-05-06 15:42:23 +02:00
Christian Kellner
2757125b60 stages/fstab: fix type 'freq', 'passno' defaults
They are integers according to the schema; make the default values
have the same type.
2020-05-06 15:42:23 +02:00
Christian Kellner
0c01a30657 stages/first-boot: fix schema
The correct type for the boolean wait_for_network option is
`boolean` not `bool`.
2020-05-06 15:42:23 +02:00
Christian Kellner
be68830c44 stages/ostree: fix schema for kernel_opts
The `kernel_opts` option is a array of strings not a single string.
2020-05-06 15:42:23 +02:00
Christian Kellner
6d2a3cbdea stages/rpm-ostree: fix stage schema
Remove the "enabled_services" requirement since that is not even
a valid option. Ops.
2020-05-06 15:42:23 +02:00
Christian Kellner
7b3ad0a540 samples: remove erroneous runner entry
Remove a misplaced "runner" item from the manifests.
2020-05-06 15:42:23 +02:00
Christian Kellner
b710c3c55a samples: fix fstab stage in base-qcow2.json
The freq and passno options have to be numbers not strings. Fix it.
2020-05-06 15:42:23 +02:00
Christian Kellner
a52c1dac45 spec: install schemata
Install the schema to %{_datadir}/osbuild/schema and provide a
link from %{pkgdir}/schema to that location so that the osbuild
library can easily access the schemata.
2020-05-06 15:42:23 +02:00
Christian Kellner
35a20922f0 osbuild: validate pipeline options
Validate the options of stages and assembler of the pipeline
before running it. A validation failure will abort the run.
Errors are printed in human readable unless `--json` is passed;
For each error a human readable message together with a path
to the object with the error is given. The syntax of the path
is such it can be used via the `jq` command to select the item.
2020-05-06 15:42:23 +02:00
Christian Kellner
bab736dd9a test/osbuild: add checks for validation
Add checks for the new validation API, specifically check that
errors in the main manifest, the stages and stage options,
assembler and assembler options. Also ensure that there are no
duplicated errors due to pipeline nesting (e.g. build pipelines).
2020-05-06 15:42:23 +02:00
Christian Kellner
e77d95f4b7 osbuild: add meta module for metadata information
This new module contains utilities that help to introspect parts
that constitute the inner parts of osbuild, i.e. its stages
and assembler (which is also considered a type of stage in
this context). It contains the `StageInfo` class that can that
contains meta-information about the individual stage, such as
a short information (`info`), a longer description (`desc`) and
its JSON schema. A new Schema class represents schema data and
has a `validation` method that can be used to validate that json
data conforms to said schema.
A `Index` class can be used to obtain `StageInfo` and `Schema`
for entities identified via `klass` and `name`.
A top level `validate` method is introduced that can validate
manifest data.
Internally it uses the `jsonschema` package so add that as a
requirement and Install this dependency in the CI.
2020-05-06 15:42:23 +02:00
Christian Kellner
651326c610 schemas/osbuild1: specify exact schema version
Using the "$schema" without any specific version has been
deprecated[1] and will lead to warnings like:

  DeprecationWarning: The metaschema specified by
  $schema was not found. Using the latest draft to validate,
  but this will raise an error in the future

Fix this by pointing $schema to "draft-07", which is the latest
version fully supported the jsonschema python package, that is
being used internally.

[1]
  "The possibility to declare $schema without specific version
  (http://json-schema.org/schema#) was deprecated after Draft 4
  and should no longer be used."
  https://json-schema.org/understanding-json-schema/reference/schema.html
2020-05-06 15:42:23 +02:00
Christian Kellner
b1a8c465ce main_cli: Add missing newlines
PEP-8 demands it.
2020-05-06 15:42:23 +02:00
David Rheinsberg
41a4afd3ba Revert "buildroot: explicitly invoke runners via python3"
This reverts commit 33844711cd.

There are systems were our runners have no standard python3 location
available. They will fix the environment before invoking any further
utilities. Therefore, we cannot rely on `python3 foo.py` to work in our
ad-hoc containers.

This simply reverts the behavior back to using the shebang.
2020-05-05 16:57:50 +02:00
David Rheinsberg
4d2f15fb46 modules: drop osbuild symlink
Drop the `osbuild -> ../osbuild` symlink from all module directories.
We now properly initialize the PYTHONPATH to provide the imported
osbuild module from the host environment. Therefore, these links are no
longer needed.

The sources run from the host environment, so they should just pick them
up from the environment the same way osbuild itself does.
2020-05-04 12:32:25 +02:00
David Rheinsberg
3c56a3b7ac buildroot: insert osbuild-library into PYTHONPATH
Prepare the PYTHONPATH of the build-root container to include the path
to the osbuild library. This way, we no longer need any symlinks or
bind-mounts for the individual modules.
2020-05-04 12:32:25 +02:00
David Rheinsberg
33844711cd buildroot: explicitly invoke runners via python3
Use the python-interpreter explicitly to invoke the runners. This works
around inconsistencies between scripts imported from the host, and the
interpreter taken from a build-root.
2020-05-04 12:32:25 +02:00
Ondřej Budai
19328b062c jenkins: remove composer directories before the tests
This commit turns on the `cleanup_composer_directories` option to clean up
the osbuild-composer directories during the time the services are stopped
(when ansible-osbuild is about to deploy the new versions of the
services).

Taken from osbuild/osbuild-composer#575, thanks to @major!
2020-05-04 11:35:44 +02:00