Skip to content

Commit 26a1a1d

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

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/storage/zfsvol/test_zfsvol_sr.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import pytest
44

5+
import logging
6+
57
from lib.common import vm_image, wait_for
8+
from lib.sr import SR
69
from lib.vdi import VDI
710
from lib.vm import VM
811
from tests.storage import CoalesceOperation, XVACompression, coalesce_integrity, xva_export_import
@@ -68,6 +71,40 @@ def test_coalesce(self, storage_test_vm: VM, vdi_on_zfsvol_sr: VDI, vdi_op: Coal
6871
def test_xva_export_import(self, vm_on_zfsvol_sr: VM, compression: XVACompression):
6972
xva_export_import(vm_on_zfsvol_sr, compression)
7073

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

73110
@pytest.mark.reboot

0 commit comments

Comments
 (0)