Commit graph

29 commits

Author SHA1 Message Date
Simon de Vlieger
b2ec2cd5ee Revert "ostree: introduce optional subpath feature"
This reverts commit 3bb5bedd8e as it
introduces problems in the caching system used by `osbuild` [1]

[1]: https://github.com/osbuild/osbuild/issues/2009
2025-02-11 17:39:45 +01:00
Lukas Zapletal
3bb5bedd8e ostree: introduce optional subpath feature 2025-02-10 20:17:36 +01:00
Tomáš Hozza
7993b78e7c Testutil: add DNF5 helper function for depsolving
This will be used for testing the SBOM implementation with DNF5.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-12-02 23:24:39 +01:00
Lukas Zapletal
ef24311f77 sources: MTLS and proxy support for ostree 2024-11-04 16:35:53 +01:00
Michael Vogt
1b3e956334 testutil: switch mock_command to use bash
This change allows use the more advanced features of bash like
array operations (e.g. `${@:2}` to drop the first two arguments
or similar. On fedora/rhel this is a no-op as it is already using
sh -> bash (afaik).
2024-10-24 10:06:46 +02:00
Tomáš Hozza
67c7d63983 testutil: add helper function for depsolving pkgset with DNF4
This will be useful for testing SBOM implementations.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-09-18 12:26:36 +02:00
Michael Vogt
e535877798 test: add new https_serve_directory() and test certs
This commit adds a new `https_serve_directory()` test helper
and some custom self-signed and worthless certs that are used
during testing. They are not dynamically generated to avoid the
extra compuation time during tests (but they could be).

Generated via:
```
$ openssl req -new -newkey rsa:2048  -nodes -x509  \
   -subj "/C=DE/ST=Berlin/L=Berlin/O=Org/CN=localhost"   \
   -keyout "key1.pem" -out "cert1.pem"
```

This will allow us to test `https` download URLs as well in e.g.
the curl source.
2024-07-29 16:51:48 +02:00
Michael Vogt
0d3a153c78 sources: add new _fetch_all_new_curl() helper
When using a modern curl we can download download multiple urls
in parallel which avoids connection setup overhead and is generally
more efficient. Use when it's detected.

TODO: ensure both old and new curl are tested automatically via
the testsuite.
2024-07-04 11:53:40 +02:00
Michael Vogt
d50857e5aa stages: fix test values for "images" inputs
The "images" inputs in the tests were bad test values and only worked
"by accident" [0]. Thanks to Achilleas for discovering this!

This commit fixes this.

[0] https://github.com/osbuild/osbuild/pull/1752#discussion_r1580891435
2024-04-29 14:11:44 +02:00
Michael Vogt
a3f86a0736 testutil: fix make_container() cleanup
During the work on PR#1752 Florian discovered that make_containers()
is broken for nested containers like:
```
with make_container(tmp_path, {"file1": "file1 from base"}) as base_tag:
    with make_container(tmp_path, {"file1": "file1 from final layer"}, base_tag) as cont_tag:
```
It errors with:
```
Error: 5b947de461ee21b858dd5b4224e80442b2f65b6410189147f2445884d9e4e3d8: image not known
```
The reason is that we work with hashes for the image and then call
`podman image rm` which by default will also remove all dangling
references. Those are defined by not having a tag and not referenced
anymore. So the inner container cleanup also removes the outter.

There are many ways to fix this, I went with re-adding tags to the
test containers because it also makes it easy for the user to see if
we left any containers (accidently) around.
2024-04-25 21:59:40 +02:00
Tomáš Hozza
3ae8f25f55 Testutil/importlib: don't write bytecode when importing modules
Cache files will split the extension, this means that all pyc cache
files looks like we get many clashing `org.osbuild.cpython-py311.pyc
files. Moreover, the cache bytecode invalidation is based on the
timestamp (which is the same after git checkout) and the file size
(which may be the same for two different files). This means that we
can't rely on the cache files.

This issue has been found after the previous commit made the
`org.osbuild.systemd` and `org.osbuild.selinux` stages to have exactly
the same size, which caused the interpreter to reuse the bytecode for
the selinux stage when running unit tests for the systemd stage. This
resulted in consistent and weird failures when the systemd stage
options were passed to the selinux stage code.

The credit for this fix goes to Michael Vogt, who found the cause and
fix. Also thanks to Simon de Vlieger for his help with debugging the
problem.

Co-authored-by: Michael Vogt <michael.vogt@gmail.com>
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-04-22 16:33:59 +02:00
Michael Vogt
2586a748fd testutil: skip tests for missing ThreadingHTTPServer in py36
Only py3.7+ has ThreadingHTTPServer and SimpleHTTPRequestHandler
that can take a directory argument. We could reimplement this
on py36 (easy for threading, harder for missing directory) but
instead this commit just skips tests that try to use a
ThreadingHTTPServer.

Remove once we no longer support py3.6.
2024-04-16 15:16:49 +02:00
Michael Vogt
b9b296a7e5 testutil: add AtomicCounter() as a threadsafe counter
The existing code in the reqs counting is not really thread safe,
this commit fixes that.
2024-04-09 03:02:45 +02:00
Michael Vogt
cee0615f4d testutil: add http_serve_director() test helper
To test the curl sources it is very useful to have a small httpd
server that can serve an arbitrary directory. This helper will
ensure that via:
```python
with with osbuild.testutil.net.http_serve_directory(fake_httpd_root) as httpd:
    port = httpd.server_port
    # download from http://localhost:{port}/<any-path-under-httpd-root>
```
2024-04-05 16:42:07 +02:00
Michael Vogt
1d4f2dc53b testutil: extract find_one_subclass_in_module() helper
A small refactor to avoid shipping this duplicated code (this
one is easy to extract/reuse).
2024-04-03 11:36:01 +02:00
Michael Vogt
5f31ccf9f2 test: add/use new testutil.make_fake_service_fd()
All inputs/sources tests need a fake service fd to instanciate
their services. Consolidate the creation in a single helper.
2024-04-03 11:36:01 +02:00
Michael Vogt
9393211b8a testutil: tweak mock_command to write a call_log
Instead of just mocking the binary also write a log of the way
it got called so that tests can use this to check if the right
options are passed.

Note that the API should be improved here, instead of returning
a "naked" path to the calllog file there should be a class wrapping
it. And of course there should be tests.
2024-03-18 20:37:21 +01:00
Michael Vogt
fd0167f130 test: return container_id in make_container
The current `make_container()` helper is a bit silly (which is
entirely my fault). It requires a container tag as input but all
tests end up creating a random number for this input. So instead
just remove the input and return the container_id from the podman
build in the contextmanager and use that.
2024-03-18 20:36:19 +01:00
Achilleas Koutsou
700dc8ded3 test/stages: build manifest and check tree
Copy hello.img into the host storage, build the manifest, export the
tree, and check the storage in the tree for the expected files and data.
2024-02-21 17:55:37 +01:00
Achilleas Koutsou
591593ea00 testutil: make_container context manager
Make make_container a context manager so we can reliably clean up
containers that were created in tests.
2024-02-21 17:55:37 +01:00
Michael Vogt
f7e4febb2c stage,test: extract make_container() test helper 2024-02-21 17:55:37 +01:00
Michael Vogt
7b5d6e4bd9 testutil: add new mock_command context manager
The new `testutil.mock_command` context manager can be used to
mock commands in PATH and replace them with arbitrary shell
scripts. This is useful in testing to e.g. simulate exact error
conditions that would be hard to trigger otherwise or to replace
long running commands with faked results.

Example:
```
fake_cmd = textwrap.dedent("""\
do-something
""")
with mock_command("some-cmd", fake_cmd):
   your_code
```
2024-02-12 17:41:21 -08:00
Michael Vogt
a56afcb280 test: add new testutil.assert_jsonschema_error_contains() helper
This commit adds a new helper `assert_jsonschema_error_contains()`
to `testutil` and uses it everywhere where we check errors from
jsonschema.
2024-01-23 12:00:59 +01:00
Michael Vogt
ac5653d9f1 stages: rework container-deploy stage to not use tmp storage
This commit reworks the `org.osbuild.container-deploy` stage to
not use a tmp storage when mounting the container image. This
is needed because of [0] but it should generally be fine because
inside the stages the real /var is a tmpfs (which is why we
triggered the bug in the first place).

[0] https://github.com/containers/storage/issues/1779
2024-01-03 11:25:48 -08:00
Michael Vogt
ad8fd2f532 testutil: extrace new make_fake_tree() helper
Extract a new helper `make_fake_tree()` that generalizes the existing
helper `make_fake_input_tree()`. The later will always create the
content under `{basedir}/tree` which is convinient for input tree
based tests but too specialized when using it in different contexts.

The existing `make_fake_input_tree()` is preserved unchanged and
becomes just a tiny wrapper.
2024-01-03 11:25:48 -08:00
Brian C. Lane
9eb9f7f7f2 test: Move make_fake_input_tree to testutil
This is useful for other stage tests, move it and add a test.
2023-12-12 19:45:04 +01:00
Alexander Larsson
eea81b660a testutils: Add assert_dict_has
This is a convenient way for tests to assert that some nested dicts
(like a parsed json) has a particular key/value somewhere in it.

For example:
  assert_dict_has(config, "toplevel.subitem.key", True)
2023-12-12 09:54:38 +01:00
Simon de Vlieger
1f51938046 osbuild: testutil provides has_executable
Add a helper function to determine if an executable is on PATH.
2023-11-10 12:03:23 +01:00
Michael Vogt
061501d4c2 osbuild: add new testutil.imports module to help test stages
This commit adds `osbuild.testutil.imports.import_module_from_path`
that can be used to import arbitrary python source files. This
allows importing files from the stages directory that have a
non python friendly filename like `org.osbuild.kickstart`.
2023-11-07 15:12:08 +01:00