Commit graph

2874 commits

Author SHA1 Message Date
Lars Karlitski
740e4da733 rpmmd: move SourceToRepo to store
This removes the `store` dependency from `rpmmd`, which is the more
generic package.

It's also nicer to have this on a method of `SourceConfig`.
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
Jacob Kozol
c4088caee1 api: add blueprint freeze route
The blueprint freeze route returns the blueprint info but each
package will be the package selected by depsolving. So, instead of the
version being the version number with optional wildcards as
/blueprints/info would provide, the version is of the form
`Version-Release.Arch`.
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
Ondřej Budai
2ed070b218 api: remove packages from api struct
This was probably forgotten in c882bebf
2019-11-15 00:23:24 +01:00
Jacob Kozol
5ffcb3fe6d api: add undo blueprint route
Add a route to set a blueprint back to its state at a particular change.
The route `blueprints/undo/:blueprint/:commit` requires the blueprint
name and the commit hash for the change that the blueprint should be
reverted too. Also, the commit message for the change created when a
blueprint is pushed is now passed from the api to the store's
PushBlueprint funtion.
2019-11-14 20:36:17 +01:00
Jacob Kozol
1b46a83522 store: add getBlueprintChange update blueprint commit message
Add function to get a single blueprint change given the blueprint name
and the commit hash. Update the PushBlueprint function to allow a commit
message to be passed to it which will be used when adding a change.
2019-11-14 20:36:17 +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
Jacob Kozol
6f4a7bacd2 api: fetch packages from sources and base repo
The package list is now generated from the base repo and the
user-defined repos. This allows users to add packages not found in the
base repo to their blueprints.
2019-11-14 12:16:07 +01:00
Jacob Kozol
085ba6fec9 rpmmd: convert sources to repos
Add function to convert between a user source and a repo which can be
passed to dnf-json. This is neccessary because user-defined sources have
a slightly different format than dnf repos.
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
Martin Sehnoutka
1fac27527b add more local boot test cases
1) additional qemu tests for ami, vmdk, vhd, and openstack image types
2) new type of systemd-nspawn tests for tar, ext4, and parititioned disk
types

the systemd-nspawn tests use loopback network interface directly from
the host so it is necessary to tweak the settings of its SSH server.
This is done in a "script" stage using simple "sed" command.
2019-11-13 21:06:49 +01:00
Ondřej Budai
36ccb110b3 api: add support for /projects/depsolve 2019-11-13 14:54:02 +01:00
Ondřej Budai
9076f68f7b rpmmd: Add error reporting support to dnf-json
Previously dnf-json hasn't been able to report any reports. This commit
tries to fix it with introduction of somewhat flexible error format.
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
080bd4968c store: add function to get blueprint changes
For a given blueprint name the store returns a list of the changes made
to that blueprint.
2019-11-13 14:51:06 +01:00
Jacob Kozol
7d2650a2e3 store: add blueprint changes
When a blueprint is pushed to the store it will also add a change to the
BlueprintChanges map. Each blueprint has a list of changes mapped to
their commit. This commmit is a hex string based off of the sha1 hash of
the current time so every commit is unique. The message and timestamp
follow the format of lorax-composer.
2019-11-13 14:51:06 +01:00
Jacob Kozol
5fe42f13d7 blueprint: add change object for blueprints
Add a struct to store changes made to a blueprint. Each change contains
a commit which is a hex string based off of an sha1 hash, a message
describing the change, a revision which will usually be null, a
timestamp, and the blueprint at the time of the change.
2019-11-13 14:51:06 +01:00
Jacob Kozol
11eb0b5226 rpmmd: sort fetched package list
When dnf-json dumps the packages from the repos passed to it, it does
not sort the packages. In order to properly list and search the
packages, the package list is now sorted before being returned by the
FetchPackageList function.
2019-11-13 14:24:58 +01:00
Lars Karlitski
41a2ef9b9a Revert "rpmmd: make dnf-json executable"
This is not really necessary right now. I needed it for testing rpmmd,
which we've postponed.

This reverts commit d05673afb1.
2019-11-13 00:36:50 +01:00
Lars Karlitski
d05673afb1 rpmmd: make dnf-json executable
This enables us to put it anywhere in `PATH`, because we don't call it
through `python3` anymore.
2019-11-11 18:30:44 +01:00
Martin Sehnoutka
77c2ab0e1c Introduce local boot test case for QCOW2
The tests works by executing osbuild with predefined pipeline. Then the
image boots and the testing script creates SSH connection to the running
VM. If everything goes fine `systemctl is-system-running` is executed
with result `running` and the test case passed.

The JSON definition of the test case contains also a blueprint that
should generate the desired pipeline, but it didn't work for me, so I'm
including it for future use from the golang unit tests.
2019-11-11 15:47:01 +01:00
Jacob Kozol
3aab64575b api: fix delete source route
The delete source handler now removes the leading "/" from the
parameters passed to it. Not removing the "/" caused sources to not
be deleted from the store since they could not be found when their name
contained a "/" as the first character.
2019-11-11 15:44:42 +01:00
Lars Karlitski
a91b5640de jobqueue: fail test if PushCompose returns an error 2019-11-10 17:23:14 +01:00
Lars Karlitski
f9cbc8593f distro: add DetectHost
lorax-composer uses the host's repositories for building images. This is
prone to accidental configuration errors and duplicates functionality
(adding custom repositories via the source API is much more explicit).

However, blueprints don't specify the distribution they're based on.
This is something they should do in the future to enable cross-distro
image builds. Until then, read `/etc/os-release` to detect the host OS
and use that as the base distro for a blueprint.

Detection works by concatenating the ID field with a `-` and the
VERSION_ID field. This mandates how additional distributions should
register themselves to the `distro` package.

If composer cannot build the detected distro, fall back to fedora-30.

Use this detection everywhere that fedora-30 was hard-coded before.
2019-11-10 17:23:14 +01:00
Lars Karlitski
b33ed9e5d2 blueprint: move pipeline generation into its own package
Introduce the `distro` package, which contains an interface for OS
implementations. Its main purpose is to convert a blueprint to a
distro-specific pipeline.

Also introduce the `distro/fedora30` package. It is the first
implementation of the distro interface. Most of its code has been copied
with minimal modifications from the blueprint package.

The `blueprint` package is now back to serving a single purpose:
representing a weldr blueprint. It does not depend on the `pipeline`
package anymore.

Change osbuild-composer and osbuild-pipeline to use the new API,
hard-coding "fedora-30". This looks a bit weird now, but is the same
behavior as before.

All test cases now also take an "distro" key in the "compose" object.
2019-11-07 17:13:20 +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
a1d2f77ff1 api: add support for user defined sources
The api now supports user defined sources alongside the existing base
repository. The routes /projects/source/new and
/projects/source/delete/<name> have been added.
/projects/source/info/<names> and /projects/source/list have been
updated.

The SourceConfig type is now called from the store instead of being
declared in the api.
2019-11-06 21:40:31 +00:00
Jacob Kozol
29ebb9ff51 store: add sources to store
The api is initialized with a base repo but users may want to add their
own custom repos. Based on lorax's implementation, the store now
supports sources. The source object is similar to but not the same as
the repos used by dnf. The store can now add, delete, and get info about
sources.
2019-11-06 21:40:31 +00:00
Lars Karlitski
c3e029ae82 dnf-json: don't hard-code Fedora 30
Make each command accept a `repos` key containing repository
descriptions.

Make weldr API pass the repository like this. Nothing should change,
because the repos were the same (Fedora 30).
2019-11-04 00:17:25 +01:00
Lars Karlitski
cae1fdd04d dnf-json: read arguments as JSON from stdin
This allows us to have more expressive input arguments.
2019-11-04 00:17:25 +01:00
Ondřej Budai
0feb4e4d44 api: improve error handling when compose push fails
There was missing condition for the case when compose push fails.
As the previous commit introduces customizations which can return even more
errors it is important to report such errors.

For now the API is returning only 500 HTTP code. In future we should
distinguish between failures and blueprint validation errors.
2019-11-02 14:10:13 +01:00
Ondřej Budai
913dc8d6c9 blueprint: integrate customizations with all output types
Customizations are ready to be used, this commit enables them. There are still
some unresolved TODOs to be solved in future. Also, tests are missing.
2019-11-02 14:10:13 +01:00
Ondřej Budai
4b546f1bbf blueprint: don't create group with the same as one of the users 2019-10-31 21:51:02 +01:00
Ondřej Budai
dc359fca3a blueprint: add support for extra packages, "modules" and groups
"modules" because they're not actual modules. Currently, it's just
a synonym to packages. This is the same behavior as lorax-composer has.
2019-10-31 21:49:09 +01:00
Ondřej Budai
93e7a26785 blueprint: fix groups definition
Group has no version field, remove it.
2019-10-31 21:49:09 +01:00
Ondřej Budai
705338c5b3 blueprint: add support for unencrypted passwords in user customization 2019-10-31 21:46:39 +01:00
Ondřej Budai
189b2b4547 crypt: fix gcc warning
Newer gcc doesn't really like strncpy producing following warnings:
warning: ‘strncpy’ specified bound depends on the length of the source argument

I switched the function to the plain old strcpy as strncpy is not necessary anyway
because we allocate the destination buffer using size returned from strlen.
2019-10-31 21:46:39 +01:00
Ondřej Budai
5b0c2cac9f Import crypt library
Copied from b3e2912865/crypt_r.go

Original sources are under MIT license
2019-10-31 21:46:39 +01: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
Lars Karlitski
e7ae3b4c47 test: move image-info tests to test/
These tests (will) test more than just image-info: they'll take a
blueprint, verify that `osbuild-pipeline` generates the correct
pipeline, run osbuild with that pipeline and verify that the resulting
image has the expected image-info output.

This change only includes the latter half (i.e., only moves the already
existing tests).

Also drop python's unittest. It was hard to control output (important
for quickly spotting failures and to make travis happy). This introduces
test/run, which runs all test cases in test/cases or the ones given on
the command line.

When a failure occurs, it prints a diff of the actual and the expected
image info.
2019-10-30 01:25:44 +01:00
Tom Gundersen
aa404dcb99 worker: move Job type to the jobqueue package
The main purpose of this is to share the structs between the server
and the client, and let the compiler ensure that our marshaling and
unmarshaling matches.

In the future we also want to make it easier to write unittests for
this code.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-10-29 16:08:54 +01:00
Lars Karlitski
fabd40da1c blueprint: always run selinux stage last
A few output types had it before the fix-bls stage.
2019-10-29 16:01:37 +01:00
Lars Karlitski
6a6144c2d9 blueprint: always exclude the rescue kernel
Its BLS entry always expects a separate boot partition. Skip it on all
images until the rescue kernel package is usable.
2019-10-29 16:01:37 +01:00
Lars Karlitski
930347c56e blueprint: move vmdk towards lorax parity
The main difference (according to image-info) is an additional package
containing a gpg key which was used to verify packages. The one
generated by lorax-composer doesn't have this, because it doesn't verify
signatures.

Also, lorax generates an image with a separate /boot partition. This is
not yet addressed here, because osbuild doesn't support it yet.
2019-10-29 16:01:37 +01:00
Lars Karlitski
cde1325bc3 blueprint: move tar towards lorax parity
The main difference (according to `rpm -qa`) is an additional package
containing a gpg key which was used to verify packages. The one
generated by lorax-composer doesn't have this, because it doesn't verify
signatures.
2019-10-29 16:01:37 +01:00