Commit graph

62 commits

Author SHA1 Message Date
Michael Vogt
d068c6d91f dnfjson: detect/error if no repositories are defined
This commit adds an error message if no repositories are
defined in the dnfjson query. We had the issue in
https://github.com/osbuild/bootc-image-builder/issues/922
that in a RHEL bootc-container no repositories are defined.

Here the error is quite confusing, as it complains about
error marking packages which is technically correct but
hides the root of the problem.

With this detect we can construct a more useful error
message in the higher layers.
2025-05-12 20:51:57 +02:00
Michael Vogt
ec3f70199c test: drop module_platform_id from depsolve tests
Drop `module_platform_id` as it is now optional and none of
our tests is using it (i.e. has any observable difference if
missing).

Once we start using it we need to add it (and maybe a
"with_platform_id" as parameter on top so that both with/without
platform_id is tested).
2025-05-07 10:28:47 +02:00
Tomáš Hozza
8f4813e273 Test/tools/depsolve: reword function doc text
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-27 17:44:44 +01:00
Tomáš Hozza
35993fe256 tools/test/depsolve/SBOM: test solver config with custom license db
Extend the depsolve SBOM test case to also cover the case when a custom
license DB file is provided.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-27 13:31:19 +01:00
Tomáš Hozza
e7d9446023 tools/test/depsolve: remove checks for errors where unnecessary
Requests in some test cases are expected to always succeed. Don't check
for errors in such test cases.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-18 10:50:19 +01:00
Tomáš Hozza
26de07737b tools/test/depsolve: use tmp_path fixture where possible
Use the tmp_path fixture where possible, instead of
TemporaryDirectory().

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-18 10:50:19 +01:00
Tomáš Hozza
badd77b31e tools/test/depsolve: introduce get_test_case_repo_configs()
Move construction of repo configs to get_test_case_repo_configs().

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-18 10:50:19 +01:00
Tomáš Hozza
7d7e0a7296 tools/test/depsolve: factor out depsolve sbom test case
Extract testing of SBOM support into a dedicated test case. There's no
added value in running all SBOM test cases for all types of depsolve
transactions.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-18 10:50:19 +01:00
Tomáš Hozza
29f93af0aa tools/test/depsolve: factor out search repo combos test case
Testing all repo config combos for each search test case does not
really increase the test coverage for repo config combos. It just
increases the run time of the test.

Move the repo config combos testing to a dedicated test case, which will
test search for two packages from two different repositories.

For the original `test_search()`, always use repo configs in the
request.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-18 10:50:19 +01:00
Tomáš Hozza
de9f4ba3cb tools/test/depsolve: always pass dnf_config as dict
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-18 10:50:19 +01:00
Tomáš Hozza
b917f6a238 tools/test/depsolve: factor out depsolve repo combos test case
Testing all repo config combos for each depsolve test case does not
really increase the test coverage for repo config combos. It just
increases the run time of the test.

Move the repo config combos testing to a dedicated test case, which will
test depsolving two packages from two different repositories.

For the original `test_depsolve()`, always use repo configs in the
request.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-18 10:50:19 +01:00
Tomáš Hozza
52d027393c tools/test/depsolve: factor out test case repo servers filtering
Extract the code that filters and composes repo servers for a test case
into a separate function. This enables reusing it in all places that did
the same thing. The problem would get more prominent as we would
separate some test scenarios into separate test cases.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-18 10:50:19 +01:00
Tomáš Hozza
3743654178 tools/test/depsolve: clean up test_depsolve_result_api()
The `test_depsolve_result_api()` test case was parametrized based on
`dnf_config`, but in reality, the `depsolve()` call always used an
empty dict as `dnf_config`. Effectively, it was being tested three
times with DNF4.

In addition, don't pass optional arguments to `depsolve()`.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-18 10:50:19 +01:00
Tomáš Hozza
e635a8a067 tools/test/depsolve: don't always pass repos, root_dir and opt_metadata
Modify the `config_combos()` to return `repo_configs` and `root_dir`
only if it should be really used. Otherwise, return `None`. Modify all
helper functions for dnf-depsolve API calls to add relevant fields to
the request JSON, only if the relevant values are set. This makes the
test cleaner, since previously, the `root_dir` was always set.

The same applies to `dnf_config`, which could be set to `None` already,
so let's make it optional.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-18 10:50:19 +01:00
Tomáš Hozza
a76d3e406b tools/test/depsolve: factor out func to generate repo config
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-18 10:50:19 +01:00
Tomáš Hozza
942c74ded1 Tools/osbuild-image-info: make read_selinux_ctx_mismatch more robust
Modify the function able to handle messages about skipped binary
fcontext files and skip them. This started to happen on c10s. Extend the
unit test to cover this new scenario.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-11 20:18:07 +01:00
Tomáš Hozza
3f8fe3381d Tools/osbuild-image-info: add unit test for read_selinux_ctx_mismatch
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-11 20:18:07 +01:00
Tomáš Hozza
b978559a80 Test/osbuild-image-info: test failures in analyse_iso()
Add unit test for testing failures in analyse_iso(). The function
should fail if it can't analyze the provided ISO.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-05 12:00:20 +01:00
Tomáš Hozza
542cf4a799 Test/osbuild-image-info: test failure on empty report
Test that the main() function exits with non-zero value if it would
return an empty report.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-03 12:58:29 +01:00
Michael Vogt
e4333f87ba tools: add test that ensures we notice if the solver api breaks
This commit adds a small test that ensures that we notice when
the solver API adds new top-level keys. When this happens the
images library breaks and we need to increase the
`Provides: osbuild-dnf-json-api` version in the `osbuild.spec`.

See e.g. https://github.com/osbuild/osbuild/pull/1992
2025-01-24 11:56:02 +01:00
Tomáš Hozza
e1b6c26bfb Test/osbuild-image-info: add unit tests for read_default_target()
Add two unit tests for the read_default_target() function:
1. When default target should be found.
2. When there should be no default target.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-01-22 20:36:11 +01:00
Simon de Vlieger
b4299b497e tools/test: explicitly enable repositories
Add a new `enabled_repos` field on the testcases which explicitly lists
which repositories are passed into a certain testcase. This allows us to
pass appstream only to the module testcase.

Re-adjust the package lists again since we're now not using appstream in
all depsolve tests.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-01-22 18:03:21 +01:00
Simon de Vlieger
b616da69f3 test/depsolve: fix package sets, add module test
With the enabling of AppStream some more (perhaps optional) packages are
included.

This also adds a test case which installs a module and verifies that
that module is returned.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-01-22 18:03:21 +01:00
Simon de Vlieger
1e70131346 data: include appstream repository metadata
The CentOS Stream 9 repository metadata contains modules; these are
necessary for testing modularity depsolving.

Note that the filelists metadata is kept empty to keep repository size
down.

Co-authored-by: Michael Vogt <michael.vogt@gmail.com>
Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-01-22 18:03:21 +01:00
Tomáš Hozza
2c3f528488 Test: add unit test for osbuild-image-info's read_boot_entries()
Add unit test for osbuild-image-info's `read_boot_entries()` function,
to ensure that it can handle various situations that can happen in the
real world.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-01-04 10:37:05 +01:00
Tomáš Hozza
562a30ce93 osbuild-depsolve-dnf: add SBOM support for DNF5
Enable generating SBOM documents for depsolved transactions when using
DNF5. Enable SBOM testing with DNF5 in unit tests.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-12-02 23:24:39 +01:00
Tomáš Hozza
ca1a21b923 Fix dependencies and test for DNF4 based osbuild-depsolve-dnf
For the DNF4 version, we actually use 'dnf' package and not 'libdnf'.
Fix the SPEC file dependencies and also the check in unit test.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-09-20 14:58:57 +02:00
Tomáš Hozza
1d8bd0f8a6 Support SBOM for depsolving in osbuild-depsolve-dnf
Extend osbuild-depsolve-dnf, to return JSON with SPDX SBOM that
corresponds to the depsolved package set, if it has been requested.
For now, only DNF4 is supported.

Cover the new functionality with unit test.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-09-18 12:26:36 +02:00
Achilleas Koutsou
d1dbcc20cf test/depsolve: use strings for pytest.skip()
The pytest.skip() argument must be a string.  Calling it with an
exception produces an error.
2024-08-20 10:47:36 -07:00
Tomáš Hozza
f4dc0f3f20 test_depsolve.py: add basic test cases for the 'search' command
Cover the 'search' command with a set of basic test cases.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-08 09:58:41 +02:00
Tomáš Hozza
421663cb28 test_depsolve.py: add basic test cases for 'dump' command
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-08 09:58:41 +02:00
Tomáš Hozza
d0094bbe2b test_depsolve.py: skip known broken tests with DNF5
The DNF5 implementation has known issues, which are not yet fixed and in
some cases, they can't be fixed due to the limitations and state of the
DNF5 implementation itself. Skip them for now.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-08 09:58:41 +02:00
Tomáš Hozza
a9caab3b1e test_depsolve.py: rename test_cases -> depsolve_test_cases
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-08 09:58:41 +02:00
Tomáš Hozza
4aca2709a7 test_depsolve.py: test installation of excluded package
Add a test case for installation of a package, which is excluded in a
different transaction. This is a common scenario in osbuild-composer,
where the image base package set is depsolved in the first transaction
and can contain package excludes. The user must be able to install these
excluded packages when specified explicitly in the Blueprint.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-08 09:58:41 +02:00
Tomáš Hozza
b49cb21a3e test_depsolve.py: test depsolving a package group with excludes
Add a test case for depsolving a package group with specific optional
packages of the group being excluded. This is a common scenario in
many image definitions.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-08 09:58:41 +02:00
Tomáš Hozza
93f69fdf94 test_depsolve.py: test depsolving of a package group
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-08 09:58:41 +02:00
Tomáš Hozza
bcc20fc94e test_depsolve.py: test that not enabled repos are not used
Add a test case, that the repositories not enabled for a transaction are
not really used to depsolve its package specs. This is a common use case
for osbuild-composer, where the custom repositories specified by the
user are enabled only for the second transaction and not for the first
one (when depsolving the image base package set). This is important, so
that the user can't possibly replace important packages shipped by
the "system" repositories (e.g. kernel, systemd, etc.) with versions
from their custom repositories.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-08 09:58:41 +02:00
Tomáš Hozza
60ac23d843 test_depsolve.py: test repository errors
Add a test case that triggers a repository error.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-08 09:58:41 +02:00
Tomáš Hozza
8c4bd7a064 test_depsolve.py: generate repo config combinations
Implement the generator for repo config combinations, instead of
hard-coding it. The motivation is to be able to optionally add e.g.
q broken repo to the list to test `RepoError`.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-08 09:58:41 +02:00
Tomáš Hozza
316a9b6203 test_depsolve.py: test depsolving conflicting packages
Add a test case for checking the error reason and message when
depsolving conflicting packages.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-08 09:58:41 +02:00
Tomáš Hozza
f19af8f374 test_depsolve.py: test error depsolving non-existing package
Porting the latests osbuild version in `osbuild/images` revealed a
regression in error messages returned by the tool in case a non-existent
package is requested in the depsolve request.

Test that requesting a non-existent package results in `MarkingErrors`,
which was the original behavior of the DNF4-based
`osbuild-depsolve-dnf`.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-08 09:58:41 +02:00
Tomáš Hozza
788afb5e66 test_depsolve.py: add IDs to test cases
Increase the readability of pytest verbose output by assigning simple
IDs to each test case.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-08 09:58:41 +02:00
Tomáš Hozza
1f237e56c3 test_depsolve.py: remove redundant test case
Remove one test case, which does not really add value or extend the test
coverage, since the same thing is already tested by previous test case.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-08 09:58:41 +02:00
Tomáš Hozza
03fbcfe7ad test_depsolve.py: assign test parameter IDs for better readability
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-08 09:58:41 +02:00
Tomáš Hozza
5bfee90f2c test_depsolve.py: support testing depsolving of multiple transactions
Until now, the unit test tested only very simple case with a single
transaction, which happens only for vanilla images. Any user
customization would result in multiple transactions in the depsolve
request. This case is not yet tested at all.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-08 09:58:41 +02:00
Tomáš Hozza
90b7de2ad5 test_depsolve.py: allow depsolve command to fail gracefully
Modify the function that executes the depsolve command, so that does not
produce exception in case the command fails. Instead, return the message
returned by `osbuild-depsolve-dnf` and the exit code. This will allow to
test also other scenarios (such as depsolve errors) in the test case.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-08 09:58:41 +02:00
Michael Vogt
ae72480612 solver: include "solver" key in the dnfjson reply
This commit includes the used sovler in the dnfjson reply. This
is mostly information (e.g. in service logs) but also useful in
tests to ensure that the expected solver was really run.

Note that this needs https://github.com/osbuild/images/pull/723
first.
2024-08-06 21:34:04 +02:00
Brian C. Lane
857507ecd6 test: Update the depsolve test
Test with no config file (libdnf), with use_dnf5 set to false, and with
it set to true. Make sure the correct dnf library was used.
2024-08-01 08:57:30 +02:00
Achilleas Koutsou
a7955e6af3 tools/test: check for *filelists* in depsolve repodata
When the filelists are enabled in the optional metadata, the local cache
for the depsolve will include a filelist file for each repository.
Count the files matching *filelists* using glob() and compare them with
the number of repositories when the option is enabled.
When the option is not enabled, there should be no filelists.
2024-05-29 01:39:05 +02:00
Achilleas Koutsou
5c171f0e8c tools/test: use a new cache for each depsolve
Use a fresh cache for each depsolve in tests.  This will let us check if
filelists are downloaded or not according to the option.
2024-05-29 01:39:05 +02:00