Commit graph

2934 commits

Author SHA1 Message Date
Brian C. Lane
5821098c29 cloudapi: Add tests for refactored handler code
Add tests for GetBlueprintWithCustomizations, GetPayloadRepositories,
GetSubscription, and GetOstreeOptions methods.
2023-08-05 11:28:29 +02:00
Brian C. Lane
6a1f12c465 cloudapi: Add a test for the new size option 2023-08-05 11:28:29 +02:00
Brian C. Lane
c1e52aebc3 cloudapi: Refactor handler.go code to make testing easier
This moves some of the code from the PostCompose function in handler.go
into methods on the OpenAPI ComposeRequest and ImageRequest structs.

In compose.go I have added several methods.
GetBlueprintWithCustomizations takes the ComposeRequest customizations
and builds a Blueprint struct.

GetPayloadRepositories returns the custom payload repos.

GetSubscription returns the ImageOptions setup with optional
subscription information from the request.

In imagerequest.go I have added GetTarget which takes the upload
options and returns a Target. This moves the giant switch statement,
which may also benefit from further simplification at some point.

GetOSTreeOptions returns the OSTree ImageOptions if there are ostree
settings in the ImageRequest.

GetImageOptions returns the distro.ImageOptions with the size set.

This commit only moves the code, making PostCompose easier to read. All
tests still pass.

cloudapi: Move the size handling to a method on ImageRequest
2023-08-05 11:28:29 +02:00
Brian C. Lane
818d434303 cloudapi: Add optional image size support
This adds a 'size' parameter to the image_request object. It can be used
to specify the minimum image size in bytes

This behaves in the same way as the size parameter of the weldr API

For raw images the root partition is grown to fill the available space.
For LVM images the PV uses the available space, but the LV does not,
leaving space available for other LVs to be created after boot.

See COMPOSER-1883
2023-08-05 11:28:29 +02:00
Ondřej Budai
cac9327b44 update to go 1.19
UBI and the oldest support Fedora (37) now all have go 1.19, so we are
cleared to switch.

gofmt now reformats comments in certain cases, so that explains the formatting
changes in this commit.
See https://go.dev/doc/go1.19#go-doc

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2023-07-21 19:18:00 +02:00
Diaa Sami
b6d6ecf874 cloudapi: add validation where missing 2023-07-21 12:52:32 +02:00
Diaa Sami
2bdfa045c1 cloudapi: fix typo in property name 2023-07-21 12:52:32 +02:00
Simon de Vlieger
326f0cfa2f cloudapi: add live-installer
This was missing to enable `live-installer` in the CloudAPI.
2023-07-20 18:53:28 +02:00
Sanne Raymaekers
4bbfdb624c cloudapi/v2: cleanup rebase leftovers
This is a review oversight from osbuild/osbuild-composer#3551, just
remove it.
2023-07-10 23:51:08 +02:00
Achilleas Koutsou
0e4a9e586f split: replace internal packages with images library
Remove all the internal package that are now in the
github.com/osbuild/images package and vendor it.

A new function in internal/blueprint/ converts from an osbuild-composer
blueprint to an images blueprint.  This is necessary for keeping the
blueprint implementation in both packages.  In the future, the images
package will change the blueprint (and most likely rename it) and it
will only be part of the osbuild-composer internals and interface.  The
Convert() function will be responsible for converting the blueprint into
the new configuration object.
2023-07-10 21:11:19 +02:00
Simon de Vlieger
e7557f6086 live-installer: enable aarch64 for fedora 2023-06-30 16:42:56 +02:00
Sanne Raymaekers
6040c10e10 worker/v1: rearrange middlewares
The duration middleware should come after the tenant channel middleware,
otherwise the tenant in the context will be empty. The status middleware
can come beforehand because it queries the request context right before
sending a response.
2023-06-29 16:41:36 +02:00
Sanne Raymaekers
f303e7c233 cloudapi/v2: rearrange middlewares
The duration middleware should come after the tenant channel middleware,
otherwise the tenant in the context will be empty. The status middleware
can come beforehand because it queries the request context right before
sending a response.
2023-06-29 16:41:36 +02:00
Gianluca Zuccarelli
fa6f3ba197 cloudapi: openscap integration
Enable the openscap customizations in the cloudapi.
2023-06-29 13:42:49 +01:00
Gianluca Zuccarelli
12e7b806b6 internal/distro: default oscap datastreams
Set fallback datastreams for openscap if no datastream is provided by
the user. This will also simplify the cloudapi experience by not
exposing the `datastream`
2023-06-29 13:42:49 +01:00
Gianluca Zuccarelli
c32fac7169 distro/rhel8: enable oscap for centos8
Remediations for centos 8 images were not previously enabled.
This commit enables running oscap remediations for centos 8.
2023-06-29 13:42:49 +01:00
Sanne Raymaekers
2837b2a3ad prometheus: split off request timing information into separate mw
Tracks the worker api in addition to the composer api.
2023-06-28 15:08:37 +02:00
Sanne Raymaekers
9594156baf internal/worker: use TenantChannelMiddleware 2023-06-28 15:08:37 +02:00
Sanne Raymaekers
06038b2af6 internal/prometheus: add tenant to http and status metrics 2023-06-28 15:08:37 +02:00
Sanne Raymaekers
0f946e1c9e internal/auth: add TenantChannelMiddleware
Extracts the tenant from the JWT and sets it in the request context.
2023-06-28 15:08:37 +02:00
Ondřej Budai
b5c9feeff9 distro/fedora: remove obsolete conditions for package set
osbuild-composer no longer supports Fedora 36, so we are safe to drop these
now.

iotCommitPackageSet would really benefit from sorting, but that would
create hard to handle conflicts with other PRs upstream, so I decided
not to do it in this commit.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2023-06-27 16:13:25 +02:00
Achilleas Koutsou
78931c0f05 test: update fedora repos
Update Fedora 37, 38, and 39 repositories for the test case generator.
Changes are only package versions and dependencies.

For Fedora 39, a package (lklug-fonts) had to be removed from the
Anaconda package set since it is no longer available.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2023-06-27 16:13:25 +02:00
Simon de Vlieger
46f93614f2 fedora: live-installer image type
This image type produces the same artifact as the current workstation
installer live media.

During the implementation of this new installer some names have been
changed to make a bit more sense in the source tree. Installer images
now always mention which installer they are (anaconda, etc).
2023-06-27 13:18:56 +02:00
Achilleas Koutsou
4f91e956aa osbuild: validate checksums for algo prefix
Make sure checksums used in the file input helper functions contain only
1 colon delimiter and it is not at the start of the string.

Adjusted tests to work with new restriction.
2023-06-27 08:57:06 +02:00
Achilleas Koutsou
464f91e35b osbuild: test NewRpmStageSourceFilesInputs
Unit test for the function where the original issue was located.

See rhbz#2215043.
2023-06-27 08:57:06 +02:00
Achilleas Koutsou
c6c0509780 osbuild: don't restrict checksum hashing algorithm
Helper functions that create stage input objects with references always
hard-coded `sha256:` as a prefix/algorithm for the checksum.  This
prevents the functions from being used in cases where other algorithms
are use, like sha1, which is possible with (perhaps older) RPM
repositories.  The inputs in osbuild a number of hashing algorithms and
we should be able to generate stages with other prefixes when necessary.

Remove the `sha256:` prefix in the helper functions and assume all
arguments to these functions provide the correct prefix.

Update tests to match.
2023-06-27 08:57:06 +02:00
Tomáš Hozza
789838682c distro/rhel8: fix Azure EAP7 RHUI image definition
PR#3421 [1] unintentionally removed the `rhui-azure-rhel8` package from
the Azure EAP7 RHUI image base package set. As a result, the image
manifest can't be built successfully. The reason is that the removed
package installs a RPM GPG key, which is hard-coded in the image manifest
to be imported as part of the image build.

Add the package back to the image base package set and regenerate all
affected test manifests.

[1] https://github.com/osbuild/osbuild-composer/pull/3421

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-06-20 14:55:26 +02:00
Eng Zer Jun
537add3d70 jsondb: improve performance of list operation
Since we only need to retrieve the file names, we can use
`(*os.File).Readdirnames` to avoid reading the whole file info for
better performance.

Sample benchmark:

func Benchmark_Readdir(b *testing.B) {
	for i := 0; i < b.N; i++ {
		f, err := os.Open("/")
		if err != nil {
			b.Fatal(err)
		}

		_, err = f.Readdir(-1)
		if err != nil {
			f.Close()
			b.Fatal(err)
		}

		f.Close()
	}
}

func Benchmark_Readdirnames(b *testing.B) {
	for i := 0; i < b.N; i++ {
		f, err := os.Open("/")
		if err != nil {
			b.Fatal(err)
		}

		_, err = f.Readdirnames(-1)
		if err != nil {
			f.Close()
			b.Fatal(err)
		}

		f.Close()
	}
}

goos: linux
goarch: amd64
pkg: github.com/osbuild/osbuild-composer/internal/jsondb
cpu: AMD Ryzen 7 PRO 4750U with Radeon Graphics
Benchmark_Readdir-16         	   31304	     33551 ns/op	    5638 B/op	      70 allocs/op
Benchmark_Readdirnames-16    	  128443	     12124 ns/op	    1228 B/op	      30 allocs/op
PASS
ok  	github.com/osbuild/osbuild-composer/internal/jsondb	3.098s

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2023-06-20 10:45:22 +02:00
Alexander Todorov
eb5dd8ae1b Conditionally skip test based on osbuild-compose.rpm version from distro 2023-06-15 08:54:57 +02:00
Achilleas Koutsou
9ed61d021b distro/test: update test distro with new behaviour
Add a checksum as a hash of URL + Ref.
Use the parent ref instead of the image ref when it's set.  This makes
the test distro always behave like ostree commit and container types
(image types that can use an ostree parent) and not raw image or
installers (that use ostree commits as a payload).

Modify the weldr API test with the expected error message.
2023-06-14 11:19:29 +02:00
Achilleas Koutsou
0eb999d510 cloudapi: remove ostree from imageRequest
Use ostree.ImageOptions for the request parameters instead of a
SourceSpec on the imageRequest.

When preparing the image request, add the ostree values from the API's
compose request to the ostree options on the image options of the image
request.

It's not necessary to create a source spec and it's also not necessary
to add the default ref when it's not specified in the request for an
ostree-based image type.  Both of these will be handled by the Manifest
generation based on the ostree options (imageOptions.OSTree).  The image
functions will take care of setting any missing parameters or returning
errors if any required parameters are missing.
2023-06-14 11:19:29 +02:00
Achilleas Koutsou
8e5ac9790e worker: update ostree job structs
Change the OSTreeResolveSpec to match the ostree SourceSpec by removing
the Parent field.

Change OSTreeResolveResultSpec to match the CommitSpec by adding the
Secrets field.  The RHSM field is kept for backwards compatibility with
older workers.
2023-06-14 11:19:29 +02:00
Achilleas Koutsou
7e2855bbb3 ostree: rewrite Resolve() to take SourceSpec and return CommitSpec
The Resolve() function is now only responsible for resolving a
SourceSpec to a CommitSpec.  It only resolves a checksum if a URL is set
and sets the option for the RHSM secrets.

The Parent has been removed from the SourceSpec.  The SourceSpec is a
simple reference to a single ostree ref and has no connection with the
ostree options.
2023-06-14 11:19:29 +02:00
Achilleas Koutsou
3a42770548 distro/test: test ostree options
Test all combinations of ostree options and verify the ostree commit
source spec returned by the manifest.
2023-06-14 11:19:29 +02:00
Achilleas Koutsou
d34ad18aaf distro/test: remove test skip line
Oops!
2023-06-14 11:19:29 +02:00
Achilleas Koutsou
7a23a81228 ostree: use image options for request data
The ostree options for a compose request should be specified using the
ImageOptions struct, not the source spec.  The source spec should be
specifying the source parameters for a single ostree commit internally.
2023-06-14 11:19:29 +02:00
Achilleas Koutsou
56ea5db9a8 ostree: variable rename: parent -> checksum
There's nothing parent-y about what we're resolving.  It's the checksum
of a ref in a given repository.
2023-06-14 11:19:29 +02:00
Achilleas Koutsou
7553d1bee1 manifest: add a Distro enum to the Manifest
Add a Distro enum to the Manifest struct for selecting package
selection.

Packages are sometimes renamed between distribution versions and since
we do the package selection in the Manifest, we need a way to select
distro-version-specific package names inside the manifest initialiser.

This may change in the future.
2023-06-14 11:19:29 +02:00
Achilleas Koutsou
5dba246813 manifest: remove Content field from manifest
Do not expose the content of the manifest statically and instead rely on
the public methods to retrieve source specifications dynamically.

Since the methods require iterating through the pipelines to collect
source specifications, we should avoid calling the function multiple
times when we can reuse the returned values.
2023-06-14 11:19:29 +02:00
Achilleas Koutsou
cecbc97e06 cloudapi/v2/test: codestyle cleanup
- Remove redundant types in struct literals (linter warning)
- Fixed indentation in json string literals
2023-06-14 11:19:29 +02:00
Achilleas Koutsou
68ccc58706 Adapt tests to new test_distro
The new test_distro's manifest produces a slightly different empty
manifest when serialized even without content.  Cloud API and Koji tests
have been adapted to match.

Weldr tests have been updated in several ways:
- The test_distro content resolver is used to resolve manifest content
  before serializing.
- The test scenarios in TestCompose have been named for easier
  troubleshooting (easier to identify a failing test by name).
- Manifests that work with the secondary ostree repo (the "other") use
  the appropriate URL and ref and create a secondary "other" serialized
  manifest.

The weldr API's test flag for resolving ostree commits does not produce
the same, fixed hash every time but instead computes a sha256 from the
URL + ref, like we do in the test manifests.
2023-06-14 11:19:29 +02:00
Achilleas Koutsou
aa4fa91214 distro/test: use the new ContentTest pipeline
Use the new ContentTest pipeline to define a manifest instead of
assigning content to the manifest directly.
2023-06-14 11:19:29 +02:00
Achilleas Koutsou
8638fe19d8 manifest: empty content-only pipeline for testing
Define a public pipeline implementation that allows initialising with
content, serialising with resolved content, but produces no stages.
This is useful for testing.
2023-06-14 11:19:29 +02:00
Achilleas Koutsou
4a37a0517f cloudapi: generate manifest once
Initialise the manifest only once in the enqueue functions
(ImageType.Manifest()) and pass it to the manifest generation function
with the workers and the dependency IDs.  The function is renamed from
generateManifest() to serializeManifest() to reflect its new
functionality more accurately.  The arguments to the function have also
been trimmed since we no longer need the image type, blueprint, and
image options.

The new functionality of the function is to collect all the resolved
content from the workers and serialize the manifest object.
2023-06-14 11:19:29 +02:00
Achilleas Koutsou
6e4efabf24 cloudapi: use manifest content to resolve containers
Use the container sources provided by the content on the initialised
manifest instead of the blueprint to resolve containers.  The container
sources on the manifest are a map keyed by the name of the pipeline that
will use the resolved containers, but the worker's container resolve job
works on a slice, so we reread the content map to get the pipeline name
(instead of taking the first payload pipeline from the image type).
This requires that there be only one pipeline that embeds containers,
which currently true of all our image types.
2023-06-14 11:19:29 +02:00
Achilleas Koutsou
962399d18a cloudapi: use manifest content to resolve ostree commit
Use the commit sources provided by the content on the initialised
manifest instead of the image options to resolve commits.  The ostree
sources on the manifest are a map keyed by the name of the pipeline that
will use the resolved commit spec, but unlike with the package sets, the
worker's commit resolve job works on a slice, so we reread the content
map to get the pipeline name.  This requires that there be only one
pipeline that requires a resolved ostree commit, which is currently true
of all our image types.

Setting the default ostree ref on the image options before calling
Manifest() isn't needed anymore.
2023-06-14 11:19:29 +02:00
Achilleas Koutsou
d833a0c3c3 weldr: resolve ostree commits after manifest initialisation
OSTree commits are now resolved after manifest initialisation just like
packages and containers.  The test commit hash handling is moved to the
resolver function.
2023-06-14 11:19:29 +02:00
Achilleas Koutsou
33dff78846 distro/test: add ostree sources to test distro
For ostree image types in the test distro, create an ostree source spec
and return it with the rest of the content.
2023-06-14 11:19:29 +02:00
Achilleas Koutsou
5c648c78f9 distro/test: adapt manifest test to new data
Read the ostree options in the compose request into a copy of the struct
that's used to write them.
Read the ostree commits from the content part of the manifest files and
use them in the serialisation function.
2023-06-14 11:19:29 +02:00
Achilleas Koutsou
7d1ee88700 Only set URL for ostree image options in tests
In tests (and dev tools) that apply to all image types, set just the
ostree URL instead of all the options.

The default ref is handled by the image functions when needed, so it
doesn't need to be set from the caller.
2023-06-14 11:19:29 +02:00