Commit graph

272 commits

Author SHA1 Message Date
Josue David Hernandez Gutierrez
6c19fd93ba tools/test/test_depsolve.py: Fix baseurl to be a list
Signed-off-by: Josue David Hernandez Gutierrez <josue.d.hernandez@oracle.com>
2025-08-13 15:42:00 +02:00
Achilleas Koutsou
e253f7c8b9 tools: new script: update-test-manifests
Add a new script that parses the Schutzfile for repository snapshot
dates and updates any vars.ipp file found in test/data/manifests/ to
match the snapshot date for the same distro.
After modifying the vars.ipp files, it runs `sudo make test-data` to
regenerate all test manifests and then, for each modified manifest,
generates the new diff.json for that stage test.

A few things to note:
- The distro detection for each vars.ipp file is partially
  heuristic-based.  It assumes that the first component of the filename
  is the distribution name.  This is true for our current files, but
  it's not a hard rule.  The script will fail with an error if the first
  component of a filename is not a valid distro name.
- The script uses ruamel.yaml instead of the standard pyyaml.
  ruamel.yaml is much better at preserving the structure of the original
  yaml file during a load-modify-dump and provides more ways of
  controlling indentation and wrapping.  The package will need to be
  installed in any runner that calls this script.
- This script will eventually become part of a GitHub workflow that is
  dispatched from the rpmrepo snapshot creation job.  When that happens,
  it might be changed to take snapshot dates as arguments rather than
  reading them from the Schutzfile.
2025-07-31 00:53:54 +02:00
Tomáš Hozza
1dc2cdcc14 Tools/inline-source.py: support specifying data encoding
Extend the script to support specifying the data encoding. Keep
'base64' as the default encoding.

Add support for 'lzma+base64' encoding.

Also use the 'base64' module, instead of 'binascii' module for base64
encoding. This is consistent with what the actual source implementation
uses.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-05-13 10:27:36 +02:00
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
Michael Vogt
549136b1b0 tools: drop requirement for module_platform_id from request
The PLATFORM_ID got retired from fedora-43 [0] and it
seems like it was always kinda optional. So lets make
it optional for real to avoid failing to build fedora-43
images.

[0] https://fedoraproject.org/wiki/Changes/Drop_PLATFORM_ID
2025-05-07 10:28:47 +02:00
Simon de Vlieger
563153ac6f tools: support zstd in image-info
We have images that are zstd-compresed now so `image-info` needs to be
able to deal with them.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-03-07 16:00:57 +01: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
a07431bb34 osbuild-depsolve-dnf: allow passing custom license index db file
Allow passing a custom license index db file for SBOM generation by
specifying it in the solver configuration.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-27 13:31:19 +01:00
Tomáš Hozza
99a7047173 tools/osbuild-depsolve-dnf: extend default config with loaded
Instead of completely overriding the default solver configuration with
the one loaded from a file, just extend the default config. This will
allow to specify just desired config options and keeping the defaults
for the rest.

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
c69b16f333 Tools/osbuild-image-info: rework analyse_iso()
Rework the function to actually fail in case it can't analyze the
provided ISO. Previously, the tool would silently fail to analyze ISO,
generate and generate an empty report. Fix this.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-05 12:00:20 +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
ce4bc01b7b osbuild-image-info: exit with non-zero value on empty report
For the purpose of using this tool in tests (specifically for manifest
tests where we diff image-info reports), it is important that the tools
exists with non-zero value if the final report is empty.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-03 12:58:29 +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
Tomáš Hozza
bf64127c26 osbuild-image-info: use .splitlines() instead of .split("\n")
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-03 12:47:35 +01:00
Tomáš Hozza
a6c09fd441 osbuild-image-info: refactor opening of LVM LV devices
Extract the opening of LVM LV devices from `discover_lvm()` to
`OSBuildDeviceManager` class as `open_lvm_lv()` method.

`open_lvm_lv()` returns the path to the opened device in the devpath set
in the underlying `DeviceManager`. The `org.osbuild.lvm2.lv`
implementation takes the responsibility for creating and managing
device nodes. This means that we don't need to be creating any device
nodes directly in `osbuild-image-info`, especially in the current
working directory. This was previously causing issues when inspecting
two images with different LVM layout in a sequence.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-01-31 10:18:14 +01:00
Tomáš Hozza
116bd17244 osbuild-image-info: add wrapper for device.DeviceManager
Add a new class `OSBuildDeviceManager`, which wraps
`devices.DeviceManager`, so that we can consolidate all code that is
opening devices using osbuild, in it. As the fist step, move the
`loop_open()` function to the class.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-01-31 10:18:14 +01:00
Tomáš Hozza
dbf01e2d1a osbuild-image-info: volume_group_for_device -> lvm_vg_for_device
Rename the function for naming consistency and always include the actual
error from `pvdisplay` when raising RuntimeError.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-01-31 10:18:14 +01:00
Tomáš Hozza
0fba11369c osbuild-image-info: extract discovery of LV names into a function
Extract the code that discovers LVM LV names for a given VG, from
`discover_lvm()` into a separate function `lvm_lvs_for_vg()`. This
improves the readability of the code. In addition, some values returned
by the `lvdisplay` invocation were never used. Don't request them and
simplify the code. Rename variables that hold LV names to clearly
express that.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-01-31 10:18:14 +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
cb4bd7051b osbuild-image-info: don't fail on no systemd default target
Some image types don't have systemd installed and don't have any default
target set, e.g. 'tar' image type. Running osbuild-image-info on such
image would result in traceback (e.g. [1]). Handle this case gracefully.

[1] https://gitlab.com/redhat/services/products/image-builder/ci/osbuild/-/jobs/8911649248#L6480

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-01-22 20:36:11 +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
Achilleas Koutsou
67f344fa52 tools/osbuild-image-info: append mountpoint to mount ID
The mount ID must be unique.  So far, we were using the device as the ID
for the mount because that was unique to each mount.  With btrfs
subvolumes however, the device and partition are the same for all, so we
need another way to differentiate.
2025-01-10 17:18:05 +01:00
Achilleas Koutsou
30d1faabdd tools/osbuild-image-info: move fstab search to function 2025-01-10 17:18:05 +01:00
Achilleas Koutsou
e513820518 tools/osbuild-image-info: handle root on subvol
Btrfs volumes typically only contain subvolumes instead of (parts of)
the OS tree directly.  In our images in particular, this is always the
case.  When searching for root to find /etc/fstab, search through the
subvolumes on a btrfs volume for the file and return the path to the
root subvolume.

Co-authored-by: Michael Vogt <michael.vogt@gmail.com>
2025-01-10 17:18:05 +01:00
Achilleas Koutsou
a16582b8c7 tools/osbuild-image-info: Mount() with partition=None
Always set partition=None for the kwargs of the Mount() constructor.

The previous code was added for backwards compatibility with older
versions of the Mount() constructor that didn't include the 'partition
argument.  It's safe to remove now because:
1. It's been long enough that we wont run osbuild-image-info with an old
   version of osbuild.
2. The tool is packaged with osbuild so there is no version drift and no
   compatibility issues.
2025-01-10 17:18:05 +01:00
Achilleas Koutsou
10029167db tools/osbuild-image-info: fail early if fstab isn't found
When the fstab file isn't found, the root_tree will never be set after
being initialised to "" and an exception is raised "The root filesystem
tree is not mounted".  It's a lot clearer if the failure happens closer
to the root cause, which is that fstab wasn't found and there are no
fstab entries to iterate through and find the root filesystem.
2025-01-10 17:18:05 +01:00
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