Commit graph

126 commits

Author SHA1 Message Date
Sanne Raymaekers
c7d2eaa5f7 test: use non-deprecated gitlab CI variables
CI_BUILD_ID was replaced with CI_JOB_ID in gitlab 9+.
2023-05-12 11:02:49 +02:00
Gianluca Zuccarelli
1c25d2792c tests/api: custom repository tests
- remove `custom-repos.sh` integratoin test
- add custom repositories check to `api` tests for supported
  images
- verify custom repositores are added to /etc/yum.repos.d
- verify gpg key is saved to /etc/pki/rpm-gpg (for inline keys)
2023-04-26 14:16:16 +01:00
Tomáš Hozza
c528948b71 Test/API: use directories and files customization for supported images
Use directories and files customization in the compose request for image
types that support this customization (only ostree installer and raw
image do not support it).

Extend the instance verification to check for the custom directories and
files.

Extend the ostree commit verification to check for the custom
directories and files.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-02-22 12:17:36 +01:00
Sanne Raymaekers
07a8f3d5ea test: adapt to shellcheck v0.9.0 2022-12-13 13:55:53 +01:00
Brian C. Lane
d73171fdde Use go install instead of deprecated go get
In go 1.18 'go install' needs to be used to install an executable. See
https://go.dev/doc/go-get-install-deprecation and
https://go.dev/doc/manage-install
2022-11-09 12:08:43 +01:00
Tom Gundersen
626530818d worker/server: requeue unresponsive jobs
If a job is unresponsive the worker has most likely crashed or been shut
down and the in-progress job been lost.

Instead of failing these jobs, requeue them up to two times. Once a job is lost
a third time it fails. This avoids infinite loops.

This is implemented by extending FinishJob to RequeuOrFinish job. It takes a
max number of requeues as an argument, and if that is 0, it has the same
behavior as FinishJob used to have.

If the maximum number of requeues has not yet been reached, then the running
job is returned to pending state to be picked up again.
2022-11-02 15:26:00 +01:00
Sanne Raymaekers
8fdd158799 cloudapi/v2: use the ostree resolve job to resolve ostree refs 2022-10-19 18:14:10 +02:00
Achilleas Koutsou
632f371a08 test: add iot-commit to api tests by name 2022-09-20 18:29:28 +02:00
Tomáš Hozza
2f6c238b7a test/cases/api.sh: fix indentation 2022-09-19 10:37:32 +02:00
Achilleas Koutsou
bf83bbea38 test: move greenprint and redprint functions to shared_lib.sh
Since we're sharing functions between test scripts, move greenprint(),
the most rewritten function in the history of the project, to
shared_lib.sh and source it everywhere.
2022-09-13 16:06:19 +01:00
Sanne Raymaekers
d13347e1ca cloudapi: Add endpoints to clone aws images across regions
Support for creating multiple amis from a single compose. It uses the
AWSEC2* jobs to push images to new regions, and share them with new
accounts.

The compose it depends upon has to have succeeded.
2022-08-30 16:14:52 +02:00
Tomas Hozza
24c52c8d69 osbuild-mock-openid-provider: support client_credentials grant type
Extend the implementation of mock openid server to take the `grant_type`
into consideration for the `/token` endpoint.

In addition to the previously supported `refresh_topen`, the
implementation now supports also `client_credentials`.

This is necessary to make it possible to use the mock server in
the `koji-osbuild` CI, because the builder plugin uses
`client_credentials` to get access token.

The implementation behaves in the following way:
 - For `refresh_token` grant type, it takes the `refresh_token` value
   from the request and adds it to the `rh-org-id` field in the custom
   claim, which is part of the returned token.
 - For `client_credentials` grant type, it takes the `client_secret`
   value from the request and adds it to the `rh-org-id` field in the
   custom claim, which is part of the returned token.

Requests without the supported `grant_type` set are rejected.

Modify affected test cases to specify `grant_type` when fetching a new
access token.
2022-08-05 16:15:24 +02:00
Tomas Hozza
45850639a0 provision.sh: don't start local worker and Weldr with TLS auth
Do not start local worker (mask the unit) and Weldr API socket when
provisioning the SUT with TLS client cert authentication method. This
method is used only in the Service scenario, therefore starting these
units / sockets was not reflecting the intended deployment.

Modify `api.sh` to not rely on local worker.

Modify `base_tests.sh` to provision SUT with TLS for
`osbuild-auth-tests`, while provisioning SUT with no authentication
method for the rest of test cases.
2022-08-04 11:55:43 +02:00
Ygal Blum
1847a6ae05 tests/api: add container related test
Add a new cloud API test that will build an edge-container,
upload it to the gitlab CI registry, fetch it from there,
run it and compare that the OSTree commit contained in it
is indeed the one we expect.

Co-Developed-By: Christian Kellner <christian@kellner.me>
2022-08-01 21:50:03 +01:00
Jakub Rusz
efbd5ebd7b ci/tests: Change the way artifacts are collected
We want to be able to safely gather any artifacts without worrying about
any possible secrets leaking. Every artifacts that we want to upload
will now have to be placed in /tmp/artifacts which will then be uploaded
to S3 by the executor and link to the artifacts will be provided in the
logs. Only people with access to our AWS account can see them.
2022-07-18 11:33:57 +03:00
Sanne Raymaekers
339d69d2da test/api: Add gcloud and generic s3 changes to split api tests
- Fixed shellcheck errors
- Moved checkEnv from common to individual tests
- Fixed package install section in spec file:
Globs which include a directory fail on el-like distros.
- Use gcloud cli to ssh
- (re)Introduce generic s3 tests
2022-07-05 12:15:31 +02:00
Ondřej Budai
cb7c0283a5 test/api: split into smaller files
Each cloud now has its own file that's sourced on-demand by the main api.sh
script. The main goal of this commit is to reduce the amount of clutter in
api.sh. I, personally, find 1300 lines of bash overwhelming and I think that
this is a reasonable beginning to start cleaning things up.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-07-05 12:15:31 +02:00
Juan Abia
8f9bb1bc01 tag azure resources with gitlab-ci-test
cloud cleaner removes old enough resources with 'gitlab-ci-test' tag.
2022-06-30 13:46:15 +02:00
Tomas Hozza
09f57b6c2f api.sh: fix requesting of JWT token
`osbuild-mock-openid-provider`'s `/token` endpoint expects URL-encoded
values in the POST request body. Use the same values as those that would
be used by the worker when refreshing a token.
2022-06-10 14:48:18 +01:00
Ygal Blum
feb357e538 Support Generic S3 upload in Composer API
Use case
--------
If Endpoint is not set and Region is - upload to AWS S3
If both the Endpoint and Region are set - upload the Generic S3 via Weldr API
If neither the Endpoint and Region are set - upload the Generic S3 via Composer API (use configuration)

jobimpl-osbuild
---------------
Add configuration fields for Generic S3 upload
Support S3 upload requests coming from Weldr or Composer API to either AWS or Generic S3
Weldr API for Generic S3 requires that all connection parameters but the credentials be passed in the API call
Composer API for Generic S3 requires that all conneciton parameters are taken from the configuration
Adjust to the consolidation in Target and UploadOptions

Target and UploadOptions
------------------------
Add the fields that were specific to the Generic S3 structures to the AWS S3 one
Remove the structures for Generic S3 and always use the AWS S3 ones

Worker Main
-----------
Add Endpoint, Region, Bucket, CABundle and SkipSSLVerification to the configuration structure
Pass the values to the Server

Weldr API
---------
Keep the generic.s3 provider name to maintain the API, but unmarshel into awsS3UploadSettings

tests - api.sh
--------------
Allow the caller to specifiy either AWS or Generic S3 upload targets for specific image types
Implement the pieces required for testing upload to a Generic S3 service
In some cases generalize the AWS S3 functions for reuse

GitLab CI
---------
Add test case for api.sh tests with edge-commit and generic S3
2022-06-02 16:12:53 +03:00
Sanne Raymaekers
71c78991a6 cloudapi: Drop bucket from composer config
This value is set in the worker config. In future it might also be
passed through the api to upload into target accounts, but it should
never be set in composer.
2022-06-01 12:03:12 +02:00
Achilleas Koutsou
cd49c932a2 test: add prominent message in test script cleanup functions
When a test script fails in CI, it's often difficult to pinpoint the
exact line in the log where the script failed and the cleanup() function
(trapped on EXIT) begins.

Adding a prominent line (with greenprint where available) at the start
of the cleanup function will make reading logs of failed jobs a lot
easier.
2022-05-25 22:10:27 +02:00
Tomas Hozza
31ff2a2283 tests/gcp: pick machine type from those available in the zone
Do not rely on the default machine type when creating a GCE instance,
but rather list the available machine types in the zone and pick from
them. Test cases will pick the smallest machine type which name matches
the `^n\d-standard-\d$` regular expression.

This should prevent CI failures like
https://gitlab.com/redhat/services/products/image-builder/ci/osbuild-composer/-/jobs/2497043942#L2930
2022-05-25 09:51:37 +02:00
Tomas Hozza
18dfa9d9c9 Improve GCP test cases to pick regions with available quota
We currently use a single GCP Compute region when spinning up VMs using
the imported GCE image. As a result, we are often hitting the
'IN_USE_ADDRESSES' quota limit when there are multiple CI jobs running.
Google does not allow us to increase the quota limit any more.

Change the GCP test cases to use the CI `GCP_REGION` variable to list
all GCE regions with available quota and pick a random one from the
list. The `GCP_REGION` value is used as the region name prefix when
filtering available regions. This means that if you specify an exact GCE
region, such as `us-west1`, you'll always get the same region, but if a
GCP multi-region is used, such as `us`, then a random region prefixed
with 'us' will be used.
2022-05-17 12:18:12 +02:00
Tomas Hozza
29174bfbef test/api.sh: take advantage of GCP guest tools to SSH to the VM
Modify the Cloud API test case for GCP to use `gcloud` and GCP guest
tools installed in the image to connect to the VM instance over SSH.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2022-04-14 19:07:31 +01:00
Tomas Hozza
ea3e6f072e test/api.sh: filter repos by image type
Filter the list of repositories passed in compose request based on the
`image_type_tags` object member. This is the same approach used by the
Weldr API. If the `image_type_tags` does not exist, the repo is added to
the list. If the `image_type_tags` exists, the repo is added to the list
only if the image type name is in the tags array.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2022-04-14 19:07:31 +01:00
Tomas Hozza
e30fa53c50 CI: rotate the used RHSM activation key 2022-04-07 11:44:52 +02:00
Tomas Hozza
72019740c2 Cloud API: upload stream-optimized VMDK to S3
The VMDK image must be in stream-optimized format in order to be
imported to VSphere. osbuild-composer does not produce VMDK by default
as stream-optimized. Instead, it is converted on the fly when the image
build job has been submitted via Weldr API.

Since we are aiming mainly for the VSphere use case with the VMDK image
in the service, the image should be ready for importing to VSphere.

Implement a temporary workaround for the Cloud API and AWS S3 target to
upload stream-optimized VMDK image.

Adjust the `api.sh` test case to not convert the VMDK image downloaded
form S3, before importing it to VSphere.
2022-04-02 08:47:02 +01:00
Tomas Hozza
5acaaabc1d test/api.sh: do not print to stdout when dumping the DB
Ensure that the content of the database is not printed to the console
when dumped at the end of the test case. The output is still preserved
as a CI run artifact.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2022-04-02 08:47:02 +01:00
Tomas Hozza
7a44d00cec test/api.sh: cleanup the DB container
Kill and remove the DB container as part of the test case cleanup.
Without this change, running the test case more than once fails.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2022-04-02 08:47:02 +01:00
Tomas Hozza
27c260daaf test/api.sh: verify VMDK images from S3 in VSphere
Extend the `api.sh` test to verify the VMDK images uploaded to S3 in
VSphere by booting them and configuring using cloud-init.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2022-04-02 08:47:02 +01:00
Ondřej Budai
80af9cac98 cloudapi: enable edge-commit on Fedora
We have to do a small hack to enable edge-commit on Fedora because its name
is different. We can also change this in the image definition but I want to
iterate quickly on the Fedora Integration MVP and don't want to run in
any conflicts with
https://github.com/osbuild/osbuild-composer/pull/2461

This commit also enables a test for Fedora IoT built through the API.

While enabling the test, I also simplified our decision logic for SSH_USER
and DISTRO.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-03-25 13:23:32 +01:00
Tomas Hozza
d11a2f3bc7 api.sh: encrypt the DB dump artifact 2022-03-23 09:45:09 +01:00
Sanne Raymaekers
2023f7731d worker: Support client_credentials grant type in client
This will allow us to use the service accounts which work against
identity.api.openshift.com. These are much easier to manage, especially
with the new multi-tenancy, as there's a single page to create/expire
them across an account.

They also have the added benefit of not expiring automatically when
they're not used like offline tokens, and immediate expiration when
desired.
2022-03-21 09:43:43 +01:00
Tomas Hozza
e5595667bc test/api.sh: move the DB dump to the cleanup() function
Previously, the DB was not dumped in case the compose failed. Ensure
that the DB is dumped before the script exits in any case.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2022-03-16 09:03:47 +00:00
Tomas Hozza
e8a347d1e8 test/api.sh: do not use /tmp, but $WORKDIR
Do not create files directly in `/tmp`, but use `$WORKDIR`, which is a
temporary directory for transient files, which gets cleaned up when the
test case finishes. Without this change, running `api.sh` twice fails
the second time.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2022-03-16 09:03:47 +00:00
Ondřej Budai
cfb756b9ba api/{cloud,worker}: used channel name based on JWT claims for new jobs
This commit implements multi-tenancy. A tenant is defined based on a value
from JWT claims. The key of this value must be specified in the configuration
file. This allows us to pick different values when using multiple SSOs.

Let me explain more in depth how this works:

Cloud API gets a new compose request. Firstly, it extracts a tenant name from
JWT claims. The considered claims are configured as an array in
cloud_api.jwt.tenant_provider_fields in composer's config file. The channel
name for all jobs belonging to this compose is created by `"org-" + tenant`.

Why is the channel prefixed by "org-"? To give us options in the future. I can
imagine the request having a channel override. This basically means that
multiple tenants can share a channel. A real use-case for this is multiple
Fedora projects sharing one pool of workers.

Why this commit adds a whole new cloud_api section to the config? Because the
current config is a mess and we should stop adding new stuff into the koji
section. As the Koji API is basically deprecated, we will need to remove it
soon nevertheless.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-03-08 12:07:00 +01:00
Sanne Raymaekers
b05723a37e templates/composer: Verify against mass sso and rh sso 2022-02-24 09:48:12 +01:00
Tom Gundersen
351d06aecf tests/cases/api.sh: make /var at least 256MB
We (mistakenly) don't enforce a minimum size for /var,
so setting it to 1024 (1kB) causes the image build to fail.

CI does not expose this in a helpful way at the moment,
so this is a bit tricky to debug.

Also skip customizations for the AWS.S3 upload type. Not all the
image types with this upload type support filesystem customizations
and that's as expected. We could make a more fine-grained test in
the future, but testing with a coulpe of targets should be
sufficient.
2022-02-19 11:13:55 +00:00
Chloe Kaubisch
0619ffa588 cloudapi: expose filesystem customizations 2022-02-19 11:13:55 +00:00
Tomas Hozza
617572ad6c test/api.sh: remove parts related to Fedora 33
We no longer test Cloud API on Fedora and Fedora 33 is EOL anyway.
Remove all Fedora 33 related lines from the test case.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2022-02-08 10:19:52 +01:00
Alexander Todorov
43738d6caa tests: Fix for unbound variable 2022-02-04 23:43:43 +01:00
Jakub Rusz
1c2c97c900 tests/api: Make cleanup best effort
We should not fail on missing variables or errors during cleanup. The
test can fail in any stage and the cleanup should be run full each time.
2022-01-19 19:56:28 +01:00
sanne
60d4f5a751 composer: Disable artifacts for the service
When backed by a DB, composer has no need of a queue directory.

This also addresses "Error moving artifacts for job" logging noise.

Signed-off-by: sanne <sanne.raymaekers@gmail.com>
2021-12-16 17:04:08 +00:00
sanne
3686e31e49 test/api: Integration test for 3rd-party repositories 2021-12-15 20:12:49 +01:00
Juan Abia
9debf97f37 test/cases: tag gcp resources
gcp test images are not tagged. Now we create the "gitlab-ci-test"
labbel so it's easier to remove them later.
2021-12-14 12:20:31 +01:00
Achilleas Koutsou
ba320c9ea0 test/api: update database query for getting job result
- Filter on manifest-id-only type jobs
- Save entire result

Co-authored-by: Sanne Raymaekers <sanne.raymaekers@gmail.com>
2021-12-03 16:49:09 +00:00
Achilleas Koutsou
3ee31c23be test/api: image type as argument
Script is run with the image type to build as the argument.
The target / cloud service is selected based on the image type
specified. This is how the API actually works now: Only an image type
can be specified.

The script now supports all the blobby image types for testing:
- edge-commit
- edge-container
- edge-installer
- image-installer
- guest-image (qcow2)
- vsphere (vmdk)

These are image types that are uploaded to S3 and provided to the user
as an object to download rather than a VM image on a cloud provider.

To verify the cloud api compose request options for the qcow2 and vmdk
image types, download the object and inspect it using image-info.

Checks if postgresql is installed and that user1 and user2 exist in the
passwd file.

Signed-off-by: Achilleas Koutsou <achilleas@koutsou.net>
2021-12-03 16:49:09 +00:00
sanne
ee8e551c5f test: Fixes for 8.5-ga 2021-12-02 10:41:04 +01:00
Juan Abia
eed20916b0 test/cases: tag aws s3 resources
all resources on aws originated from a test should be tagged with
"gitlab-ci-test". this commit ensures s3 resources get tagged.
2021-11-26 10:00:42 +01:00