Commit Graph

16 Commits

Author SHA1 Message Date
Peter Krempa
156ddb43b1 storage_file_probe: Treat qcow2 images with protocol drivers in backing store field as raw
qemu allows and in some cases uses protocol driver names ('file',
'host_device', 'nbd', ...) in the 'backing file format' field of a qcow
to denote a image where the dummy 'raw' driver was not used on top.

Adapt our backing store parser for such cases. The examples added in
previous patch show the difference in behaviour.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-11-27 10:12:34 +01:00
Peter Krempa
6fe9e35610 virstoragetest: Add test cases for QCOW2 files with a protocol name as backing file format
QEMU allows and in cases where you omit the not-strictly-needed 'raw'
driver on top of raw images automatically uses the protocol name inside
of the 'backing file format' field of the qcow2 image.

Libvirt expects only format names in that field.

Add example images showing this scenario, which will be fixed later.

The qcow2 image files in this commit were formatted as:

  qemu-img create -f qcow2 -F nbd -b  nbd+tcp://example.org:6000/blah -u qcow2-protocol-backing-nbd.qcow2 10M

and

  qemu-img create -f qcow2 -F file -b raw  qcow2-protocol-backing-file.qcow2

thus using 'nbd' and 'file' as backing format respectively.

(note that '-b raw' refers to the file in the example image folder)

To satisfy the test, note that the NBD image is also rejected as we
can't probe it, thus such configuration would not work.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-11-27 10:12:34 +01:00
Peter Krempa
7e158006b6 virstoragetest: Format detected/unprocessed backing store format into output files
Compare also the detected format of the backing file
('backingStoreRawFormat' field) into the output data for comparison with
others. Since the ToString function can't convert VIR_STORAGE_FILE_AUTO
use also the numeric value.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-11-27 10:12:34 +01:00
Peter Krempa
bc54376f09 virstoragetest: Use strings for storage type and format in output data
Make it easier for the humans to read/compare the outputs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-11-27 10:12:34 +01:00
Peter Krempa
4f7aaa1b7b virstoragetest: Reinstate testing of images without 'backing_fmt'
There are important security implications when we'd misprobe those
images. This commit reinstates the tests removed by commit 979d1ba3ae
since 'qemu-img' refused to format them.

With the new testing approach with stored images we won't run into that
problem.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-09-09 15:29:00 +02:00
Peter Krempa
dc80ca18e0 virstoragetest: Unify testing of QCOW2 images with absolute backing
We have 3 test cases for this currently:

1) "qcow2->raw"
 1.1) VIR_STORAGE_FILE_QCOW2 as top level format
 1.2) VIR_STORAGE_FILE_AUTO as top level format
2) "wrap->qcow2->raw" whith just VIR_STORAGE_FILE_QCOW2

This patch adds also testing of VIR_STORAGE_FILE_AUTO for case 2) and
removes both 1) subcases as they are being actually tested as part of
2).

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-09-09 15:29:00 +02:00
Peter Krempa
8f36cf91ac virstoragetest: Use preformatted qcow2 image for testing relative paths
More preparation for eliminating image rewriting.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-09-09 15:29:00 +02:00
Peter Krempa
229a6d6992 virstoragetest: Convert symlink and relative image testing use preformatted images
Use prepared test images instead to simplify and clarify the code
instead of rewriting existing images multiple times.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-09-09 15:29:00 +02:00
Peter Krempa
0ee87da294 virstoragetest: Use existing file for testing 'raw' image lookup
We've already added a 'raw' file to the example image directory so we
can use that instead of formatting one.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-09-09 15:29:00 +02:00
Peter Krempa
df020845d5 virstoragetest: Use preformatted file for testing missing backing store
Similarly to previous ones, this one doesn't need to be created by
qemu-img in order for the test to make sense.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-09-09 15:29:00 +02:00
Peter Krempa
80412bfbeb virstoragetest: Use pre-formatted file for non-path extraction test
This one doesn't require using qemu-img either.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-09-09 15:29:00 +02:00
Peter Krempa
325fce82d1 virstoragetest: Use a pre-formatted QED file for testing backing store extraction
The QED format isn't really being developed any more. Use a
pre-formatted image to test the existing code. In this instance we
switch to using a relative backing path for simplicity.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-09-09 15:29:00 +02:00
Peter Krempa
55688197ee virstoragetest: Use existing directory in the source tree for 'directory' probing tests
We don't need a special directory for the tests. Reuse the directory
holding the data for the virstoragetest.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-09-09 15:29:00 +02:00
Peter Krempa
df94a4e907 virstoragetest: Test backing chain loops with hardcoded images
Provide the images for the self and mutual backing image loop cases in
the repository rather than formatting them with qemu-img.

This makes the code more readable and also decouples the backing chain
tests from each other.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-09-09 15:29:00 +02:00
Peter Krempa
0a67ae731a virstoragetest: Rework TEST_LOOKUP* cases to work on fake backing chain
Rather than using 'qemu-img' and rewriting the chain we can use fake
data and few empty files to ensure the same level of coverage. This is
possible since we've already tested that the metadata parsing from files
works properly and the only thing we are testing here is that the
symlink resolution works properly.

Additionally after the refactor of 'virstoragetest' is complete
additional tests on real data will be added.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-09-09 15:29:00 +02:00
Peter Krempa
80c1fea639 virstoragetest: Store output of TEST_CHAIN in output files
The TEST_CHAIN cases were storing the expected output (or rather data
to generate the expected output) in code. This made the code really hard
to follow and even harder to modify to add new cases.

This patch modifies the code to store the expected output in text files
(using the same generator as we've used to) and uses
'virTestCompareToFile' to check the outputs.

The result is that the code is way simpler and doesn't require fiddling
with 'testFileData' structs when adding new cases. Additionally this
removes mixing of code and declaration so we can stop disabling the
warning for this file.

Another advantage is that the tests are now named so it's easier to
figure out if one of them breaks.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-09-09 15:29:00 +02:00