|
7 | 7 |
|
8 | 8 | from lib.commands import SSHCommandFailed |
9 | 9 | from lib.common import vm_image, wait_for |
| 10 | +from lib.sr import SR |
10 | 11 | from lib.vdi import VDI |
11 | 12 | from lib.vm import VM |
12 | 13 | from tests.storage import vdi_is_open |
@@ -130,6 +131,36 @@ def test_xva_export_import(self, vm_on_zfs_sr: VM, compression): |
130 | 131 | imported_vm.destroy() |
131 | 132 | vm.host.ssh(f'rm -f {xva_path}') |
132 | 133 |
|
| 134 | + @pytest.mark.small_vm |
| 135 | + def test_vdi_export_import(self, storage_test_vm: VM, zfs_sr: SR, image_format: str): |
| 136 | + vm = storage_test_vm |
| 137 | + sr = zfs_sr |
| 138 | + vdi = sr.create_vdi(image_format=image_format) |
| 139 | + image_path = f'/tmp/{vdi.uuid}.{image_format}' |
| 140 | + try: |
| 141 | + vm.connect_vdi(vdi, 'xvdb') |
| 142 | + # generate 2 blocks of data of 200MiB, at position 0 and at position 500MiB |
| 143 | + vm.ssh("randstream generate -v --size 200MiB /dev/xvdb") |
| 144 | + vm.ssh("randstream generate -v --seed 1 --position 500MiB --size 200MiB /dev/xvdb") |
| 145 | + vm.ssh("randstream validate -v --size 200MiB --expected-checksum c6310c52 /dev/xvdb") |
| 146 | + vm.ssh("randstream validate -v --position 500MiB --size 200MiB --expected-checksum 1cb4218e /dev/xvdb") |
| 147 | + vm.disconnect_vdi(vdi) |
| 148 | + vm.host.xe('vdi-export', {'uuid': vdi.uuid, 'filename': image_path, 'format': image_format}) |
| 149 | + vdi = vdi.destroy() |
| 150 | + # check that the zero blocks are not part of the result |
| 151 | + size_mb = int(vm.host.ssh(f'du -sm {image_path}').split()[0]) |
| 152 | + assert 400 < size_mb < 410, f"unexpected image size: {size_mb}" |
| 153 | + vdi = sr.create_vdi(image_format=image_format) |
| 154 | + vm.host.xe('vdi-import', {'uuid': vdi.uuid, 'filename': image_path, 'format': image_format}) |
| 155 | + vm.connect_vdi(vdi, 'xvdb') |
| 156 | + vm.ssh("randstream validate -v --size 200MiB --expected-checksum c6310c52 /dev/xvdb") |
| 157 | + vm.ssh("randstream validate -v --position 500MiB --size 200MiB --expected-checksum 1cb4218e /dev/xvdb") |
| 158 | + finally: |
| 159 | + if vdi is not None: |
| 160 | + vm.disconnect_vdi(vdi) |
| 161 | + vdi.destroy() |
| 162 | + vm.host.ssh(f'rm -f {image_path}') |
| 163 | + |
133 | 164 | # *** tests with reboots (longer tests). |
134 | 165 |
|
135 | 166 | @pytest.mark.reboot |
|
0 commit comments