Skip to content

Commit fb3e45b

Browse files
committed
zfs: add vdi export/import test
Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
1 parent 32f8df7 commit fb3e45b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/storage/zfs/test_zfs_sr.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from lib.commands import SSHCommandFailed
99
from lib.common import vm_image, wait_for
10+
from lib.sr import SR
1011
from lib.vdi import VDI
1112
from lib.vm import VM
1213
from tests.storage import vdi_is_open
@@ -130,6 +131,36 @@ def test_xva_export_import(self, vm_on_zfs_sr: VM, compression):
130131
imported_vm.destroy()
131132
vm.host.ssh(f'rm -f {xva_path}')
132133

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+
133164
# *** tests with reboots (longer tests).
134165

135166
@pytest.mark.reboot

0 commit comments

Comments
 (0)