Skip to content

Commit 6fe53b8

Browse files
committed
zfsvol: add vdi export/import test
Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
1 parent 28bb81b commit 6fe53b8

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 import CoalesceOperation, XVACompression, coalesce_integrity, xva_export_import
@@ -68,6 +69,38 @@ def test_coalesce(self, storage_test_vm: VM, vdi_on_zfsvol_sr: VDI, vdi_op: Coal
6869
def test_xva_export_import(self, vm_on_zfsvol_sr: VM, compression: XVACompression):
6970
xva_export_import(vm_on_zfsvol_sr, compression)
7071

72+
@pytest.mark.small_vm
73+
def test_vdi_export_import(self, storage_test_vm: VM, zfsvol_sr: SR, image_format: str):
74+
vm = storage_test_vm
75+
sr = zfsvol_sr
76+
vdi = sr.create_vdi(image_format=image_format)
77+
image_path = f'/tmp/{vdi.uuid}.{image_format}'
78+
try:
79+
vm.connect_vdi(vdi, 'xvdb')
80+
# generate 2 blocks of data of 200MiB, at position 0 and at position 500MiB
81+
vm.ssh("randstream generate -v --size 200MiB /dev/xvdb")
82+
vm.ssh("randstream generate -v --seed 1 --position 500MiB --size 200MiB /dev/xvdb")
83+
vm.ssh("randstream validate -v --size 200MiB --expected-checksum c6310c52 /dev/xvdb")
84+
vm.ssh("randstream validate -v --position 500MiB --size 200MiB --expected-checksum 1cb4218e /dev/xvdb")
85+
vm.disconnect_vdi(vdi)
86+
vm.host.xe('vdi-export', {'uuid': vdi.uuid, 'filename': image_path, 'format': image_format})
87+
vdi = vdi.destroy()
88+
# check that the zero blocks are not part of the result
89+
if image_format != 'vhd':
90+
# FIXME: this is broken with vhd, skip for now (XCPNG-2631)
91+
size_mb = int(vm.host.ssh(f'du -sm {image_path}').split()[0])
92+
assert 400 < size_mb < 410, f"unexpected image size: {size_mb}"
93+
vdi = sr.create_vdi(image_format=image_format)
94+
vm.host.xe('vdi-import', {'uuid': vdi.uuid, 'filename': image_path, 'format': image_format})
95+
vm.connect_vdi(vdi, 'xvdb')
96+
vm.ssh("randstream validate -v --size 200MiB --expected-checksum c6310c52 /dev/xvdb")
97+
vm.ssh("randstream validate -v --position 500MiB --size 200MiB --expected-checksum 1cb4218e /dev/xvdb")
98+
finally:
99+
if vdi is not None:
100+
vm.disconnect_vdi(vdi)
101+
vdi.destroy()
102+
vm.host.ssh(f'rm -f {image_path}')
103+
71104
# *** tests with reboots (longer tests).
72105

73106
@pytest.mark.reboot

0 commit comments

Comments
 (0)