Commit graph

815 commits

Author SHA1 Message Date
Lars Karlitski
54c44cf135 README: we're only requiring Go 1.12 right now 2020-04-09 15:18:58 +02:00
Lars Karlitski
47df3820ce jsondb: don't use error wrapping (%w)
This is a Go 1.13 feature. We're trying to run on 1.12 for now.
2020-04-09 15:18:58 +02:00
Major Hayden
a604482f09 📜 Add PR gating docs
Signed-off-by: Major Hayden <major@redhat.com>
2020-04-09 12:33:38 +00:00
Jacob Kozol
105124dd25 store: use default size in image build
If a user creates a compose with a size of 0, the default image size for
the image type should be used. Also, certain image types have
requirements for the image size. In order to ensure that the proper image
size is stored in the compose object, the compose's ImageBuild object
uses ImageType.Size() to get the correct image size for the image type.
2020-04-09 13:56:21 +02:00
Martin Sehnoutka
d702760182 test/cases: regenerate fedora test cases for x86_64
We made few changes to the format of the test cases, regenerate them to
reflect the change and also to make sure it still works.
2020-04-09 13:22:59 +02:00
Martin Sehnoutka
e769377f0e crypt_test: don't run on macOS
The new crypt tests cannot be run on macOS. Making them conditional for
non-macOS platforms fixes running unit tests in the internal directory
on macOS.
2020-04-09 13:21:30 +02:00
Lars Karlitski
17f4281648 jsondb: introduce a simple JSON database
weldr's store is quite complex and handled serialization itself. Move
that part out into a separate package `jsondb`.

This package is more generic than the store needs: it can write an
arbitrary amount of JSON documents while the store only needs one:
state.json. This is in preparation for future work, which introduces a
queue package that builds on top of `jsondb`.
2020-04-09 08:52:31 +02:00
Lars Karlitski
6bf31423a2 codecov: disable codecov/patch status
Codecov's patch status measures lines covered in a given pull request,
which fails when moving code around.

Adding code with no coverage still fails the codecov/project status,
which fails if coverage has gone down.
2020-04-08 22:26:45 +02:00
Martin Sehnoutka
f51932974a test-case-generators: use unxz also for aws
In PR #400:
https://github.com/osbuild/osbuild-composer/pull/400
we changed the boot type of AWS images from qemu-extract to aws, which
resulted in a bug in the generate-test-case script. It tried to attach
xz archive using qemu-nbd which works just fine from qemu-nbd
perspective but sfdisk and blkid of course failed, because the xz
archive is not a disk image.

This patch makes sure we extract the image before attaching it to
/dev/nbdX.
2020-04-08 11:20:23 +02:00
Martin Sehnoutka
1ae1131fe4 image-info: report errors from subprocess calls
The subproces.check_output function hides the output of the subprocess
it runs, using subprocess.run directly enable us to see the errors.
2020-04-08 10:27:26 +02:00
Martin Sehnoutka
2b83a16c37 osbuild requirement: bump to version 11
The newest osbuild is needed for support for aarch64. The aarch64 images
are using GPT which requires stable partuuid which was included in the
latest osbuild release (11). This will be used to produce stable
image-info tests.
2020-04-07 21:14:05 +02:00
Major Hayden
f124b8e0e0 📦 Use prepared containers
We added this to osbuild but it was never added to osbuid-composer.

Signed-off-by: Major Hayden <major@redhat.com>
2020-04-07 20:16:58 +02:00
Lars Karlitski
0d3c8329c0 dnf-json: change base error type
Even though `dnf.exceptions.RepoError` is documented as the base error,
`dnf.exceptions.Error` is actually the base error (and also documented
as such).
2020-04-07 14:40:12 +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
Major Hayden
abb30b947c 🤏 Little bit more testing: weldr-tests
Signed-off-by: Major Hayden <major@redhat.com>
2020-04-07 12:19:00 +00:00
Major Hayden
af967dd8cc 🤏 Little bit more testing: osbuild-tests
Signed-off-by: Major Hayden <major@redhat.com>
2020-04-07 09:05:52 +02:00
Lars Karlitski
8ef4db816d jobqueue/api: return errors as JSON
The API is always advertising a content type of application/json, but
not sending JSON on errors.

Change it to send simple JSON objects like this:

    { "message": "something went wrong" }

This can be extended to include more structured information in the
future.

Also return an (for now) empty JSON object from `addJobHandler()`. It
returned nothing before, which is invalid JSON.

Stop testing for the actual error strings in `api_test.go`. These are
meant for humans and can change. Only check what a client could
meaningfully check for, which is only the HTTP status code right now.
2020-04-06 19:51:36 +02:00
Lars Karlitski
ce6d3c511a jobqueue/api: don't panic when error cannot be returned
Don't panic when the error message cannot be written to the connection.
Ignore it, because there's nothing we can do in this case. The standard
library has the same behavior.
2020-04-06 19:51:36 +02:00
Lars Karlitski
2ac76602bb jobqueue/api: add additional test cases 2020-04-06 19:51:36 +02:00
Lars Karlitski
6083eb3867 jobqueue/api: don't redundantly set 200 OK
This wasn't done in all cases and is redundant, because the default
status is 200 OK.
2020-04-06 19:51:36 +02:00
Lars Karlitski
4cc459c5cc jobqueue: move remaining request struct to json.go 2020-04-06 19:51:36 +02:00
Alexander Todorov
bd4793eb58 tests: verify system-wide sources can't be deleted. Closes #315
make sure this test can be run both as a unit test and as an
integration test on a running system
2020-04-06 19:49:23 +02:00
Alexander Todorov
a1eb6b4cd5 tests: verify user defined sources can be deleted. Refs #315 2020-04-06 19:49:23 +02:00
Martin Sehnoutka
24b25bd06c test-case-generators: report errors from child processes
The current implementation does not report any errors because it uses
the subprocess.check_output function from Python std library. The
function is convenient to use but it hides all the errors from us which
makes it very inconvenient when the test generation often fails (like
developing support for alternative architecture). This patch introduces
a wrapper around the subprocess.run function which dumps the
subprocess's stdout to stderr in case of failure and forwards it to the
caller in case of success. This way the generation code is still very
straight forward, but the errors are reported properly.
2020-04-06 19:48:29 +02:00
Brian C. Lane
0eb3bfe89a weldr: Adding sources with empty name should return an error
Currently, if a TOML source is added with no name, or the source is
incorrectly inside a [section] it will add an empty source, causing
depsolving to crash.

This adds tests for 'name' and 'type' fields as a minimum requirement,
and returns an API error if they are empty or missing.

This also includes unit and integration tests.

Closes PR#462
2020-04-06 19:34:37 +02:00
Brian C. Lane
58c16f1e6d weldr, store: Add toml fields to SourceConfig
TOML output of the source wasn't using the correct field names or case.
This adds toml tags to the weldr.SourceConfigV0, and store.SourceConfig
structs.
2020-04-06 19:34:37 +02:00
Major Hayden
41e8090e95 🔮 Add dnf integration tests
Run the dnf integration tests with every pull request.

Signed-off-by: Major Hayden <major@redhat.com>
2020-04-06 19:06:06 +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
ada058f2c3 jobqueue: move Job struct to client.go
`Job` is now a simple data struct, which is only used to return
multiple arguments from `AddJob()`. Move it to that file.
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
54b63a645f jobqueue: remove JSON tags on Job
Job is not used for serialization anymore.
2020-04-06 12:11:54 +02:00
Lars Karlitski
ab2c8aff08 jobqueue: make import declarations consistent
The usual style is three blocks: standard library, external
dependencies, internal dependencies.

Also run through `go fmt`, which sorts each of those blocks
alphabetically.
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
Lars Karlitski
269988a737 jobqueue: start moving API types to json.go
Similar to `weldr/json.go`, this file will contain structs that are
shared between client and server and only meant to be used to
serialize from and to JSON.

This immediate change allows us to make fields in `Job` private in a
future commit.
2020-04-06 12:11:54 +02:00
Ondřej Budai
9a96908c1e upload/aws: delete the s3 object after the snapshot is imported
After the snapshot is imported to EC2, there's no point in having the s3
object anymore. If the s3 object is not deleted, the user will be charged
for it periodically, while the object doesn't provide any value.
2020-04-04 02:49:00 +02:00