Commit graph

42 commits

Author SHA1 Message Date
Brian C. Lane
7ca9579487 client: Add an integration test for a bad blueprint depsolve
This test makes sure that a bad /blueprints/depsolve/... will return a
list of blueprints and a list of errors, not just a single error 400
response.
2020-07-28 08:18:56 +02:00
Ondřej Budai
fa0d800850 test: add a test-case to prevent bad multilib depsolves
When gsl with version * was specified in the blueprint,
composer depsolved both x86_64 and i686 version of gsl.
This test case should prevent this from happening.
gsl is used because it has x86_64 and i686 versions on both RHEL and Fedora.
Also, gsl-devel package exists, which is not dependant on gsl and shouldn't
be depsolved.
2020-06-10 17:40:30 +02:00
Brian C. Lane
e37b513560 weldr: Add check for deleting system sources
It was passing it through to the non-system delete function
and not returning an error. This checks for system repos first and
returns a 400, SystemSource error response if it is in the system list.
2020-06-03 21:24:47 +02:00
Brian C. Lane
37258803b4 weldr: Add support for the v1 API to /projects/source/delete
This changes store.DeleteSource to DeleteSourceByName for v0 use and
DeleteSourceByID for v1 usage.

It includes a new client function DeleteSourceV1, adds a new test, and
converts the tests for the previous Source V1 API commits to use
DeleteSourceV1.
2020-06-03 21:24:47 +02:00
Brian C. Lane
982d292a96 weldr: Update projects/source/info to support API v1
This commit changes the store.GetAllSources to distinguish between
getting the source by the Name field, or by the ID (the key to the map)
using GetAllSourcesByName and ...ByID.

SourceConfig.RepoConfig() now takes an id parameter because SourceConfig
only stores the Name, not the ID.

In weldr I split the sourceInfoHandler into 2 separate functions for v0
and v1 behavior, with the core of the old function refactored as
getSourceConfigs and used by both of them.

This also adds new structs for the SourceResponseV0 and SourceResponseV1
as well as helper functions for converting to/from store.SourceConfig
2020-06-03 21:24:47 +02:00
Brian C. Lane
ddd2010815 weldr: Add support for the v1 API to /projects/source/new
This commit changes the store.PushSource function to take the key as
well as the SourceConfig so that it can be used for v0 or v1.

It adds helper functions for decoding the toml/json into a new
SourceConfig interface type which lets the core source/new code be
shared between the versions.

It also adds tests for the new API behavior.
2020-06-03 21:24:47 +02:00
Brian C. Lane
55325a8549 weldr: Add API v1 support to source listing
This is the first patch in a series to add APIv1 support to the
/projects/source routes. The change involves using the store.Sources key
in a different way (as an id instead of as a duplicate of the struct's
Name field) but does not actually involve changing the Sources json in
the store.

In the V0 API the name of the source was used as the identifier, and
there was no short id. In V1 the source is identified by the API using
a short id, and the Name is just a field in the struct to describe the
source. This will become more obvious with the /projects/source/info
response.

This commit changes the following:

Changes store.ListSources to ListSourcesByName and explicitly pulls the
name from the source struct instead of the key. v0 will use this
function call.

Adds store.ListSourcesById which returns the source key as the
identifier. This is used by v1.

Adds a new weldr.SourcesListV1 response type, even though it is exactly
the same as the V1 response in this specific case. I thought it would be
better to have one called V1 than to reuse the V0 struct and possibly
confuse people.

The /projects/source/list API now lists the sources by name for v0 and id for v1.

A test has been added. You will notice it still uses v0 to push and
delete the sources. These will be updated when the new version of the
functions are added in subsequent commits.
2020-06-03 21:24:47 +02:00
Brian C. Lane
508e7b40f7 tests: lorax-composer returns 2 errors for these tests
TestComposeEmptyBlueprintV0
TestComposeInvalidCharsBlueprintV0
2020-05-28 08:28:11 +02:00
Brian C. Lane
c000a409a3 tests: Add missing descriptions to test blueprints
These were causing the wrong error when running against lorax-composer.
2020-05-28 08:28:11 +02:00
Brian C. Lane
49ca489efa client: Add functions to handle Metadata and Results requests
Includes basic tests to check for errors, but not content.
2020-05-28 00:39:10 +02:00
Tom Gundersen
48079b3a4d rpmmd/RepoConf: rename Id to Name
This is how it is used in the rest of the code, as a name to represent
the repository in the weldr API. Rename to match its use, and avoid
confusion with the ID passed to dnf-json, which is not the same.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-05-28 00:23:54 +02:00
Lars Karlitski
e06076ed8c worker: add JobArtifact() and DeleteJobArtifacts()
This allows removing the `artifactsDir` from `weldr.API`. It makes more
sense to deal with that directory in one place only.
2020-05-27 16:16:05 +02:00
Lars Karlitski
a1cf3984dc worker: introduce job artifact directory
The `jobs/:job_id/builds/:build_id/image` route was awkward: the
`:jobid` was actually weldr's compose id and `:build_id` was always `0`.

Change it to `jobs/:job_id/artifacts/:name`, where `:job_id` is now a
job id, and `:name` is the name of the artifact to upload. In the
future, it could support uploading more than one artifact.

This allows removing outputs from `store`, which is now back to being a
pure JSON-store. Take care that `weldr` returns (and deletes) images
from the new (or for backwards compatibility, the old) location.

The `org.osbuild.local` target continues to exist as a marker for the
worker to know whether it should upload artifacts.
2020-05-26 10:42:20 +02:00
Brian C. Lane
369312989f blueprints: Fix handling of invalid blueprint names in the API code
Empty names are not allowed, and blueprint names should only contain
characters matching: ^[a-zA-Z0-9._-]+$

This also adds tests for the various places where the blueprint name
could potentially be wrong.
2020-05-13 20:00:52 +02:00
Brian C. Lane
56ae3d33c8 client: urlencode compose status filter parameters 2020-05-13 20:00:52 +02:00
Lars Karlitski
2ecdee6814 client: drop client timeout in tests
A timeout doesn't make sense on this level, because it is very difficult
to estimate how long downloading rpm metadata takes. Drop it completely
in favor of higher-level timeouts in the test runner.

Fixes #601
2020-05-12 22:38:10 +02:00
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
Alexander Todorov
7ce08bc788 tests: Make sure TestMain cleans up after itself
os.Exit() doesn't execute defer-ed functions, OTOH we call panic()
in case of setup errors, which does run defer-ed functions. So move
the actual test setup and execution in a separate function which will
execute all defer-ed functions and return the exit code from the
test suite to TestMain.
2020-04-27 11:53:45 +02:00
Alexander Todorov
cd1e6d3aaf tests: replace cmd.Diff() with require functions 2020-04-20 14:00:49 +02:00
Alexander Todorov
fb7373aa62 tests: Use the require package 2020-04-20 14:00:49 +02:00
Brian C. Lane
f960985c17 client: Add functions to support compose testing
Also adds new types to weldr/json.go to support them.
ComposeEntry had to be duplicated instead of used as-is because it
enforces image type strings that do not match what the API uses (the API
types are all lower case, the internal names are capitalized).
2020-04-15 11:35:05 +02:00
Brian C. Lane
7c86dc533c client: Add GetRawBody function to return the io.ReadCloser from the request
And refactor GetRaw to use it.
2020-04-15 11:35:05 +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
fc205786fc weldr: Return a JSON API error response for all unknown requests
This matches the lorax-composer behavior.
2020-03-27 19:07:33 +01:00
Brian C. Lane
e3934108f7 client: Handle the differences between unit tests and integration tests
The mock server used by unit tests is slightly different than the
running server, mostly related to package names that are hard-coded.

This adds a bool to testState that can be used in the tests to alter the
expected behavior. It should be used as little as possible.
2020-03-27 19:07:33 +01:00
Brian C. Lane
856eb59edf client: Move the weldrcheck integration tests to client
With this change the integration tests can now also be run as unit tests
against the mocked server. The way it works is this:

internal/client/unit_test.go sets up the mock server and is built
when the `integration` build tag is *not* included.

internal/client/integration_test.go sets up the connection to an
existing server and is built when the `integration` build tag *is*
included.

The test code is built and run for both cases.

Currently they all pass for the integration test run. The unit test
cases need some work because the mocked server isn't a real server with
real depsolving and package lists. A future commit will fix this.
2020-03-27 19:07:33 +01:00
Brian C. Lane
816a09fd9d client: Add integration test setup code 2020-03-27 19:07:33 +01:00
Brian C. Lane
b5b5bd96df client: Move test setup into unit_test.go
Copy weldrcheck's utils.go into client, switch to using TestState struct
to hold global test data. Only build unit_test.go if integration has not
been selected.

This is in preparation to moving weldrcheck code into client *_test.go
files so that the test code can be shared and run against a mock server
during unit testing, or against a running WELDR API server during
integration testing.
2020-03-27 19:07:33 +01:00
Brian C. Lane
b5da15e2d8 client: Add /modules/ support 2020-03-25 10:01:14 +01:00
Brian C. Lane
271d27a41d client: Add /projects/ support 2020-03-25 10:01:14 +01:00
Brian C. Lane
3005486cb4 client: Add projects/source API support 2020-03-23 21:08:01 +01:00
Brian C. Lane
971bafbc09 Move the API struct definitions into internal/weldr
This will prevent problems with import loops. client already imports
weldr, so weldr cannot import client.
2020-03-23 21:08:01 +01:00
Tom Gundersen
f201fc84b7 weldr: pin a real Arch object, rather than a string
weldr needs to know the host architecture. Rather than pinning
a string, pin a real Arch object, and query its name when we
need it.

This verifies the validitiy of the architecture for the given
distro before it is passed to weldr, rather than lazily on
demand.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-03-23 15:43:55 +01:00
Lars Karlitski
77556973cc distro: don't expose repositories in distro objects
Mixing the way to build a distribution with where to get the source
packages from is wrong: it breaks pre-release repos, local mirrors, and
other use cases. To accommodate those, we introduced
`/etc/osbuild-composer/repositories`.

However, that doesn't work for the RCM API, which receives repository
URLs to use from outside requests. This API has been wrongly using the
`additionalRepos` parameter to inject those repos. That's broken,
because the resulting manifests contained both the installed repos and
the repos from the request.

To fix this, stop exposing repositories from the distros, but require
passing them on every call to `Manifest()`. This makes `additionalRepos`
redundant.

Fixes #341
2020-03-18 20:46:28 +01:00
Brian C. Lane
46c3bed153 client: Use http.Client instead of a string for the socket
This converts the client and weldrcheck functions to use http.Client for
connections instead of passing around the socket path and opening it for
each test.
2020-03-09 18:02:54 +01:00
Ondřej Budai
284e9b9e53 fix linter errors
#261 was created before the introduction of the linter, therefore it wasn't
approved by it. This commit fixes all the introduced linter violations.
2020-03-03 14:26:13 +01:00
Brian C. Lane
9dafb3337b Refactor error handling in the client code
client errors are now returned as an 'error', API errors as APIResponse.
2020-03-03 12:21:40 +01:00
Brian C. Lane
ea1b633d3a Add exported response structures for API results
Currently the responses are all embedded in the weldr API functions.
They need to be usable by the client helper functions so I'm copying
them here and giving them names.

A later commit will go through the API can refactor it to use these
instead of the embedded ones.
2020-03-03 12:21:40 +01:00
Brian C. Lane
f0ddb3d866 client: Add tests for the core client functions 2020-03-03 12:21:40 +01:00
Brian C. Lane
cfa4233db5 client: Add client helper functions for API testing and future cli tools
This package will contain functions for communicating with the API that
can be used in both the integration tests as well as in a future cmdline
tool similar to composer-cli

When possible the client functions will return the same structures used
by weldr/api.go which have been exported in weldr/json.go
2020-03-03 12:21:40 +01:00