|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import pytest |
| 4 | + |
3 | 5 | import logging |
4 | 6 |
|
5 | 7 | from lib.commands import SSHCommandFailed |
@@ -201,32 +203,31 @@ def coalesce_integrity(vm: VM, vdi: VDI, vdi_op: CoalesceOperation): |
201 | 203 |
|
202 | 204 | XVACompression = Literal['none', 'gzip', 'zstd'] |
203 | 205 |
|
204 | | -def xva_export_import(vm: VM, compression: XVACompression): |
| 206 | +def xva_export_import(vm: VM, compression: XVACompression, request: pytest.FixtureRequest): |
205 | 207 | # The tests using this function are using specific fixtures to create the VM on the expected SR |
206 | 208 | # In consequence, we can't use the storage_test_vm, so we have to start the VM explicitly and install randstream |
207 | 209 | vm.start() |
208 | 210 | vm.wait_for_vm_running_and_ssh_up() |
209 | 211 | install_randstream(vm) |
| 212 | + |
210 | 213 | # 500MiB, so we have some data to check and some empty spaces in the exported image |
211 | 214 | vm.ssh("randstream generate -v --size 500MiB /root/data") |
212 | 215 | vm.ssh("randstream validate -v --expected-checksum 24e905d6 /root/data") |
213 | 216 | vm.shutdown(verify=True) |
| 217 | + |
214 | 218 | xva_path = f'/tmp/{vm.uuid}.xva' |
215 | | - imported_vm = None |
216 | | - try: |
217 | | - vm.export(xva_path, compression) |
218 | | - # check that the zero blocks are not part of the result. Most of the data is from the random stream, so |
219 | | - # compression has little effect. We just check the result is between 500 and 700 MiB |
220 | | - size_mb = int(vm.host.ssh(f'du -sm --apparent-size {xva_path}').split()[0]) |
221 | | - assert 500 < size_mb < 700, f"unexpected xva size: {size_mb}" |
222 | | - imported_vm = vm.host.import_vm(xva_path, vm.vdis[0].sr.uuid) |
223 | | - imported_vm.start() |
224 | | - imported_vm.wait_for_vm_running_and_ssh_up() |
225 | | - imported_vm.ssh("randstream validate -v --expected-checksum 24e905d6 /root/data") |
226 | | - finally: |
227 | | - if imported_vm is not None: |
228 | | - imported_vm.destroy() |
229 | | - vm.host.ssh(f'rm -f {xva_path}') |
| 219 | + request.addfinalizer(lambda: vm.host.ssh(f'rm -f {xva_path}')) |
| 220 | + vm.export(xva_path, compression) |
| 221 | + # check that the zero blocks are not part of the result. Most of the data is from the random stream, so |
| 222 | + # compression has little effect. We just check the result is between 500 and 700 MiB |
| 223 | + size_mb = int(vm.host.ssh(f'du -sm --apparent-size {xva_path}').split()[0]) |
| 224 | + assert 500 < size_mb < 700, f"unexpected xva size: {size_mb}" |
| 225 | + |
| 226 | + imported_vm = vm.host.import_vm(xva_path, vm.vdis[0].sr.uuid) |
| 227 | + request.addfinalizer(lambda: imported_vm.destroy()) |
| 228 | + imported_vm.start() |
| 229 | + imported_vm.wait_for_vm_running_and_ssh_up() |
| 230 | + imported_vm.ssh("randstream validate -v --expected-checksum 24e905d6 /root/data") |
230 | 231 |
|
231 | 232 | def vdi_export_import(vm: VM, sr: SR, image_format: ImageFormat): |
232 | 233 | vdi = sr.create_vdi(image_format=image_format) |
|
0 commit comments