Commit graph

191 commits

Author SHA1 Message Date
Lars Karlitski
b5769add2c store: move queue out of the store
The store is responsible for two things: user state and the compose queue. This
is problematic, because the rcm API has slightly different semantics from weldr
and only used the queue part of the store. Also, the store is simply too
complex.

This commit splits the queue part out, using the new jobqueue package in both
the weldr and the rcm package. The queue is saved to a new directory `queue/`.

The weldr package now also has access to a worker server to enqueue and list
jobs. Its store continues to track composes, but the `QueueStatus` for each
compose (and image build) is deprecated. The field in `ImageBuild` is kept for
backwards compatibility for composes which finished before this change, but a
lot of code dealing with it in package compose is dropped.

store.PushCompose() is degraded to storing a new compose. It should probably be
renamed in the future. store.PopJob() is removed.

Job ids are now independent of compose ids. Because of that, the local
target gains ComposeId and ImageBuildId fields, because a worker cannot
infer those from a job anymore. This also necessitates a change in the
worker API: the job routes are changed to expect that instead of a
(compose id, image build id) pair. The route that accepts built images
keeps that pair, because it reports the image back to weldr.

worker.Server() now interacts with a job queue instead of the store. It gains
public functions that allow enqueuing an osbuild job and getting its status,
because only it knows about the specific argument and result types in the job
queue (OSBuildJob and OSBuildJobResult). One oddity remains: it needs to report
an uploaded image to weldr. Do this with a function that's passed in for now,
so that the dependency to the store can be dropped completely.

The rcm API drops its dependencies to package blueprint and store, because it
too interacts only with the worker server now.

Fixes #342
2020-05-08 14:53:00 +02:00
Ondřej Budai
3ba8c79e5e test/image: don't fallback to hvf/tcg if kvm is not available
-cpu host cannot be used with anything else than kvm. This commit removes
hvf and tcg because it doesn't make any sense with -cpu host.

If this causes some issues for anyone, we can revert back and remove -cpu
host.
2020-05-04 10:12:56 +02:00
Ondřej Budai
0c354e34e4 test/image: fix qemu args on qemu>=4.2
Running qemu with -accel accel= results in the following error:

qemu-system-x86_64: -accel accel=kvm:hvf:tcg: Don't use ':' with -accel,
use -M accel=... for now instead

Qemu 4.2 deprecated the -accel accel= argument. When the arg is passed in,
qemu exists status code of 1.

This commit changes the qemu command to use the recommended way of specifying
the acceleration options.

See:
3d5e90a50b
2020-05-04 10:12:56 +02:00
Alexander Todorov
02482a0eea tests: Distro is fedora-31 update the repo URL to match 2020-04-29 18:48:51 +02:00
Ondřej Budai
6eb43c3d97 worker: add a support for uploads to azure
Everything else is already implemented, this commit just connects the bits
and pieces in worker.
2020-04-29 18:15:13 +02:00
Ondřej Budai
b916a88242 worker: fix passing the result from osbuild when it fails
I tried fixing this in 181128c5 and forgot to pass the right error in one
place. This commit fixes it.
2020-04-29 11:40:36 +02:00
Ondřej Budai
e235fdedb3 tests/image: boot the vhd images on Azure
Previously, vhd images were tested using QEMU. This commit changes that to
boot them in the actual Azure infrastructure.

Azure VMs have quite a lot of dependencies - a network interface, a virtual
network, a network security group, a public ip address and a disk. Azure CLI
and Azure Portal handle the creation of all these resources internally.
However, when using the API, the caller is responsible to create all these
resources before creating an actual VM.

To handle the creation of all the resources in the right order, a deployment
is used. A deployment is a set of resources defined in a JSON document.
It can optionally take parameters to customize each deployment. After the
deployment is finished, the VM is up and ready to be tested using SSH.

Sadly, the deployments are a bit hard to clean-up. One would expect that
deleting a deployment removes all the deployed resources. However, it doesn't
work this way and therefore it's needed to clean up all resources "manually".
For this reason, our deployment sets a unique tag on all the resources created
by the deployment. After this test is finished, the API is queried for all
the resources with the tag and then, they're deleted in the right order.
2020-04-27 20:34:20 +02:00
Ondřej Budai
0041ae5655 tests/image: move constants to a subpackage
The cmd/osbuild-image-tests package is becoming bigger than I would like to.
It will be nice to split it to some smaller pieces at some point.
This commit does the first step - splits off the first subpackage containing
all the constants.
2020-04-27 20:34:20 +02:00
Ondřej Budai
b109ec878e cmd/osbuild-upload-azure: improve error message on wrong arguments
After this commit osbuild-upload-azure tool returns the help text when wrong
arguments were passed to it.
2020-04-27 20:34:20 +02:00
Ondřej Budai
181128c5b9 worker: fix missing logs when osbuild fails
The commit 2435163f broke sending the logs to osbuild-composer. This was
partly because of unusual error handling in the RunOSBuild function.

This commit fixes that by creating a custom error and properly propagating
the result from it.
2020-04-27 19:36:22 +02:00
Ondřej Budai
7b784aaa7e tests/image: drop support for raw.xz images
raw.xz is not used anymore, let's drop the dead code.

Yay, deleting code!
2020-04-24 15:27:39 +02:00
Ondřej Budai
8f351026d8 tests/image: drop the qemu-extract boot type
Previous commit switched the ami output type to qemu boot type, therefore
qemu-extract is not needed anymore.
2020-04-24 15:27:39 +02:00
Ondřej Budai
e890e03d68 tests/image: run the tests in parallel (somewhat)
This commits enables the parallelism for the image tests. However, there's
a catch. Osbuild cannot be reliably run in parallel, so the code uses
a mutex to ensure there's always only one osbuild instance for now. Even
with this limitation, there's a significant speed-up of the tests:

Prior this commit, the image tests run in 40 minutes on Travis. After this
commit, the time is reduced to 32 minutes.

The speed-up will have an even bigger effect when more cloud-upload tests are
added to the test suite.
2020-04-24 08:41:31 +02:00
Major Hayden
3dbfdc4ee6 🐎 Run dnf-json tests in parallel
Run multiple dnf-json tests in parallel to speed up execution. The
total number of parallel tests is limited by the number of CPUs in
the machine that is running the tests.

Signed-off-by: Major Hayden <major@redhat.com>
2020-04-23 09:13:22 +02:00
Major Hayden
1d743f048a 🐣 Add initial RHEL 8.3 support
The osbuild changes were made in osbuild/osbuild#341.

Signed-off-by: Major Hayden <major@redhat.com>
2020-04-22 15:25:59 +02:00
Major Hayden
3740e9bc6b 🐎 Allow qemu to use all available CPUs
Speed up the boot tests by allowing qemu to use all of the available
CPUs on the system. Our CI VMs have at least 2 CPUs and this shortens
the time required for a boot test.

Signed-off-by: Major Hayden <major@redhat.com>
2020-04-17 17:10:56 +02:00
Lars Karlitski
4a710429de worker: rename API to Server
This makes it symmetric with the client:

    s := worker.NewServer()
    c := worker.NewClient()
2020-04-16 01:02:16 +02:00
Lars Karlitski
ac40b0e73b jobqueue: rename to worker
This package does not contain an actual queue, but a server and client
implementation for osbuild's worker API. Name it accordingly.

The queue is in package `store` right now, but about to be split off.
This rename makes the `jobqueue` name free for that effort.
2020-04-16 01:02:16 +02:00
Martin Sehnoutka
e887518736 image-tests: Include qemu command specific for aarch64
The osbuild-image-tests don't currently support boot test for any
alternative architecture because the qemu-system-x86_64 command is
hardcoded. This patch introduces a branch specific to aarch64, but
without a KVM support as I was unable to make it run in Beaker, which is
currently the only offering we have with ARM machines. As a workaround
the boot tests will be skipped if kvm kernel module is not found and only
image-info tests will run.
2020-04-15 15:22:57 +02:00
Lars Karlitski
eb5b198205 dnf-json-tests: use subtests in TestCrossArchDepsolve
For one, this allows us to use `require` instead of `assert` and
`continue`, which was awkward to read. That works because it's ok to
fail a subtest: the remaining subtests are executed after it.

Also, this shows which test was executed, making debugging easier:

    === RUN   TestCrossArchDepsolve
    === RUN   TestCrossArchDepsolve/fedora-30
    === RUN   TestCrossArchDepsolve/fedora-30/x86_64
    === RUN   TestCrossArchDepsolve/fedora-30/x86_64/ami
    ...

You can now also run those sub tests in isolation:

    osbuild-dnf-json-tests -test.run TestCrossArchDepsolve/fedora-30/x86_64/ami

Lastly, it enables running those tests in parallel (not part of this
patch) by calling `t.Parallel()`.
2020-04-07 14:40:12 +02:00
Lars Karlitski
a2a6e79d21 dnf-json-tests: use assert.NoErrorf to check for errors
This function prints the formatted unexpected error message, instead of
the error struct in golang syntax.

It also allows to remove the error in the assertion message.
2020-04-07 14:40:12 +02:00
Lars Karlitski
89447a6a7b dnf-json-tests: rename repositories to repoDir
This variable holds the directory from which to load repository
information, not the repositories themselves.
2020-04-07 14:40:12 +02:00
Lars Karlitski
07d06f1efd dnf-json-tests: sort imports 2020-04-07 14:40:12 +02:00
Ondřej Budai
7dd09443cf tests/image/ami: test ami images on AWS
Prior this commit the ami images were tested locally using qemu. This does
not reflect at all how they're used in practice. This commit introduces
the support for running them in the actual AWS. Yay!

The structure of code reflects that we want to switch to osbuild-composer
to build the images soon.
2020-04-06 16:38:28 +02:00
Ondřej Budai
92e69dcb85 tests/image: extract one test method for each boot type
Shorter functions are always nicer, right? Also, the AWS and Azure tests will
be longer, this change prepares for that.
2020-04-06 16:38:28 +02:00
Ondřej Budai
00f903b879 tests/image: refactor constants
It's not very clear that the constants are indeed constants. This commit moves
them to a new struct. This way it should be more clear that those values are
constants.
2020-04-06 16:38:28 +02:00
Ondřej Budai
640a9fcd92 tests/image: pass the ssh key from boot types
Soon, images will be run non-locally (AWS, Azure). For the remote ones it's
potentially dangerous to use the publicly available key-pair. This change
prepares the codebase for specifying different keys than the pre-generated
one.
2020-04-06 16:38:28 +02:00
Ondřej Budai
1a8379f2cd tests/image: extract withTempDir helper
It will be needed on another place at some point, I promise.
2020-04-06 16:38:28 +02:00
Ondřej Budai
ca3c469bdc tests/image: move the namespace creation closer to the boot types
Soon, images will be run non-locally (AWS, Azure). For those boot types
there's no need to have an unshared network namespace. This commit prepares
the code for that.
2020-04-06 16:38:28 +02:00
Ondřej Budai
cd51cfdcdf tests/image: allow to specify host address
Soon, images will be run non-locally (AWS, Azure). This commit adds support
to test ssh for different machines than those on localhost.
2020-04-06 16:38:28 +02:00
Ondřej Budai
7baacda6ef tests/image: allow to run ssh without network namespace
Soon, images will be run non-locally (AWS, Azure). For this, we cannot
use ssh in a namespaced environment. This commit makes the namespace for ssh
optional.
2020-04-06 16:38:28 +02:00
Ondřej Budai
e593bceede tests/image: use NoError when asserting errors
This is not a functional change (except for the slightly different output).
NoError() is more understandable (both in the code and in the output) than
Nil() when asserting errors. Also the rest of the tests uses mostly NoError()
when asserting errors, this change should lead to a better consistency.
2020-04-06 16:38:28 +02:00
Ondřej Budai
e6f323e6b6 tests/image: format osbuild output in case of a failure
testify library cannot deal with error messages with length > 64k. Sadly,
osbuild output is very long one line. This commits formats the output before
making the error from it.
2020-04-06 16:38:28 +02:00
Lars Karlitski
2435163fc9 worker: move running osbuild into separate function
Setting up a command to run is quite involved. Separate that from the
logic of running it.
2020-04-06 12:11:54 +02:00
Lars Karlitski
1ece08414c jobqueue: move Job.Run() to the worker
This makes the jobqueue package independent of forking osbuild, the
choices for which (exact invocation, location of the cache directory)
should be made in the worker.
2020-04-06 12:11:54 +02:00
Lars Karlitski
d3b9a3515d worker: inline handleJob()
It's a small function that's only called once.
2020-04-06 12:11:54 +02:00
Lars Karlitski
db5dd1ee2c worker: remove redundant UpdateJob() call
A job is already set to be running when it is returned from the API (see
Store.PopJob()).
2020-04-06 12:11:54 +02:00
Lars Karlitski
1f06d78362 jobqueue: rename ID to ComposeID in job structs
It's not an id of the job, but the compose id.
2020-04-06 12:11:54 +02:00
Martin Sehnoutka
92145822d9 distro: rename ListArchs to ListArches
In PR#395 we discussed the spelling of archs vs. arches and we agreed to
use arches. This patch only renames the public method `ListArchs`in the
`Distro` interface.
2020-03-30 10:41:02 +02:00
Tom Gundersen
f945c5057e osbuild-pipeline: always pass repositories as input
Require repository informaiton to be passed as input, rather than
read from the current directory.

Reading from the repository informaiton meant to be used by weldr
has several drawbacks.
 - it makes it impractical to use the tool outside a git checkout
 - it makes it awkward to adapt the repositories to different use
   cases
 - it means that the shipped repositories cannot be extended with
   update repos, as the same repos are used for testing, and that
   would render our tests non-reproducible.

Overall, we are moving towards making repositories something the
caller must always pass in, rather than something that composer
maintains. For the weldr API we need to keep working as before,
but for new APIs we are avoiding that.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-03-29 16:08:36 +02:00
Tom Gundersen
fa015a70f6 rcm: rework the API for submitting composes
The API allowed composes to have multiple architectures, image
types and repositories. Turns out that's not exactly what we want
it is not clear how to combine the lits of each. Each architecture
might not combine with each image type, and it is not clear which
repositories are need for each image build. Lastly, while allowing
different image builds to have different distros in the same
compose does not appear immediately useful, there is no particular
reason to disallow that. This patch reworks the way composes are
specified.

The intention remains the same, to be able to submit several image
builds as one compose. But rather than taking arrays of image types
and architectures, take one array of image builds instead, each of
which consists of one distro, one architecture, one image build and
an array of repositories.

In a follow-up patch they will also each contain an array of upload
targets.

This means that each image build will have the same sort of structure
as a compose request in the weldr API. The reason we want to submit
an array of them rather than have them as individual composes, is that
in a follow-up patch we will introduce the concept of a "finalizer",
or "call-back" or something to that effect, which will be triggered
when all the images have been built successfully. The use-case is,
as always, koji, which requires this.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-03-29 16:08:04 +02:00
Alexander Todorov
7967ecbbf8 tests: Make TestSources distro independent. Refs #315
by calling `composer-cli sources info` on a user defined repository
2020-03-25 16:30:52 +01:00
Lars Karlitski
3b5d5a73d3 worker: drop default port
We require passing the address from the unit file. Do the same for the
socket, using host:port syntax.

Overriding the port was broken before, because we unconditionally
appended ":8700" to every address.
2020-03-25 14:05:44 +01:00
Lars Karlitski
f8982f4a1a worker: don't hard code path to unix domain socket
Introduce a mandatory argument `address`, which is interpreted as a path
to a unix socket when `-unix` is given or a network address otherwise.

Move the default path to the service file.

Add a more useful usage message when passing `-help` or no arguments.
2020-03-25 14:05:44 +01:00
Lars Karlitski
b5432e78b9 worker: move ComposerClient to jobqueue package
This moves the client code into the same package as the server code,
which makes it easier to change (and version) the two in sync. Also, it
will allow to make some structs private to the jobqueue package and to
test `Client`.

Also rename it to jobqueue.Client.
2020-03-25 14:05:44 +01:00
Lars Karlitski
cb4421b69f worker: remoteAddress → address 2020-03-25 14:05:44 +01:00
Lars Karlitski
94183d14a8 worker: split NewClient()
Use the default dialing functions for tcp connections and set the tls
config on the transport directly. This makes the code easier to follow,
because the only special case is overriding the DialContext() for unix
connections.
2020-03-25 14:05:44 +01:00
Lars Karlitski
845ba6e8e5 worker: don't hard code upload URL
This doesn't work with remote workers.
2020-03-25 14:05:44 +01:00
Lars Karlitski
9e71df234a worker: load tls certificates once on startup 2020-03-25 14:05:44 +01:00
Lars Karlitski
16cd243300 worker: set remoteAddress once on startup 2020-03-25 14:05:44 +01:00