Commit graph

496 commits

Author SHA1 Message Date
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
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
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
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
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
Tom Gundersen
8797cd4704 common: drop unused image types
The Alibaba and GCE image types were not used, and they were
causing problems when translated from and to strings as they were
mapping to the same internal image type. The end result was that
AWS jobs were shown as Alibaba or GCE in the UI.

This fixes #369.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-04-03 08:46:50 +02:00
Jakub Rusz
8861c6dbb9 tests: increase coverage of internal/crypt
fixes #444
2020-04-02 20:12:06 +02:00
Jakub Rusz
4f160447ee tests: use asserts in states_test.go 2020-04-02 09:17:09 +02:00
Jakub Rusz
1cf2af10d0 tests: add coverage for common/helpers.go
This also changes the helpers.go to enable mocking all the different architectures.
2020-04-02 09:14:40 +02:00
Ondřej Budai
bbd71efeff distro/rhel: remove dracut-config-generic from build packages
The build pipeline doesn't run dracut nor install kernel, the package is
therefore useless in it.
2020-04-01 12:29:59 +02:00
Ondřej Budai
c48728a049 distro/rhel: move dracut-config-generic to bootloader packages
This change makes the dracut-config-generic installation in par with
Fedora. Also, by having it in bootloader packages, it is not installed in
non-bootable images, where it provides no value.
2020-04-01 12:29:59 +02:00
Ondřej Budai
f14224ede1 distro/fedora: add dracut-config-generic to bootloader packages
Dracut is unfortunately very host-dependant by default. The package
dracut-config-generic forces it use a generic configuration instead of a
configuration generated from the host environment.

This change should make the image generation more reproducible. For example
it was not possible to boot ami images built on Travis on AWS prior this
commit.

Also, the tests were re-generated in this commit.
2020-04-01 12:29:59 +02:00
Jiri Kortus
b0e28689fb Add unit test for systemd stage
Refs: #406
2020-04-01 09:52:10 +02:00
Lars Karlitski
3a957f4b16 store: don't add custom repositories in PushCompose()
The weldr API already passes custom repositories, so they end up in the
list twice. This is a bit awkward, because weldr passes something to the
store that the store already knows about. It only works this way right
now though, because the rcm API doesn't need these repositories at all.
It expects all repositories to be passed.
2020-04-01 00:29:13 +02:00
Lars Karlitski
cef7267a2d store: create compose id from PushCompose
Every caller had to make their own uuid and pass that into
PushCompose(). Make PushCompose() create the id and return it.
2020-04-01 00:29:13 +02:00
Lars Karlitski
a6338410bc rcm: remove outdated comment
PushCompose() does not inject a local target anymore.
2020-04-01 00:29:13 +02:00
Lars Karlitski
eb10cf3124 store: remove unused arguments from PushCompose 2020-04-01 00:29:13 +02:00
Jiri Kortus
e516180640 Add unit tests for SELinux stage
Refs: #406
2020-04-01 00:26:22 +02:00
Jiri Kortus
44b501d401 Add unit test for timezone stage
Refs: #406
2020-04-01 00:25:59 +02:00
Jiri Kortus
8dafb64f1b Add unit tests for script stage
Refs: #406
2020-04-01 00:25:34 +02:00
Jiri Kortus
8c808831d3 Add unit test for users stage
Refs: #406
2020-04-01 00:24:39 +02:00
Jiri Kortus
ea02b33d2b Add unit test for RPM stage
Refs: #406
2020-04-01 00:19:43 +02:00
Jakub Rusz
703039495b tests: add coverage for internal/blueprint/customizations.go 2020-03-31 16:47:00 +02:00
Jakub Rusz
4807b64dea tests: add coverage for compose_result.go 2020-03-31 16:32:34 +02:00
Jakub Rusz
2b87ca41b5 Separate nested structure in compose_result.go
This separated the nested structure into their own struct types.
2020-03-31 16:32:34 +02:00
Jiri Kortus
600a0f50a9 Add unit test for locale stage
Refs: #406
2020-03-31 09:35:20 +02:00
Jiri Kortus
c4d5edaf0d Add unit tests for Pipeline struct
Refs: #406
2020-03-31 09:35:11 +02:00
Brian C. Lane
107ecde90b store: Fix setting interrupted composes to failed at startup
If a compose was interrupted by restarting osbuild-composer it should be
set to failed at startup. This was not working because imgBuild is a
temporary variable, the value stored in ImageBuild needs to be modified
directly.
2020-03-31 09:34:25 +02:00
Jiri Kortus
f5ad337c62 Add unit test for keymap stage
Refs: #406
2020-03-30 20:45:33 +02:00
Jiri Kortus
c2ed6da92e Add unit test for hostname stage
Refs: #405
2020-03-30 20:44:16 +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
7825132ae2 test/cases: include repository information
This means that the unit tests no longer need to load the
repositories from the git repo, and in a follow-up, osbuild-composer
won't need to either.

By splitting the repositories used for testing from the system
repositories available through the weldr API we are able to extend
the system repositories without affecting the reproducibility of
the tests.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-03-29 16:08:36 +02:00
Tom Gundersen
a949843f1e test/cases: rename output-format to image-type
Bring this in line with our naming convention.

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
Tom Gundersen
1c0d951f54 rcm: make repository struct private
This is only used internally to the `submit()` function.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-03-29 16:08:04 +02:00
Martin Sehnoutka
db4b6e71ed distro_test: add test that covers BuildPackages
The main reason here is not to make sure we have the right set of build
packages, but rather to make sure the pointer hierarchy (distro->arch->
image type) works as expected.
2020-03-28 00:21:31 +01:00
Martin Sehnoutka
91f572e961 fedora30,32: merge fedora3XImageType into imageType struct
This patch uses the same approach as fedora31 few commits ago. It moves
the arch pointer to the imageType struct and sets it while creating the
distro->arch->image type hierarchy in the setImageType function. The
rest of the patch is just renaming.
2020-03-28 00:21:31 +01:00
Martin Sehnoutka
ff065cc7d0 fedora30,32: merge fedora3XArch structure into arch
It uses the same approach as fedora31 few commits ago. The pointer to
distro is moved to "arch" and "arch" now contains a map of allowed
image types for each arch.

Also include setArches and setImageTypes helper functions to ease the
creation of pointers from the structures to a parent structure while
creating the distro->arches->image types hierarchy.
2020-03-28 00:21:31 +01:00