|
3 | 3 | import pytest |
4 | 4 |
|
5 | 5 | from lib.common import vm_image, wait_for |
| 6 | +from lib.sr import SR |
6 | 7 | from lib.vdi import VDI |
7 | 8 | from lib.vm import VM |
8 | 9 | from tests.storage import CoalesceOperation, XVACompression, coalesce_integrity, xva_export_import |
@@ -68,6 +69,38 @@ def test_coalesce(self, storage_test_vm: VM, vdi_on_zfsvol_sr: VDI, vdi_op: Coal |
68 | 69 | def test_xva_export_import(self, vm_on_zfsvol_sr: VM, compression: XVACompression): |
69 | 70 | xva_export_import(vm_on_zfsvol_sr, compression) |
70 | 71 |
|
| 72 | + @pytest.mark.small_vm |
| 73 | + def test_vdi_export_import(self, storage_test_vm: VM, zfsvol_sr: SR, image_format: str): |
| 74 | + vm = storage_test_vm |
| 75 | + sr = zfsvol_sr |
| 76 | + vdi = sr.create_vdi(image_format=image_format) |
| 77 | + image_path = f'/tmp/{vdi.uuid}.{image_format}' |
| 78 | + try: |
| 79 | + vm.connect_vdi(vdi, 'xvdb') |
| 80 | + # generate 2 blocks of data of 200MiB, at position 0 and at position 500MiB |
| 81 | + vm.ssh("randstream generate -v --size 200MiB /dev/xvdb") |
| 82 | + vm.ssh("randstream generate -v --seed 1 --position 500MiB --size 200MiB /dev/xvdb") |
| 83 | + vm.ssh("randstream validate -v --size 200MiB --expected-checksum c6310c52 /dev/xvdb") |
| 84 | + vm.ssh("randstream validate -v --position 500MiB --size 200MiB --expected-checksum 1cb4218e /dev/xvdb") |
| 85 | + vm.disconnect_vdi(vdi) |
| 86 | + vm.host.xe('vdi-export', {'uuid': vdi.uuid, 'filename': image_path, 'format': image_format}) |
| 87 | + vdi = vdi.destroy() |
| 88 | + # check that the zero blocks are not part of the result |
| 89 | + if image_format != 'vhd': |
| 90 | + # FIXME: this is broken with vhd, skip for now (XCPNG-2631) |
| 91 | + size_mb = int(vm.host.ssh(f'du -sm {image_path}').split()[0]) |
| 92 | + assert 400 < size_mb < 410, f"unexpected image size: {size_mb}" |
| 93 | + vdi = sr.create_vdi(image_format=image_format) |
| 94 | + vm.host.xe('vdi-import', {'uuid': vdi.uuid, 'filename': image_path, 'format': image_format}) |
| 95 | + vm.connect_vdi(vdi, 'xvdb') |
| 96 | + vm.ssh("randstream validate -v --size 200MiB --expected-checksum c6310c52 /dev/xvdb") |
| 97 | + vm.ssh("randstream validate -v --position 500MiB --size 200MiB --expected-checksum 1cb4218e /dev/xvdb") |
| 98 | + finally: |
| 99 | + if vdi is not None: |
| 100 | + vm.disconnect_vdi(vdi) |
| 101 | + vdi.destroy() |
| 102 | + vm.host.ssh(f'rm -f {image_path}') |
| 103 | + |
71 | 104 | # *** tests with reboots (longer tests). |
72 | 105 |
|
73 | 106 | @pytest.mark.reboot |
|
0 commit comments