|
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.storage import install_randstream |
@@ -111,6 +112,38 @@ def test_xva_export_import(self, vm_on_zfsvol_sr: VM, compression): |
111 | 112 | imported_vm.destroy() |
112 | 113 | vm.host.ssh(f'rm -f {xva_path}') |
113 | 114 |
|
| 115 | + @pytest.mark.small_vm |
| 116 | + def test_vdi_export_import(self, storage_test_vm: VM, zfsvol_sr: SR, image_format: str): |
| 117 | + vm = storage_test_vm |
| 118 | + sr = zfsvol_sr |
| 119 | + vdi = sr.create_vdi(image_format=image_format) |
| 120 | + image_path = f'/tmp/{vdi.uuid}.{image_format}' |
| 121 | + try: |
| 122 | + vm.connect_vdi(vdi, 'xvdb') |
| 123 | + # generate 2 blocks of data of 200MiB, at position 0 and at position 500MiB |
| 124 | + vm.ssh("randstream generate -v --size 200MiB /dev/xvdb") |
| 125 | + vm.ssh("randstream generate -v --seed 1 --position 500MiB --size 200MiB /dev/xvdb") |
| 126 | + vm.ssh("randstream validate -v --size 200MiB --expected-checksum c6310c52 /dev/xvdb") |
| 127 | + vm.ssh("randstream validate -v --position 500MiB --size 200MiB --expected-checksum 1cb4218e /dev/xvdb") |
| 128 | + vm.disconnect_vdi(vdi) |
| 129 | + vm.host.xe('vdi-export', {'uuid': vdi.uuid, 'filename': image_path, 'format': image_format}) |
| 130 | + vdi = vdi.destroy() |
| 131 | + # check that the zero blocks are not part of the result |
| 132 | + if image_format != 'vhd': |
| 133 | + # FIXME: this is broken with vhd, skip for now (XCPNG-2631) |
| 134 | + size_mb = int(vm.host.ssh(f'du -sm {image_path}').split()[0]) |
| 135 | + assert 400 < size_mb < 410, f"unexpected image size: {size_mb}" |
| 136 | + vdi = sr.create_vdi(image_format=image_format) |
| 137 | + vm.host.xe('vdi-import', {'uuid': vdi.uuid, 'filename': image_path, 'format': image_format}) |
| 138 | + vm.connect_vdi(vdi, 'xvdb') |
| 139 | + vm.ssh("randstream validate -v --size 200MiB --expected-checksum c6310c52 /dev/xvdb") |
| 140 | + vm.ssh("randstream validate -v --position 500MiB --size 200MiB --expected-checksum 1cb4218e /dev/xvdb") |
| 141 | + finally: |
| 142 | + if vdi is not None: |
| 143 | + vm.disconnect_vdi(vdi) |
| 144 | + vdi.destroy() |
| 145 | + vm.host.ssh(f'rm -f {image_path}') |
| 146 | + |
114 | 147 | # *** tests with reboots (longer tests). |
115 | 148 |
|
116 | 149 | @pytest.mark.reboot |
|
0 commit comments