Commit graph

138 commits

Author SHA1 Message Date
Tom Gundersen
a385d91565 osbuild-pipeline: print more helpful info in case invalid input is given
Use the List*() functions to print the valid options in case an invalid
one is given.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-03-24 15:46:57 +01:00
Alexander Todorov
5a0ccd55db tests: Add sanity tests for sources. Refs #315, #356 2020-03-23 21:10:46 +01:00
Brian C. Lane
3af34fba3f test: Move temporary repo setup into test/helpers.go
This allows it to be shared between the dnf-json tests and weldrcheck.
2020-03-23 21:08:01 +01:00
Tom Gundersen
1ceb504738 osbuild-pipeline: resolve argumnets to Arch and ImageType objects
This gives us verification at the point of use for free and simplifies
the code a bit.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-03-23 15:43:55 +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
Tom Gundersen
ff0ec01eb6 distro: drop NewDefaultRegistry()
Require the caller to pass in the required distros explicitly. This
would allow us to easily add distros in osbuild-pipeline and tests
before exposing them in composer itself, for instance.

This means there is no longer a dependency from the distro package
to each of the individual distros, so the distros are now able
to depend on the distro packag for types and interfaces.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-03-23 15:43:55 +01:00
Tom Gundersen
1345ca77fd store: drop the distro registry
This was now unused.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-03-22 22:26:09 +01:00
Lars Karlitski
1bb8f7eee0 osbuild-image-tests: add missing build constraints
Build constraints must be added to every file. We only want to build
this package when the `integration` tag is set.

Without this, every build prints this warning:

    # github.com/osbuild/osbuild-composer/cmd/osbuild-image-tests
    runtime.main_main·f: function main is undeclared in the main package
2020-03-22 13:50:28 +01:00
Ondřej Budai
7c1de17300 tests/image: use %#v when printing errors
When using %#v instead of %v, printing an error gives a slightly more
informative error message, therefore this commit switches to %#v in all
error prints.
2020-03-19 14:25:08 +01:00
Ondřej Budai
1b49755a7e tests/image: remove all distro restrictions
The distro argument and restrictions to run only tests for the same distro
as the host's one were confusing. This commit removes them. Now the behaviour
is following:

By default all the test cases in test case directory are run.
If test cases are given by arguments, they are all run, and test case
directory is ignored.
2020-03-19 14:25:08 +01:00
Ondřej Budai
832fb44eb8 tests/image: give the test VM only 1 GB of memory
The VM doesn't need 2 GBs to start Fedora and ssh server. This fix enables
us to run the tests in more constrained environment.
2020-03-19 14:25:08 +01:00
Ondřej Budai
3cb2a5f930 tests/image: remove the hack for fedora-30
Previously we had only tests for Fedora 30, therefore I added a hack to treat
every Fedora as Fedora 30, so the tests would run. Now, we have tests for
multiple Fedora versions, therefore the hack is no longer needed.
2020-03-19 14:25:08 +01:00
Ondřej Budai
acfb461aa5 tests/image: switch the implementation to go testing framework
We're currently rewriting all the integration tests to use the Go
testing framework. This commit does the switch for the image tests.

I decided not to use the testing framework in functions which are
not directly tight to testing (booting images, running osbuild). I think
it's reasonable to use classic error handling there and propagate the errors
to places directly tight to testing and use the testing library.
This enables us to reuse the code in different part of projects if needed.
2020-03-19 14:25:08 +01:00
Jiri Kortus
48027293cb Use testing module syntax and asserts in osbuild-tests
Fixes #312
2020-03-19 13:22:14 +02: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
Jakub Rusz
31a3cc6455 tests: rewrite rcm-tests to use go test framework
Fixes #311
2020-03-18 16:23:43 +01:00
Lars Karlitski
0f1a014aca store: don't keep a "default" distro
Only the weldr API has the concept of a default distro. Pass that distro
explicitly to `PushCompose()` and fetch the distro from the compose in
all other functions that accessed Store.Distro.
2020-03-18 08:33:42 +01:00
Lars Karlitski
c2c8fae093 store: give ComposeRequest a real distro
`ComposeRequest` included a `common.Distribution`, which had to be
resolved in PushComposeRequest. Use a real `distro.Distro` object here,
and push resolving it to the rcm package.

Change the `Distribution` on the (lower-case) `composeRequest` to a
string. This struct represents the incoming request. Since we're now
resolving the real distro object from the registry in the same function,
it seems redundant to validate the incoming distro twice.
2020-03-18 08:33:42 +01:00
Brian C. Lane
548c58ddda weldrcheck: Convert to go testing framework + testify/require
Convert weldrcheck to use the standard go testing framework along with
the github.com/stretchr/testify/require assert package.

This also removes the cmd/osbuild-weldr-tests and builds the test binary
directly from the weldrcheck package. This makes it easier to organize
the code instead of putting it all into a single main_test.go file.
2020-03-17 21:10:00 +01:00
Ondřej Budai
15e905b4d2 tests/image: add option to filter test cases by distro
By default, image test executable runs only test cases for the same distro
as the host's one. On Travis there's Ubuntu, so we need to adjust the
behaviour and run the cases for a distro specified by command line
arguments.
2020-03-16 21:10:57 +01:00
Ondřej Budai
dc9c82fd96 tests/image: add path constants for Travis CI
The new set of constants allows to run the tests on Travis. The tests must
be build by:

go build -tags travis ./cmd/osbuild-image-tests
2020-03-16 21:10:57 +01:00
Ondřej Budai
03ae0007af tests/image: extract constants containing paths
We need to use different values for path constants when running the tests
on the Travis CI. This is the first step to achieve this.

Note that this commit may be reverted when Travis CI is dropped.
2020-03-16 21:10:57 +01:00
Ondřej Budai
d4ecebd38a tests/image: rename the main source file
To be consistent with other binaries.
2020-03-16 21:10:57 +01:00
Martin Sehnoutka
9f4042af6c osbuild-composer: don't use hardcoded state directory
Use $STATE_DIRECTORY environment variable which is set by systemd
because we use: StateDirectory=osbuild-composer in the service unit.

also change systemd unit to include STATE_DIRECTORY, because
RHEL comes with older systemd version, so we need to set this variable explicitly.
2020-03-16 21:05:39 +01:00
Tom Gundersen
7957feff48 distro.Manifest: take Customizations rather than Blueprint as argument
This makes two changes simultaneously, to avoid too much churn:
 - move accessors from being on the blueprint struct to the
   customizations struct, and
 - pass the customizations struct rather than the whole blueprint
   as argumnet to distro.Manifest().

@larskarlitski pointed out in a previous review that it feels
redundant to pass the whole blueprint as well as the list of
packages to the Manifest funciton. Indeed it is, so this
simplifies things a bit.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-03-15 23:48:42 +01:00
Tom Gundersen
5d179428be rpmmd: drop the Name attribute from RepoConfig
This was never actually used anywhere, as passing it to dnf-json
was a noop.

We may want to reconsider the concept of a source/repo name and
how it differs from an ID, but for now drop the name.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-03-15 23:48:42 +01:00
Tom Gundersen
8400b39577 distro.Manifest: drop checksums parameter
This is no longer used to generate pipelines, but has been replaced
by the package specs.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-03-15 19:38:59 +01:00
Tom Gundersen
819430e659 rpmmd: no longer flush the caches on every call
When we used the dnf-based pipelines, we were relying on the fact
that the metadata was unlikely to have changed between we generated
the pipeline and called osbuild. We achieved this by always updating
to the most recent metadata on every call to rpmmd.Depsolve that
would end up in a pipelin.

Refreshing the metadata is time-consuming, and something we want
to avoid if at all possible. Now that our pipelines no longer
rely on this property, we can drop the flushing.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-03-15 19:38:59 +01:00
Ondřej Budai
b4a7bc6467 tests/image: add booting tests
This commit makes the osbuild-image-tests binary doing the same set of tests
like the old test/run script.

Changes from test/run:
- qemu/nspawn are now killed gracefully. Firstly, SIGTERM is sent.
  If the process doesn't exit till the timeout, SIGKILL is sent.
  I changed this because nspawn leaves some artifacts behind when killed
  by SIGKILL.
- the unsharing of network namespace now works differently because of
  systemd issue #15079
2020-03-13 18:06:56 +01:00
Ondřej Budai
f060c8d795 tests/image: fix testcase struct
The field compose was renamed in caca553, therefore also the image tests got
broken. This commit fixes it.
2020-03-13 18:06:56 +01:00
Tom Gundersen
333a1f3500 osbuild-pipeline: read the blueprint from stdin
Make the bluprint parameter a bool, and if set, then read a
blueprint from stdin, otherwise an empty blueprint is used.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-03-13 15:00:24 +01:00
Tom Gundersen
40040f2cc8 osbuild-pipeline: make blueprint optional
If no blueprint is provided, consider that the same as the empty
blueprint.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-03-13 15:00:24 +01:00
Alexander Todorov
b81580081b Use asserts in tests. Refs #309 2020-03-13 14:01:18 +01:00
Lars Karlitski
efb2975e36 tree-wide: run go fmt 2020-03-10 23:38:03 +01:00
Alexander Todorov
bd46389059 tests: use go's test framework in osbuild-dnf-json-tests
This allows us to take advantage of the `testing` package. It also gives
the resulting test binary common command line arguments (same as `go
test`).

Tests need to be compiled with `go test -c`, which injects a `Main()`
that calls the Test* functions.

This is not supported by the golang rpm macros. Thus, build this binary
by calling `go test -c` directly, but taking care to pass the same
linker flags as the `%gobuild` macro.

Mark the test binary with the `integration` build constraint, so that
`go test ./...` doesn't pick them up. That's only for unit tests.

The idea is to move all other test binaries to this scheme as well.

Spec file changes by Lars Karlitski <lars@karlitski.net>
2020-03-10 20:29:19 +01:00
Jacob Kozol
2ce40e179a osbuild-pipeline: add rpmmd flag and output
A developer may want to use the output of rpmmd (build package specs,
package specs, and checksums) instead of the pipeline manifest. In this
case they may pass the -rpmmd flag to osbuild-pipeline. With this flag,
instead of returning the pipeline, it will return the output of rpmmd.
2020-03-10 17:26:37 +01:00
Martin Sehnoutka
245e6ad6e7 rcm tests: document the test cases
The purpose of this documentation is to describe how the user is
expected to work with the RCM API. It can also serve as an example for
creating automation scripts if the RCM teams wants to create some.
2020-03-09 18:08:43 +01:00
Martin Sehnoutka
3b3d22d91e rcm tests: add get status test
This is a very basic test to get the status of a single compose. It will
evolve as the API gains support for Koji builds.
2020-03-09 18:08:43 +01:00
Martin Sehnoutka
0f48220225 rcm tests: read the response to a variable
This will be needed for following tests.
2020-03-09 18:08:43 +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
Alexander Todorov
2778efed6f Download AMI image inside integration tests
only build and download AMI image type here b/c building the rest
of the output types is tested separately elsewhere
2020-03-09 13:25:09 +01:00
Alexander Todorov
8117344307 Fix typo in log message 2020-03-09 13:25:09 +01:00
Martin Sehnoutka
885704db05 tests: introduce RCM API testing executable
It is an equivalent to what we already have for Weldr API but this one
is for the RCM API. It should test the expected use cases:
 * submit a compose
 * get a status
2020-03-09 09:37:11 +01:00
Tom Gundersen
fc47ae8c39 test/cases: test manifests rather than pipelines
A manifest is struct made up of a pipeline and a sources object. So
far all our sources objects are empty, but we have moved from
using pipelines to manifests everywhere, in preparation for
generating pipelines that require sources.

Make the same change in the test cases.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-03-08 21:05:01 +01:00
Lars Karlitski
3cff0a2578 osbuild-tests: test saving a blueprint
This is safe now that it is running each test in a temporary working
directory.
2020-03-08 17:04:47 +01:00
Lars Karlitski
22dee28885 osbuild-tests: run compose tests in a temporary directory
Some `composer-cli` commands operate on the current directory, for
example saving blueprints or images. Add the `TemporaryWorkDir` type,
which helps changing to a temporary working directory and cleaning
everything up after.

The alternative would have been to pass a working directory to all calls
of `runComposerCLI`, but that seemed like it would require a lot of
change, which I didn't deem worth for testing code.
2020-03-08 17:04:47 +01:00
Tom Gundersen
571932db37 job: pass manifest instead of pipeline to osbuild
This is not a behavioral change, as all distros currently use
empty source objects. But when we move over to rpm-based pipelines,
this will change.

Make the same change to osbuild-pipeline, so these stay in sync.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-03-03 22:25:49 +01:00
Brian C. Lane
b9eb01c9d3 Add osbuild-weldr-tests command 2020-03-03 18:30:21 +01:00
Lars Karlitski
17ca73ab14 osbuild-pipeline: validate distro when fetching it
We were verifying two things: if the passed distroArg exists in the
distribution mapping in common/types.go and if the it is an actually
registered distro. Since you cannot have distros registered that don't
correspond to a type, the first test is unnecessary.

Merge the two tests by moving the (much better) error message down into
the second test. This makes DistributionExists redundant, because
Registry.GetDistro() checks this implicitly.

Also, move ListDistributions() to the Registry object, because we want
to show distributions that are actually registered.

Add a test which checks that Registry.List() works and that all included
distributions register correctly.
2020-03-03 16:21:13 +01:00
Lars Karlitski
db95328ab6 osbuild-pipeline: remove stray comment 2020-03-03 16:21:13 +01:00