Commit graph

228 commits

Author SHA1 Message Date
Achilleas Koutsou
dc047513b7 tools/osbuild-image-info: skip swap partitions
When iterating partitions to mount, skip any with filesystem type
"swap".  This is done in two places:
1. When mounting partitions to find /etc/fstab.
2. When mounting partitions and volumes to analyse the tree.
2025-01-10 17:18:05 +01:00
Achilleas Koutsou
b9e84587ad tools/osbuild-image-info: store fstype when iterating parts
When iterating through partitions, store the fstype along with the other
information.  This will be useful for identifying btrfs partitions,
which we will need to scan for subvolumes, and for identifying swap
partitions, so we can avoid trying to mount them.
2025-01-10 17:18:05 +01:00
Achilleas Koutsou
fc4232af63 tools/osbuild-image-info: print fstype in error
Print the unrecognised fstype string when failing.
2025-01-10 17:18:05 +01:00
Achilleas Koutsou
0553465306 tools/osbuild-image-info: fix typos in docstrings and comments 2025-01-10 17:18:05 +01:00
Achilleas Koutsou
ac83e4541c tools/osbuild-image-info: code quality and style improvements
Run isort for imports.
Pylint: wrong-import-order / C0411
Solves the following linter warnings:
- standard import "pathlib" should be placed before third party import
  "yaml"
- standard import "collections.OrderedDict" should be placed before
  third party imports "yaml", "jsonschema"
- standard import "typing.Dict" should be placed before third party
  imports "yaml", "jsonschema"

Fix default arg values.
Pylint: dangerous-default-value / W0102
- Using mutable default values ([]) for function arguments is considered
  dangerous.

Rename format variable.
Pylint: redefined-builtin / W0622
- 'format' is a built-in function.

Use f-strings instead of formatting where possible.
Pylint: consider-using-f-string / C0209

Remove unnecessary else after returns.
Pylint: no-else-return / R1705

Remove unnecessary else after continue.
Pylint: no-else-continue / R1724

Set the encoding (utf-8) for all calls to open().
Pylint: unspecified-encoding / W1514

Disable the too-many-branches and too-many-statements warnings for
append_partitions() and append_filesystem().  We can refactor the
functions to make them smaller later, but for now we're addressing only
the simpler issues.

Initialise with dict literal instead of call to function.
Pylint: use-dict-literal / R1735

Use implicit truthiness for glob instead of len().
Pylint: use-implicit-booleaness-not-len / C1802

Rename ambiguous variable 'l' to 'line'.
pycodestyle: ambiguous-variable-name (E741)

Merge comparisons with 'in'.
Pylint: consider-using-in / R1714
2025-01-10 17:18:05 +01:00
Tomáš Hozza
ee3f0ab59a tools/osbuild-image-info: make read_boot_entries() more robust
`read_boot_entries()` could previously fail when trying to split lines
in bootloader entries, which contained only "\n" and became empty
string after stripping whitespace characters. This is the case e.g. on
F41 images.

Moreover, bootloader entries can contain comments as lines starting with
"#", which were previously not ignored by the function and would end up
in the parsed entry and could potentially fail to be split.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-01-04 10:37:05 +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
bced04b57d tools/osbuild-image-info: fix issues reported by autopep8
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-12-18 12:50:32 +01:00
Tomáš Hozza
0f99200ba1 tools: add image-info tool as osbuild-image-info
Add the image-info tool as osbuild-image-info from the manifest-db
repository [0]. This is an exact copy without any changes.

[0] 8e05a898d4/tools/image-info

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-12-18 12:50:32 +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
Alexander Larsson
9c3e5107aa osbuild-mpp: Fix error on python < 3.11
The change in commit ed33869430 to
use hashlib.file_digest breaks with older python, because
it was added in 3.11.

This change reverts back to hashing all the data in the case
where file_digest doesn't exist.
2024-11-27 00:06:08 +01:00
Alexander Larsson
a699d05094 osbuild-mpp: Allow using formating in the mpp-resolve-images handling
This allows using e.g. mpp-eval in the resolve-image operation, similar
to how it is now possible in the mpp-depsolve handling.

We want this so we can inject the list of images from a list variable
(that can then be mpp-join:ed, etc).
2024-11-13 11:22:16 +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
Jonathan Lebon
ed33869430 tools/osbuild-mpp: hash mpp-embed urls from stream
Currently if one uses `mpp-embed` with URLs, osbuild-mpp still wants to
download the full file just so it can hash it. Make this more efficient
by hashing from the stream instead, which `hashlib` natively supports.

This also makes osbuild-mpp work with large artifacts in environments
that may not have enough space to temporarily save the data.
2024-09-19 01:53:18 +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
Tomáš Hozza
65ef88687e osbuild/solver: add InvalidRequestError exception
This will allow validating request arguments in the solver method in a
different way for dnf4 and dnf5 and raising an exception if needed.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-09-18 12:26:36 +02:00
Paweł Poławski
db08c472f3 general: Fix linter issues across the codebase 2024-08-26 11:59:46 -07: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
64b102c297 osbuild-depsolve-dnf: fix traceback in case of repository error
Fix a bug in the `osbuild-depsolve-dnf`, which would cause the
`RepoError` to not be handled and producing a traceback.

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
Brian C. Lane
f17ab5cbaf osbuild-depsolve-dnf: refactor into osbuild.solver module
This moves the dnf and dnf5 code into a new osbuild module called
solver. The dnf specific code is in dnf.py and dnf5 is in dnf5.py

At runtime the osbuild-depsolve-dnf script reads a config file from
/usr/lib/osbuild/solver.json and imports the selected solver. This
currently just contains a 'use_dnf5' bool but can be extended to support
other configuration options or depsolvers.

At build time a config file is selected from tools/solver-dnf.json or
tools/solver-dnf5.json and installed. Currently dnf5 is not installed,
it will be added when dnf5 5.2.1.0 becomes available in rawhide (Fedora
41).

The error messages have been normalized since the top level functions in
osbuild-depsolve-dnf do not know which version of dnf is being used.
2024-08-01 08:57:30 +02:00
Roberto Majadas
ac7379488c mpp: Allow container-storage image resolution
This commit allows to the user to define the "container-transport"
variable when they are defining a container image to be resolved by the
osbuild-mpp tool. When the user defines the "container-storage" as
"container-transport" osbuild-mpp will look for the image in the local
container-storage.

Signed-off-by: Roberto Majadas <rmajadas@redhat.com>
2024-07-23 16:01:33 +02:00
Gianluca Zuccarelli
faaa0bf508 tools/tree-diff: use null for timestamped files
The `tree-diff` tool is used by the `gen-stage-diff` tool to generate
the stage `diff.json` files. A few of these stages have timestamped
files that need to be edited after the tool is run to replace the
`sha256` content hash with `null` so the stage diff tests ignore these
files.

This commit updates the `tree-diff` tool to check through a list of the
files that contain timestamps and to use the `null` value rather than
the `sha256` content hash so the stage tests don't fail.
2024-06-06 15:41:49 +01:00
Achilleas Koutsou
484130b678 tools/osbuild-depsolve-dnf: ignore optional-metadata for old dnf
The optional_metadata_types option isn't available in older versions of
dnf.  We could version-guard the option, but let's be more explicit and
check if it exists instead.

If it doesn't we can safely ignore it and rely on dnf's default
behaviour.
2024-05-31 09:00:24 +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
Achilleas Koutsou
8a9dac5258 tools/test: include optional metadata in tests
Run depsolve tests both with and without adding filelists to optional
metadata.
2024-05-29 01:39:05 +02:00
Achilleas Koutsou
31362772dd tools/osbuild-depsolve-dnf5: support optional metadata
We originally enabled filelists unconditionally in dnf5.  Let's make it
optional as part of the 'optional-metadata' option in the arguments so
that the caller can decide if it's needed, for example when using dnf5
with older repositories that have packages with file dependencies, but
don't download them when they're not needed, since the filelists are
quite large.
2024-05-29 01:39:05 +02:00
Achilleas Koutsou
806a1caba7 tools/osbuild-depsolve-dnf: support optional metadata
Filelist repo metadata is required when using newer versions of libdnf
with old repositories or packages that specify dependencies on files.
For example, depsolving with RHEL 9.3 repos on Fedora 40 fails to
resolve platform-python with the message

  nothing provides /usr/libexec/platform-python needed by platform-python-...

Not loading filelists is beneficial because it greatly reduces the size
of the metadata to download.  Filelists were downloaded by default for
repositories in the past, but with newer versions of dnf/libdnf (in
Fedora 40), they are downloaded on-demand (e.g. when running a query
that requires file information).  Newer package guidelines prohibit
depending on file paths, so filelists are not needed for package
depsolving with newer distro repositories.

Add an 'optional-metadata' property to the 'arguments' object of the
depsolve request, so that callers can enable any optional metadata they
need.

Further reading:
- https://libdnf.readthedocs.io/en/stable/tutorial-py/#case-for-loading-the-filelists
- https://github.com/rpm-software-management/dnf/releases/tag/4.19.0
- https://dnf.readthedocs.io/en/stable/user_faq.html#starting-with-fedora-40-i-noticed-repository-metadata-is-synchronized-much-faster-what-happened
2024-05-29 01:39:05 +02:00
Brian C. Lane
2269554829 osbuild-depsolve-dnf5: Fix sslverify setting
It was accidentally switched to being set on repo instead of conf when
it was renamed in commit ffa1e91707
2024-04-27 00:29:02 +02:00
Brian C. Lane
3ef6e684e5 test: Add a depsolve test for sslverify
Also fix the test, it wasn't updated to use sslverify instead of
ignoressl. This now correctly passes on -dnf and fails on -dnf5 which
will be fixed in the next commit.
2024-04-27 00:29:02 +02:00
Brian C. Lane
106a9af937 test_depsolve: Use host python3 for libdnf check 2024-04-23 07:42:09 +02:00