Commit graph

700 commits

Author SHA1 Message Date
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
Ondřej Budai
c680248d29 jenkins: Use sudo for tests
Jenkins now uses a non-root user for its agents, so we will need to use
sudo for some commands.

Stolen from osbuild/osbuild-composer#581, big thanks to @major!
2020-05-04 10:54:18 +02:00
Christian Kellner
245809f40d 13
This completes the development of osbuild version 13.
2020-04-29 20:39:37 +02:00
David Rheinsberg
975ef7ff54 buildroot: drop unneeded DeviceAllow=
With `--keep-unit` we now run with the privileges and resources of the
caller. We no longer require external services to extend our privileges.
This also means we no longer have to configure our unit sandbox
manually, but simply rely on kernel sandboxing to do the right thing.
2020-04-29 20:31:32 +02:00
David Rheinsberg
ae1b5029b7 build: fill in preliminary NEWS entry for v13
Create a preliminary NEWS entry for the upcoming v13 release. Lots of
fixes all over the place, but most of them not worth mentioning for the
release. However, we do have some feature improvements as well.
2020-04-29 15:30:42 +02:00
Major Hayden
a1ca198f53 🔧 Run osbuild-composer tests in osbuild CI
Although we are doing a good job of finding osbuild breakage when we
test osbuild-composer, we aren't finding osbuild-composer breakage
when we test osbuild.

Run the image tests from osbuild-composer whenever we do CI for osbuild.

Fixes #362.

Signed-off-by: Major Hayden <major@redhat.com>
2020-04-29 07:40:50 -05:00
David Rheinsberg
d7adf2b3a5 osbuild: split main apart a bit
Split off the argument parser as well as the manifest parser into
helper functions. Drop the pylint hints from the main function now that
it is considerably smaller.
2020-04-28 15:39:54 +02:00
David Rheinsberg
421414ef0b osbuild: extract CLI to prepare for additional entrypoints
This extracts the CLI entrypoint into `main_cli.py` and prepares the
codebase for the introduction of additional entrypoints. This should
not contain any functional changes.

The idea behind this is to add `main_api.py` (and maybe more in the
future), which will be similar to `main_cli.py` but contain the
`osbuild-api` entrypoint. This will make all entrypoints nicely symetric
and the only difference will be `setup.py` selecting the right
entrypoint for each executable, as well as `__main__.py` selecting the
entrypoint for the module itself (which we will keep to the CLI for
compatibility).
2020-04-28 15:39:54 +02:00
David Rheinsberg
20cf5dba6a test: '{. -> ./mod}/test_util_osrelease.py'
Move the os-release tests to the module-level tests and align its
coding-style with the others.
2020-04-28 15:39:00 +02:00
David Rheinsberg
4493d057a2 osbuild: move osrelease parser into ./util
Reduce the clutter in our pipeline implementation and move the
os-release parser into ./osbuild/util/.
2020-04-28 15:39:00 +02:00
David Rheinsberg
7176f1e85a test: '{. -> ./mod}/test_util_linux.py'
Move the util-linux tests to the module-level tests and align its
implementation.
2020-04-28 15:39:00 +02:00
David Rheinsberg
ea7561329f test: '{. -> ./mod}/test_util_rmrf.py'
Move the rmrf tests to the module-level tests and align its
implementation with the others.
2020-04-28 15:39:00 +02:00