Commit graph

1368 commits

Author SHA1 Message Date
Christian Kellner
a3ea8dc748 inputs/files: use os.link instead of ln binary 2021-06-09 18:37:47 +01:00
Christian Kellner
78ce4c2700 stages: add zip.inst stage
This is the stage that will actually install the Z initial program
loader, i.e. the boot loader for s390x.
2021-06-09 18:37:47 +01:00
Christian Kellner
54a5aec0a6 stages: add org.osbuild.grub2.inst
This stage is the part of the qemu assembler that generates and
installs the grub2 core image on non-uefi or hybrid systems,
like x86 legacy and PPC64LE (Open Firmware).
2021-06-09 18:37:47 +01:00
Christian Kellner
17124473be stages: add copy stage
This sage can be used to copy items, such as files or trees, from one
location to another. The only supported location for reading currently
is currently `input`. Supported locations for writing are `mount` and
`tree`.
2021-06-09 18:37:47 +01:00
Christian Kellner
546949fd00 mounts: add org.osbuild.fat
Mount host service for (v)fat filesystems.
2021-06-09 18:37:47 +01:00
Christian Kellner
ddb7aa4431 mounts: add org.osbuild.xfs
Mount host service for xfs filesystems.
2021-06-09 18:37:47 +01:00
Christian Kellner
367a044453 osbuild: introduce mount host service
Allows stages to access file systems provided by devices.
This makes mount handling transparent to the stages, i.e.
the individual stages do not need any code for different
file system types and the underlying devices.
2021-06-09 18:37:47 +01:00
Christian Kellner
92f936e15c stages: add mkfs.fat stage 2021-06-09 18:37:47 +01:00
Christian Kellner
819a094bc1 stages: add mkfs.xfs stage 2021-06-09 18:37:47 +01:00
Christian Kellner
f93dd9c397 stages: add sfdisk stage 2021-06-09 18:37:47 +01:00
Christian Kellner
0b330947cc stages: add truncate stage
Add a new stage that can be used to create, shrink or extend a file.
2021-06-09 18:37:47 +01:00
Christian Kellner
3085114ed7 devices: add support for loopback devices
Device service that provides support for bind files within the tree
to loopback devices. Valid parameters are the `filename`, `offset`
and `size`. This controls what part of the file to bind to the loop
device. The unit for `size` and `offset` is sectors and the sector
size can be configured via the `sector-size` parameter. The reason
behind the sector unit is so that numbers can easily be compared
with those specified in the partition table.
2021-06-09 18:37:47 +01:00
Christian Kellner
4f211eb0a5 osbuild: introduce device host service
A new host service that provides device functionality to stages.
Since stages run in a container and are restricted from creating
device nodes, all device handling is done in the main osbuild
process. Currently this is done with the help of APIs and RPC,
e.g. `LoopServer`. Device host services on the other hand allow
declaring devices in the manifest itself and then osbuild will
prepare all devices before running the stage. One desired effect
is that it makes device handling transparent to the stages, e.g.
they don't have to know about loopback devices, LVM or LUKS.
Another result is that specific device handling is now modular
like Inputs and Source are and thus moved out of osbuild itself.
2021-06-09 18:37:47 +01:00
Christian Kellner
26b15a062d format/v2: generalize stage module validation
Generalize the code that validates the stage `inputs`, so it can
be used for future extensions of the stage with new sub-modules.
2021-06-09 18:37:47 +01:00
Christian Kellner
1ed85dc790 inputs: convert to host service
Create a `InputService` class with an abstract method called `map`,
meant to be implemented by all inputs. An `unmap` method may be
optionally overridden by inputs to cleanup resources.
Instantiate a `host.ServiceManager` in the `Stage.run` section and
pass the to the host side input code so it can be used to spawn the
input services.
Convert all existing inputs to the new service framework.
2021-06-09 18:37:47 +01:00
Christian Kellner
08bc9ab7d8 inputs: pre-defined input paths
Instead of bind-mounting each individual input into the container,
create a temporary directory that is used by all inputs and bind-
mount this to the well known location ("/run/osbuild/inputs"). The
temporary directory is then passed to the input so that it can
make the requested resources available relative to that directory.
This is enforced by the common input handling code.
Additionally, pass the well known input path via a new "paths" key
to the arguments dictionary passed to the stage.
2021-06-09 18:37:47 +01:00
Christian Kellner
47fefe7e2d schema/v2: restrict input names
Ensure that input names start with a character and otherwise only
contain characters, numbers, `-`, `_` and `.`. Limit their length
to 255.
2021-06-09 18:37:47 +01:00
Christian Kellner
ef5e9364bb inputs: make inputs aware of their names
The name of the input here refers to its id within the manifest. This
is unique per stage and thus identifies a input for a given stage.
2021-06-09 18:37:47 +01:00
Christian Kellner
8c1a0a2eeb inputs: remove info.name proxy property
This helper property is misleading since it is not the name of the
input in the context of the manifest, but actually "type". Name is
a left-over from the nomenclature of format v1, where the type of
stages and inputs was called `name`.
2021-06-09 18:37:47 +01:00
Christian Kellner
463e67d61c api: root relative paths for stage arguments
Resolve relative paths for items the `api.arguments` call: Since paths
are different on the host and in the container, they can be transmitted
relative. Resolve the items for all groups that have paths registered.
2021-06-09 18:37:47 +01:00
Christian Kellner
3377f6c288 test/objectstore: add store server test
Include basic checks for the store server and client.
2021-06-09 18:37:47 +01:00
Christian Kellner
1743eceb41 objectstore: runtime exceptions for mount errors
Instead if using `check=True` for `subprocess.run`, which turns
a process failure (i.e. non-zero return codes) into generic a
`CalledProcessError` exception, use `check=False` and explicitly
handle mount errors, translating them into a `RuntimeError` with
a better error message.
2021-06-09 18:37:47 +01:00
Christian Kellner
f8428e56e2 objectstore: add Object.read_at method
Implement a new `read_at` method that will bind mount the tree of the
object to a specified location, instead of a temporary directory as
it done in the `read` method. Implement the latter via `read_at`.
Implement the corresponding methods for `Store{Client,Server}`. Since
the `ObjectStore.read_at` method will fail if the target directory
does not exist (or is of the wrong type), catch any exceptions in
the `StoreServer` and send those to the `StoreClient` via an `error`
entry.
This one is for David: also fix a missing blank line.
2021-06-09 18:37:47 +01:00
Christian Kellner
c9327a7a79 pipeline: remove left-over temp directory
The source temporary directory was left over from the time when
stages were using the source server API.
2021-06-09 18:37:47 +01:00
Christian Kellner
2b19e534e6 inputs/files: extract sources definition
Make the main portion of the schema more readable by extracting the
two possible reference definitions.
2021-06-09 18:37:47 +01:00
Christian Kellner
d577a306f9 inputs/files: extract metadata schema
Make the schema more readable by extracting the metadata definition.
2021-06-09 18:37:47 +01:00
Christian Kellner
869efab578 format/v2: extract stage-level input description
Extract the loop that describes the inputs at the stage level into
its own function. Mostly to keep the describe_stage method slim.
2021-06-09 18:37:47 +01:00
Christian Kellner
6a3b5818ef format/v2: small whitespace fixes
Fix a misaligned bracket.
2021-06-09 18:37:47 +01:00
Christian Kellner
acfc5f6d71 buildroot: set PYTHONUNBUFFERED env variable
This disables buffering for the standard output stream for python
executables spawn within the build root. This should help with
the ordering of text output in stages: when stdout is buffered,
debug messages via `print` will be end up in that buffer. When
executables are run in the stage, via `subprocess.run` their 
stdout has its own buffering, which will be flushed at the end 
of the run. If stdout was not manually flushed before invoking
the executable, the output of the tool will be emitted before
anything in the buffer. For example:
  print("stage")
  subprocess.run(["echo", "tool"])
Will lead have the following ordering:
  "tool"
  "stage"
To avoid this, without having to manually flush the stdout
buffer before every `subprocess.run`, disable buffering for
python binaries run inside the build root.
2021-06-09 18:37:47 +01:00
Christian Kellner
7f50d2b57f buildroot: don't specify encoding for popen
Since low-level primitives (os.read) are used to read from the stdout
pipe, manual text decoding was necessary there anyway. The `encoding`
argument meant that we could forgo the manual decoding for the call
to `communicate`. But this meant that text handling is not uniform.
Therefore, remove the `encoding` argument from the `Popen` call and
manual decode all the text.
2021-06-09 18:37:47 +01:00
Christian Kellner
13e629ba72 test/host: test for host services
Implement basic checks for the new host service scaffolding.
2021-06-09 18:37:47 +01:00
Christian Kellner
0562f5daf8 osbuild: introduce host services
Host services are a way to provide functionality to stages that is
restricted to the host and not directly available in the container,
such as providing input to stages, devices access and mounting.
This commit introduces a `ServiceManager` class that can be used to
start and (automatically) stop host service, as well as a `Service`
base class together with a `ServiceClient` class that be used to
implement host services and communicate with them. Refer to the doc
string of the module for more information.
2021-06-09 18:37:47 +01:00
Christian Kellner
70b971b83d util/jsoncomm: add send_and_recv helper
Often, a message is being sent and followed by a call to `recv`
to wait for a reply. Create a simple helper `send_and_recv` that
does both in one method.
Add a simple check for that helper to the tests.
2021-06-09 18:37:47 +01:00
Christian Kellner
610d1c45d5 util/jsoncomm: ability to create socket from fd
Add a new constructor method that allows creating a `Socket` from
an existing file-descriptor of a socket. This might be need when
the socket was passed to a child process.
Add a simple test for the new constructor method.
2021-06-09 18:37:47 +01:00
Christian Kellner
0447b00dfc util/jsoncomm: add pair constructor method
Add a new constructor method, `Socket.new_pair`, to create a pair
of connected sockets (via `socketpair`) and wrap both sides via
`jsoncomm.Socket`.
Add a simple test to check it.
2021-06-09 18:37:47 +01:00
Christian Kellner
a8fcda8348 meta: support definitions in schema version 2
For schema version 2 of modules, the `definitions` node, as defined in
the module itself, won't be at the `options` level but at the level of
the `properties` node. Look for a `definitions` at that `properties`
level and move it to the top, if found.
2021-06-09 18:37:47 +01:00
Christian Kellner
98a82ff47e aarch64: use single qemu-img thread
Work around a bug on aarch64[1] where `qemu-img` would hang
about a third of the time when converting images. To be able 
to activate the work-around based on the environment, i.e.
only on certain distributions, introduce an environment
variable, `OSBUILD_QEMU_IMG_COROUTINES`, that is set in the
runner and then picked up in the assembler.

[1] https://bugs.launchpad.net/qemu/+bug/1805256
2021-06-09 11:57:26 +02:00
Christian Kellner
1fbe4bb31a runners/rhel82: extract code into main function
Move the code in `__main__` to a `main` function to not pollute the
global namespace.
2021-06-09 11:57:26 +02:00
Christian Kellner
7ad212dc89 runners/rhel82: fix spacing between functions
Two lines between functions, demanded by PEP-8.
2021-06-09 11:57:26 +02:00
Christian Kellner
3a85c196f7 spec: move all ostree modules to the sub-package
When new ostree related stages and the new ostree input was added
they were included in the main package since all the modules were
manually listed in the corresponding exclude/include sections.
Change that by using wildcards, since all ostree related modules
should start with the org.osbuild.ostree* pattern.
2021-06-08 22:30:51 +02:00
Christian Kellner
5707c0a5b9 meta: proper error reporting for schema parsing
When parsing the module file, parse the JSON directly from the AST
node, because the AST node contains the line number of the schema
in the  module and thus we can resolve the correct line number for
errors  within the JSON. Convert the `JSONDecodeError` to a
`SyntaxError` which results in an overall better exception message:

Before:
Traceback (most recent call last):
  File "/workspaces/osbuild/osbuild/meta.py", line 331, in get_schema
    opts = self._make_options(version)
  [...]
  File "/usr/lib64/python3.9/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in
                              double quotes: line 2 column 1 (char 14)

After:
Traceback (most recent call last):
  File "/usr/lib64/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  [...]
    raise SyntaxError(msg, detail) from None
  File "stages/org.osbuild.ostree.init-fs", line 31
    additionalProperties: False
    ^
SyntaxError: Invalid schema: Expecting property name enclosed in ...
2021-06-07 17:55:00 +02:00
Christian Kellner
91e7708d80 meta: small whitespace fixes
Remove an extra line and properly align an closing bracket.
2021-06-07 17:55:00 +02:00
Christian Kellner
475b41c49a meta: promote list of modules to class level
Define the mapping of modules and their paths at the `ModuleInfo` class
level instead of having it inline in a function. This makes it possible
to use it from other places in the code.
2021-06-07 17:55:00 +02:00
Tomas Hozza
1c3aadba20 stages/dracut: disable hostonly mode and default to reproducible images
Disable host-only mode when running dracut and generate reproducible
images by default.

Suggested-by: gicmo
Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-06-07 12:15:26 +02:00
Tomas Hozza
8d43a78918 test: update test manifests to use Fedora 34
Move from using 'zram' to 'zram-generator-defaults' in the ostree bootiso
testing manifest. More information is available in Fedora 33 Change
document [1].

Add org.osbuild.kernel-cmdline stage to fedora-boot.json manifest
because of change in how grub handles the kernel command line arguments
[2].

GRUB2 Stage 2 checksums in assemblers test are updated. The change have
been verified by building the fedora-boot.json manifest with each checked
filesystem and booting the image in QEMU with legacy mode.

[1] https://fedoraproject.org/wiki/Changes/SwapOnZRAM
[2] https://github.com/osbuild/osbuild-composer/pull/982#issuecomment-697356929

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-06-07 12:15:26 +02:00
Martin Sehnoutka
ee3760e1ba sources/curl: Implement new way of getting RHSM secrets
The previous version covered too few use cases, more specifically a
single subscription. That is of course not the case for many hosts, so
osbuild needs to understand subscriptions.

When running org.osbuild.curl source, read the
/etc/yum.repos.d/redhat.repo file and load the system subscriptions from
there. While processing each url, guess which subscription is tied to
the url and use the CA certificate, client certificate, and client key
associated with this subscription. It must be done this way because the
depsolving and fetching of RPMs may be performed on different hosts and
the subscription credentials are different in such case.

More detailed description of why this approach was chosen is available
in osbuild-composer git: https://github.com/osbuild/osbuild-composer/pull/1405
2021-06-04 18:23:05 +01:00
Ondřej Budai
4f00e282ca readme: add IRC 2021-06-04 15:10:12 +02:00
Ondřej Budai
b5e324c874 ci: remove Fedora 32 tests
It's EOL.
2021-06-04 15:08:38 +02:00
Ondřej Budai
ef0939db9b ci: remove RHEL 8.4 tests
RHEL 8.4 is now GA, so we don't need any extra tests for it. This should also
make the CI more reliable because having two distros with the same DISTRO_CODE
caused some tests to fail randomly (they used the same intermediate
artifacts).
2021-06-04 15:08:38 +02:00
Christian Kellner
ec4d7c0c1c test/manifests: annotations for ostree container
Include the new OSTree specific annotations in the ostree container
manifest.
2021-05-26 13:17:01 +02:00