Commit graph

60 commits

Author SHA1 Message Date
Tom Gundersen
5fcdd4bea5 distro: don't use a global variable to store the distro register
Introduce a DistroRegister object. For now this does not introduce
any functional changes, as the object is always instantited to be
the same. However, in follow-up patches it will get options.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-01-03 22:35:52 +01:00
Ondřej Budai
8c6f5016b0 api: implement /compose/log 2019-12-20 11:43:39 +01:00
Ondřej Budai
665a7d81a8 api: return actual logs in /compose/logs
Commit b1c5ef2a introduced support for retrieving logs from osbuild.
This commit finishes the second part - actually returning the logs
from /compose/logs route.
2019-12-20 11:43:39 +01:00
Ondřej Budai
fb14c2c2c8 api/test: add check for status code in compose/logs check 2019-12-20 11:43:39 +01:00
Tom Gundersen
0ef89aa864 store: fix compose state handling on restart
When restarting composer, we were not handling the compose states
correctly.

This resolves that as follows:
 * any running composes are marked as failed,
 * any waiting composes are put back in the pending jobs queue

As a consequence of needing the ability to reinitialize the job
queue, we must include the depsolved pipeline in the compose object.
This is the correct thing to do, as the semantics we currently
adhere to is that pipelines are depsolved when the compose is
started (and restarting composer should not affect this by for
instance re-depsolve the pipeline).

Resolves rhbz#1784062.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-12-17 21:49:11 +01:00
Lars Karlitski
57aea4160d weldr: return version as string from api/status
This is what lorax-composer does and composer-cli expects.
2019-12-13 00:14:40 +01:00
Lars Karlitski
d9ad5d7062 weldr: add toml output to projects/source/info 2019-12-11 18:53:10 +00:00
Lars Karlitski
72e1da47ab weldr: make projects/source/new accept text/x-toml
composer-cli sends sources as toml if the original format is toml.
2019-12-11 18:53:10 +00:00
Tom Gundersen
d33fc5f010 composer: add provisional multi-arch support
The pipeline generation now takes the architecture as an argument.
Currently only x86_64 is supported. The architecture is detected
at start-up, and passed down to each pipeline translation.

For osbuild-pipeline we now requrie the architecture to be passed
in.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-12-11 15:23:24 +01:00
Lars Karlitski
ea70d9dfc5 blueprint: don't set omitempty for toml groups and modules
The integration tests expect the empty arrays to be there.
2019-12-10 20:21:47 +00:00
Lars Karlitski
0718766fbc weldr: fix reply on compose/info route
composer-cli requires `dependencies.packages` to exist. We can still
leave it empty for now, because it doesn't look at the contents.
2019-12-10 20:21:47 +00:00
Lars Karlitski
b7dac20c74 weldr: add test for blueprint/depsolve route 2019-12-10 20:38:22 +01:00
Ondřej Budai
6bbc89d5f3 api: implement /compose/delete route 2019-12-10 01:14:36 +01:00
Ondřej Budai
6d15833e4e store: introduce state directory
Prior to this commit outputs directory used by local target was owned by root.
This made impossible for osbuild-composer to delete images. (osbuild-composer
doesn't run as root).

This commit introduces state directory in which osbuild-composer creates
outputs directory. Because this directory is owned by osbuild-composer, it's
able to delete files inside.
2019-12-10 01:14:36 +01:00
Ondřej Budai
4e62f181fa api: implement /compose/logs route
The implementation is just a stub returning always the same tar archive.
The ability to return actual logs will be implemented in the future - osbuild
isn't currently returning any logs.
2019-12-08 00:21:30 +01:00
Ondřej Budai
d7f81b36e6 api: implement /compose/info route
Not everything is implemented in this route but enough to pass the tests.
2019-12-06 10:42:19 +01:00
Lars Karlitski
b1c65bb671 blueprint: tag all struct fields for toml
This is repetitive, but there doesn't seem to be another way to export
lower-case field names.
2019-12-04 19:15:33 +01:00
Lars Karlitski
94bfcc518c weldr: bump blueprint version
According to the same rules as lorax-compposer:

  https://weldr.io/lorax/lorax-composer.html#blueprints
2019-12-04 18:35:18 +01:00
Ondřej Budai
b6307cafd5 api: fix compose routes returning null instead of empty array
Cockpit-composer really doesn't like that
2019-12-03 11:49:35 +01:00
Lars Karlitski
20bb60f3fd weldr: add support for toml blueprints 2019-12-03 01:27:00 +01:00
Ondřej Budai
f4991cb1ca api: Add support for upload API
This commit introduces basic support for upload API. Currently, all the routes
required by cockpit-composer are supported (except for /compose/log).

Also, ComposeEntry struct is moved outside of the store package. I decided
to do it because it isn't connected in any way to store, it's more connected
to API. Due to this move there's currently a known bug that image size is
not returned. This should be solved by moving Image struct inside Compose
struct by follow-up PR.
2019-12-01 00:05:17 +01:00
Ondřej Budai
66c57a05b7 api tests: add store fixtures
Prior this commit there wasn't an easy to populate the store. The only way
was to call the weldr API or store methods. This design made testing of
various edges quite hard.

This commit adds store fixtures - an easy way how to define store state
before each test case.

In addition, the fixtures were refactored so that new instances are created
prior each test. Before this change the tests were in some cases dependant
on each other.
2019-11-27 22:27:40 +01:00
Ondřej Budai
a00a0caa70 api tests: refactor weldr and jobqueue api tests to use common helpers
The helper functions in both api packages were more or less same. However,
over time they have been slowly diverging. This commit extract the helpers
into one common package to make the tests more maintainable and
to deduplicate the code.
2019-11-27 22:27:40 +01:00
Lars Karlitski
b911d0b928 weldr: get repositories from distro
Make distros export repository information and use those in the weldr
API. This means that repos are only specified once and that the API
returns the right packages when we allow different distros.
2019-11-18 12:22:10 +01:00
Lars Karlitski
919d849123 weldr: use repo ids as source names
The naming is confusing: repositories have an `id` and a human readable
`name`. Weldr's sources also have a field called `name`, but
lorax-composer uses that as a way to identify repositories by their id.

Use `id` consistently here as well.
2019-11-18 12:22:10 +01:00
Jacob Kozol
e72004de56 api/tests: fix blueprints freeze test
The blueprints freeze test now creates the blueprint with the package
dep-package1 which is mocked and will properly depsolve when the
blueprint is frozen. This test can no longer run externally against
lorax-composer.
2019-11-15 15:24:39 +01:00
Jacob Kozol
6dbde1b5df api/tests: add blueprint freeze test
This test creates a new blueprint with libsemanage. Libsemanage is
already in the mock rpmmd so when we test the freeze route on this
blueprint, the blueprint will properly depsolve and return the package
with the depsolved version.
2019-11-15 00:25:18 +01:00
Ondřej Budai
dd9a815c40 api: improve parity of /{modules,projects}/{list,info} routes
These endpoint are similar in many ways, therefore just one commit. Their
functionality is basically same as in lorax except for error messages and
weird edge cases when handling trailing slashes.

closes #64, closes #65
2019-11-15 00:23:24 +01:00
Jacob Kozol
c882bebfb4 remove packages from weldr API initialization
The package list is generated on each request for a package so there is
no longer a need to generate the package list in main or to store these
packages in the API object.
2019-11-14 12:16:07 +01:00
Ondřej Budai
af73810a2d tests: fix failing tests due to a bad merge
I changed the API of weldr.New in 495f5b55 and Jacob added a new call of
that function in 9970150e, which created conflicting state.
2019-11-14 10:19:27 +01:00
Ondřej Budai
2cb7c8936e api/tests: test bodies for equality even if status codes are different
When developing tests it's nice to see all the differences at once.
2019-11-13 23:49:57 +01:00
Ondřej Budai
36ccb110b3 api: add support for /projects/depsolve 2019-11-13 14:54:02 +01:00
Ondřej Budai
495f5b558b Add support for mocking rpmmd
We want to test API methods which calls dnf. Unfortunately, calling dnf
is expensive operation - it requires network access and downloading
a lot of (meta)data. This commit changes the rpmmd implementation
so that it can be mocked.
2019-11-13 14:54:02 +01:00
Jacob Kozol
9970150ed5 api: add blueprints changes route
For each blueprint name passed to the route, a list of the changes to
that blueprint will be returned.

weldr/tests: add blueprint changes test

In order to test blueprint changes a blueprint must be created with a
unique id. Blueprint changes are not deleted when the blueprint is
deleted so in order to test this against lorax the blueprint must have
not been used/tested before. This id is created from a random int. The
test creates and deletes the same blueprint twice to check that each
creation updates the list of changes.
2019-11-13 14:51:06 +01:00
Jacob Kozol
3ae39e54c5 weldr/tests: add and update sources tests
Add tests for adding and deleting user defined sources. Update existing
tests for source info. The source being added is the fish repository.
This is the same source that the cockpit-composer tests attempt to add.
2019-11-06 21:40:31 +00:00
Jacob Kozol
2c2a20fdb7 weldr/tests: update tests to specify ignored fields
Compose tests ignore the id and timestamps and verify that the rest
of the response is as expected. The testRoute function now accepts
fields to ignore and uses dropFields to remove them from the test and
response objects.
2019-10-31 19:08:34 +01:00
Jacob Kozol
6515946369 weldr/tests: Add ability to ignore fields in the response
Certain fields (timestamps, uuids, etc.) are difficult to test for. The
dropFields function allows specific fields to be removed from an
unmarshalled json response body.
2019-10-31 19:08:34 +01:00
Tom Gundersen
fd33ea1cc7 weldr/tests: add first version of a compose/queue test
This can serve as a starting point, but it shows there are a few
problems to solve: we need to verify json that depends on the setup,
in particular, the json the queue contains will contain UUID's that
are generated out of our control.

Moreover, the setup for this test only makes sense for internal test,
so I think we may want to change the logic for whether or not a test
sholud be supported to be run externally to be per test-function,
rather than per call to sendHTTP().

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-10-25 10:18:47 +02:00
Tom Gundersen
26995d7a1d weldr/tests: refactor tests
This does not change the behavior, but refactors according to these principles:
1) No two routes are tested in the same function (but it would be ok to split
   tests for one route over several funcions)
2) At most one testRoute() call is made per API object, and the state is
   completely set up and tore down between tets.

On top of this we should add more test cases to each of the tables, but
I'm leaving this to future PRs.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-10-25 10:18:47 +02:00
Tom Gundersen
8c3cd245d8 weldr/test: split out sendHTTP helper method
This simplifies the code a bit, and will be used in follow-up patches
to distinguish between setup calls and explicit tests.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-10-25 10:18:47 +02:00
Jacob Kozol
72a54b9c0e tests: specify if each test runs against external API
Not all tests will be compatible with external APIs such as Lorax. When
calling testRoute each test now declares if it can run against an
external API or not. This change allows us to test against Lorax but
skip the cases that will be invalid when not run against
osbuild-composer's API.
2019-10-23 20:53:50 +02:00
Jacob Kozol
81d9fef76a api: update api error responses to equal lorax's
In order to maintain parity with lorax the api needs to reply with an
error message equivalent to that used by lorax. Error messages are now
returned inside an error object that contains an id, message, and
optional status code.

For some routes, there are errors when no url parameters are passed. The
httprouter was using named parameters of the form /:param which does not
match for empty parameters. Now, it has been updated to use the
catch-all parameters of the form /*param. This change allows the case of
no parameters. However, parameters will now include a "/" as
their first character. This needs to be removed from the string in the
route handler.

In order to provide the proper error message for
/modules/list/<modules>, searching for the modules needed to be updated.
The requested modules and known packages are iterated over and if there
is a match the module is added to the response. Also, the found module
is dropped from the list of requested modules. If this list is not empty
after searching all of the modules then an error is returned containing
the name of the non-existant module.
2019-10-23 01:08:03 +02:00
Jacob Kozol
d5830a4794 tests: delete blueprints after tests
At the end of each set of tests the blueprint created is deleted.
This tests the delete route as well as removing blueprints
created while testing external apis such as lorax.
2019-10-11 14:16:19 +02:00
Ondřej Budai
15b82a15d2 osbuild-composer: Rename module to github.com/osbuild/osbuild-composer
This should be the best practice according to other popular go projects:
- https://github.com/prometheus/prometheus
- https://github.com/syncthing/syncthing
- https://github.com/drone/drone
- https://github.com/hashicorp/terraform

Also, this change fixes go get command (it currently fails due to bad package
name).
2019-10-08 21:44:57 +02:00
Tom Gundersen
68ade23fcc store: make state (de)serialization internal
This hides the state hanlding in the store package. As before, it
can be disabled by passing `nil` instead of the path to the state
file.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-10-07 10:37:43 +02:00
Tom Gundersen
9cb140795e store: add {Push,Pop}Compose methods and hide channel
Wrap the channel in Pop and Push methods, so it is not exposed to
the callers. PushCompose replaces the old AddCompose for consistency,
and PopCompose simply reads from the other end of the channel.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-10-07 10:37:43 +02:00
Tom Gundersen
3ff4f59fc7 store: pass the store to the jobqueue API
Drop the jobUpdates channel, and instead add an UpdateCompose method
to the store, which updates the status of a compose directly.

This allows us to report back errors directly, rather than having to
mirror the staet in the jobqueue API.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-10-07 10:37:43 +02:00
Tom Gundersen
89fd2e6037 store: move creation to main.go
Let the weldr API take the store as an argument, rather than create it
itself. This will allow us to share the store with the jobqueue API in
follow-up patches.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-10-07 10:37:43 +02:00
Jacob Kozol
cefea2d387 test: run api tests against lorax
osbuild-composer's tests can be run against lorax-composer's api in
order to ensure parity with lorax. This can be accomplished by passing
the environment variable LORAX=true into the tests. Otherwise, the
tests run as usual against osbuild-composer's api.
2019-10-04 22:17:44 +02:00
Jacob Kozol
d23d57bc31 Update api and store for parity with lorax
Add parameters to the api responses that while not displayed by
cockpit-composer are used in props validation or blueprint updates.
2019-10-02 15:25:02 +02:00