Skip to content

Commit 92c11bb

Browse files
committed
zfsvol: add vdi export/import test
Signed-off-by: Gaëtan Lehmann <[email protected]>
1 parent fb3e45b commit 92c11bb

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/storage/zfsvol/test_zfsvol_sr.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44

55
from lib.common import vm_image, wait_for
6+
from lib.sr import SR
67
from lib.vdi import VDI
78
from lib.vm import VM
89
from tests.storage.storage import install_randstream
@@ -111,6 +112,38 @@ def test_xva_export_import(self, vm_on_zfsvol_sr: VM, compression):
111112
imported_vm.destroy()
112113
vm.host.ssh(f'rm -f {xva_path}')
113114

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

116149
@pytest.mark.reboot

0 commit comments

Comments
 (0)