Commit graph

40 commits

Author SHA1 Message Date
Michael Vogt
f7d56b3d7e tests: update l2hash for the fc40 move
Similar to what was explained in 2e6d49fbe this commit updates
the l2hash in test_assemblers to the new values from fc40 images.

Sadly it is hard to derive them from first principles (see the
other commit) and given that this is legacy code it is probably
fine this way.
2024-07-02 09:46:45 +02:00
Michael Vogt
1278e5d217 test: fix test_assembler to support parallel runs and run in parallel
The `test_assembler.py` hardcods some filesystem and partition
UUIDs. This leads to hard to diagnose test failures when the
test is run in parallel. The btrfs and xfs filesystem drivers
will see the same uuid for multi created images and error sometimes with
someting like:
```
Mar 06 10:22:54 top kernel: BTRFS error: device /dev/loop104 belongs to fsid aff010e9-df95-4f81-be6b-e22317251033, and the fs is already mounted, scanned by mount (123856)
```
Its a race that only happens when two images are checked at the
same time.

This commit fixes the issue by just using a randomized UUID in
the test_assemblers.py. It also re-enables running the test in
parallel (which make it run a lot faster, from 34min to 14min).
2024-03-06 12:28:10 +01:00
Michael Vogt
87636878da Revert "workflow: run assembler tests in parallel"
This reverts commit ea36e25b09.
2024-03-06 10:43:21 +01:00
Michael Vogt
ea36e25b09 workflow: run assembler tests in parallel
The assembler tests currently run around 45min, try to run in
parallel to see how much we can win from that.
2024-03-05 07:44:26 +01:00
Michael Vogt
4d2476a26d test: use OSBUILD_TEST_STORE in test_assemblers.py too
Use the OSBUILD_TEST_STORE in the test_assemblers.py file too
and re-use already downloaded sources.
2024-03-05 07:44:26 +01:00
Michael Vogt
2e6d49fbef tests: update test_assemblers.py for f38 changes
The `test_assemblers.py` has an `assertGRUB2` helper that ensures
that the data written in the mbr and first megabyte is unchanged
by the `org.osbuild.qemu` assembler.

With the move to f38 the digests change. The mbr digest is
computed via the following python code and it matches that value
used in the test (440 byte only because the rest is the partition
table).
```
$ python3 -c 'import hashlib,sys; f=open(sys.argv[1], "rb"); m1=hashlib.sha256();m1.update(f.read()[:440]);print(m1.hexdigest())' ./f34/usr/lib/grub/i386-pc/boot.img
26e3327c6b5ac9b5e21d8b86f19ff7cb4d12fb2d0406713f936997d9d89de3ee
```

So with that code we can update the f38 mbr value now.
```
$ python3 -c 'import hashlib,sys; f=open(sys.argv[1], "rb"); m1=hashlib.sha256();m1.update(f.read()[:440]);print(m1.hexdigest())' ./f38/usr/lib/grub/i386-pc/boot.img
b8cea7475422d35cd6f85ad099fb4f921557fd1b25db62cd2a92709ace21cf0f

However computing the second sha256 for the `512:1024*1024` is much
harder to do from first principles because the value depends on the
image generated via `grub2-mkimage` and the hash changes with each
different module or config option. This means one needs to replicate
the exact inputs of:
```
    subprocess.run(["grub2-mkimage",
                    "--verbose",
                    "--directory", f"/usr/lib/grub/{platform}",
                    "--prefix", f"(,{partid})/{grub_path}",
                    "--format", platform,
                    "--compression", "auto",
                    "--output", core_path] +
                   modules,
                   check=True)
```
in the test. At this point I cheated and just update to the computed
value inside the test.
2023-11-14 10:45:44 -08:00
Ondřej Budai
3bb5a00375 test/run/assemblers: convert to a v2 manifest
Instead of using the F34-based manifests, let's switch to F38. I tried my
best to import the vars into the new manifest, but I don't think that's
currently supported.
2023-11-14 10:45:44 -08:00
Tomáš Hozza
5946a013ee Test: some tests depending on rpm-ostree were not checking its presence
Add conditional skip to some tests that depend on rpm-ostree
availability, but were not checking for its presence. These tests would
previously fail if rpm-ostree is not available. They will be skipped
now.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-04-28 22:02:35 +02:00
Tomáš Hozza
d9e97a4830 Test/assemblers/assertImageFile: don't set default argument values
Do not specify the default value for 'expected_size' argument in
assertImageFile() function declaration. Previously, it was set to
`None`, which was never taken into account. Moreover, all callers of the
function always provide an explicit value, so the default was never
really used.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-04-21 17:13:10 +02:00
Tomáš Hozza
ff6b96bee5 Test: add ability to skip tests for unsupported file-systems
Add a new optional pytest CLI argument `--unsupported-fs` allowing to
specify file-systems which should be treated as unsupported in the
platform where running tests. Any test cases dependent on such
file-system support will be sipped.

This will allow to run unit tests and selectively skipping test cases
for unsupported file-systems.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-04-21 17:13:10 +02:00
Tomáš Hozza
db89984465 Test: port assembler tests from unittest to pytest
Port assembler tests from unittest to pytest. In addition, use
parametrized tests when testing various filesystems and various
combinations.

This is important to be able to selectively skip the test for if a
specific filesystem is not supported by the kernel (e.g. btrfs is not
supported on RHEL). Skipping a unittest subtest is not possible, which
is the motivation to move away from it and use only pytest.

Test output is now also much nicer for parametrized test cases.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-04-21 17:13:10 +02:00
Simon de Vlieger
ea6085fae6 osbuild: run isort on all files 2022-09-12 13:32:51 +02:00
Simon de Vlieger
e330e82cf0 lint: appease autopep8 2022-09-09 15:33:29 +02:00
Simon de Vlieger
38d2ab685c test: explicit encodings for open() 2022-09-09 15:33:29 +02:00
Christian Kellner
4b11989ce3 manifests: convert ostree commit to format v2
Convert the manifest to use version 2 format. Version 1 is really
not used much anymore because composer was completely ported to
using v2. Welcome to the future, ostree commit.
2022-08-13 19:21:52 +01:00
Christian Kellner
80414299cd test/stages: export tree and compare that
Instead of checkpointing the tree and then accessing the generated
tree inside the store via the `map_object` function we not just
export the tree and use that. This better hides the internals of
the store and also allows us to activate on-demand building that
does not rely on checkpoints being implicitly built like exports.
2021-12-02 12:51:30 +00:00
Christian Kellner
7ae4a7e785 test: use and require explicit exports
Require all the tests that compile a manifest to either specify
checkpoints or exports. Convert all the tests that were relying
on implicit exports with v1 manifests to use explicit exports.
2021-12-02 12:51:30 +00:00
Christian Kellner
2c64c65608 test/assembler: use new loop_for_fd helper
Use the new `loop_for_fd` helper that got added to `LoopControl`,
which is basically a version of the existing code.
2021-08-11 20:59:51 +02:00
Christian Kellner
a47a40cf26 test: remove unittest dependency for OSBuild
Remove the dependency on unittest for the `OSBuild` class which
used the `unittest` instance only for `assertEqual`, which can
easily also be done via a plain `assert`.
2021-06-21 18:56:38 +02:00
Tomas Hozza
8d43a78918 test: update test manifests to use Fedora 34
Move from using 'zram' to 'zram-generator-defaults' in the ostree bootiso
testing manifest. More information is available in Fedora 33 Change
document [1].

Add org.osbuild.kernel-cmdline stage to fedora-boot.json manifest
because of change in how grub handles the kernel command line arguments
[2].

GRUB2 Stage 2 checksums in assemblers test are updated. The change have
been verified by building the fedora-boot.json manifest with each checked
filesystem and booting the image in QEMU with legacy mode.

[1] https://fedoraproject.org/wiki/Changes/SwapOnZRAM
[2] https://github.com/osbuild/osbuild-composer/pull/982#issuecomment-697356929

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-06-07 12:15:26 +02:00
Christian Kellner
89c3df8de4 test/assembler: verify the tar'ed content
In the test case for the tar assembler, actually verify the
content by un-tar-ing the result again and comparing it to
the tree. This would have spotted missing SELinux labels.
2021-01-26 12:09:23 +01:00
Christian Kellner
ef5875e1f4 test/assemblers: skip unless we can bind mount
We need to be able to bind-mount in the assembler tests, so skip
all of those if we can't (because we are not root).
2020-12-04 12:28:30 +01:00
Christian Kellner
cf48fe8afe test/assembler: check metadata for ostree asm
Check the metadata is in the result and that it has the 'compose'
entry, which should match what is in `compose.json`.
2020-08-13 10:50:34 +02:00
Christian Kellner
fdded58cdd test/assembler: check for ostree version metadata
Set the OS version of the commit via the new `os_version` option
and make sure that it is in the compose info as well as in the
commit metadata.
2020-08-12 08:08:17 +02:00
Davide Cavalca
a5f4de85cd test: bump filesystem size to 1G 2020-08-04 10:49:37 +02:00
Davide Cavalca
38c1ed52ce test: xfs also needs a different l2hash 2020-08-04 10:49:37 +02:00
Davide Cavalca
04204d585d test: lost+found really is just ext4 2020-08-04 10:49:37 +02:00
Davide Cavalca
fc6eb5c4c4 test: btrfs needs a different l2hash 2020-08-04 10:49:37 +02:00
Davide Cavalca
925530ac0a assemblers: add btrfs support to qemu and rawfs 2020-08-04 10:49:37 +02:00
Ondřej Budai
3cc8c91092 test/assemblers: use smaller images
640k ought to be enough for anybody!

Err... I mean...

The assembler tests now install only the filesystem and selinux packages and
their dependencies. For this, we don't need the  luxury of 2 GiB.

This commit changes the image size to 512 MiB. This has some advantages:

- the tests are faster - I measured the qemu assembler test and the running
  time went down from 290s to 260s.
- the tests can be run in environments with smaller disk space
2020-07-29 07:35:32 +02:00
Ondřej Budai
5842bbb93e test: make osbuild.compile method take output_dir as a parameter
Previously, the osbuild executor had its internal temporary directory that
served as the output directory. However, this approach gives no power to
the caller to control the lifetime of the produced artifacts. When more
images are built using one executor, the results will accumulate in one
place possibly leading to exhaustion of disk space.

This commit removes the executor's internal output directory. The output
directory can now be passed to osbuild.compile, so the caller can control
its lifetime. If no directory is passed in, the compile method will use
its own temporary directory - this is useful in cases when the caller
doesn't care about the built artifacts or the manifest doesn't have any
outputs.
2020-07-29 07:35:32 +02:00
Ondřej Budai
06db7834f9 test/assemblers: use one osbuild executor for all qemu and tar tests
This way the test can benefit from osbuild's internal cache:

The first subtest builds all the stages and  runs the assembler
The next subtests can reuse the built stages and just run the assembler

Some data from my machine running the qemu test:

Building the manifest takes about 120 seconds
Running just the assembler on the cache's content takes 30 seconds.

Before this change, the whole manifest was built 3 times:
3 * 120 = 360 seconds

After this change, the whole manifest is built once and the cache
is reused 2 times:
1 * 120 + 2 * 30 = 180 seconds
2020-07-27 13:18:40 +01:00
Ondřej Budai
49049276f5 test/assemblers: pass osb executor to run_assembler explicitly
Let the caller decide which executor instance should be used to build
the manifest. This change allows us to use osbuild's built-in cache
in the following commit.
2020-07-27 13:18:40 +01:00
Ondřej Budai
4b290dd2a4 test: use a dummy pipeline when testing assemblers
#471 extends the assembler test suite to also test xfs and btrfs filesystems
in raw and qemu assemblers. However, this change leads to long running times
of this suite.

The running time of these test consist of 3 main steps:

1) Building the build pipeline
2) Building the stages
3) Running the assembler

There are two optimization approaches:

1) Caching
   OSBuild supports caching, therefore it's possible to cache results of first
   two steps.

2) Minimizing the operating system tree
   Assemblers don't care about the image contents. Therefore, it's possible
   to create just a small tree which would be used to test the assemblers.
   This should lead to speed up in the step 2 (smaller tree should be built
   quicker) and in step 3 (big part of assembling is just copying files over
   to the image).

This commit implements the second approach. A new test manifest is now added,
which just installs the filesystem package and its dependencies and this tree
is then labeled. This solution was chosen, so that the assemblers get
something that looks as a proper filesystem tree but also can be built pretty
quickly.

Before this change, the test_rawfs method with #471 merged ran for 842 seconds.
After this change, it ran for 391 seconds.
2020-07-21 10:25:47 +02:00
Christian Kellner
00f06dff16 test/assemblers/ostree: check rpm-ostree.inputhash
Verify the rpm-ostree.input hash is set correctly for the repository
itself as well. This will in turn also verify that the repository
is existent and can be accessed.
2020-06-15 13:44:01 +02:00
Christian Kellner
da80259ea0 test: add a test for the ostree.commit assembler
Create a ostree commit and check that it successfully was created
by inspecting the resulting `compose.json`.
2020-06-15 13:44:01 +02:00
Christian Kellner
cf03ca0715 test/assemblers: remove the need to use nbd
Using the network block device (nbd) kernel module to test all
the non-raw image formats often caused tests to fail due to nbd
not being stable itself (see below).
Instead convert non-raw images to the raw format via qemu-img
convert and mount those with loop-back devices. All the testing
code itself stays the same.

Example nbd error messages:
  kernel: block nbd15: NBD_DISCONNECT
  kernel: block nbd15: Disconnected due to user request.
  kernel: print_req_error: 89 callbacks suppressed
  kernel: blk_update_request: I/O error, dev nbd15, sector 0 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 0
  kernel: buffer_io_error: 134 callbacks suppressed
  kernel: Buffer I/O error on dev nbd15, logical block 0, async page read
  kernel: blk_update_request: I/O error, dev nbd15, sector 1 op 0x0:(READ) flags 0x0 phys_seg 7 prio class 0
2020-06-15 11:51:31 +02:00
Christian Kellner
21e0475031 test/assemblers: split partition reading and test
Split up the partition table test into reading the partition table
and then asserting it has the correct entries. Prepares the usage
of the partition information later.
2020-06-15 11:51:31 +02:00
David Rheinsberg
06af246f38 test/assemblers: use F32 manifest
Switch to the fedora-boot.json manifest, so we automatically use the
latest fedora manifest for assembler-tests.
2020-06-05 09:27:40 +02:00
David Rheinsberg
0010514c4a test: move assembler-tests into ./test/run/
Move the last remaining test into the correct subdir. With this done,
all our tests run in one of the 3 groups:

   * `make test-src`
     Run tests against the source-code, including linters.

   * `make test-mod`
     Run unit-tests on the individual python modules. This needs no
     special permissions (unless noted in each test) or runtime
     environments. It is meant to be fast and easy to run in all
     circumstances.

   * `make test-run`
     Run tests that execute the osbuild pipeline. This requires
     superuser privileges and will likely take a while. Furthermore,
     this might produce large artifacts.
2020-06-05 09:27:40 +02:00
Renamed from test/test_assemblers.py (Browse further)