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