Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions tests/storage/ext/test_ext_sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging

from lib.commands import SSHCommandFailed
from lib.common import vm_image, wait_for
from lib.common import Defer, vm_image, wait_for
from lib.fistpoint import FistPoint
from lib.host import Host
from lib.sr import SR
Expand Down Expand Up @@ -87,17 +87,17 @@ def test_snapshot(self, vm_on_ext_sr: VM) -> None:

@pytest.mark.small_vm
@pytest.mark.parametrize("vdi_op", ["snapshot", "clone"])
def test_coalesce(self, storage_test_vm: VM, vdi_on_ext_sr: VDI, vdi_op: CoalesceOperation) -> None:
coalesce_integrity(storage_test_vm, vdi_on_ext_sr, vdi_op)
def test_coalesce(self, storage_test_vm: VM, vdi_on_ext_sr: VDI, vdi_op: CoalesceOperation, defer: Defer) -> None:
coalesce_integrity(storage_test_vm, vdi_on_ext_sr, vdi_op, defer)

@pytest.mark.small_vm
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
def test_xva_export_import(self, vm_on_ext_sr: VM, compression: XVACompression) -> None:
xva_export_import(vm_on_ext_sr, compression)
def test_xva_export_import(self, vm_on_ext_sr: VM, compression: XVACompression, defer: Defer) -> None:
xva_export_import(vm_on_ext_sr, compression, defer)

@pytest.mark.small_vm
def test_vdi_export_import(self, storage_test_vm: VM, ext_sr: SR, image_format: ImageFormat) -> None:
vdi_export_import(storage_test_vm, ext_sr, image_format)
def test_vdi_export_import(self, storage_test_vm: VM, ext_sr: SR, image_format: ImageFormat, defer: Defer) -> None:
vdi_export_import(storage_test_vm, ext_sr, image_format, defer)

# *** tests with reboots (longer tests).

Expand Down
14 changes: 7 additions & 7 deletions tests/storage/lvm/test_lvm_sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging

from lib.commands import SSHCommandFailed
from lib.common import vm_image, wait_for
from lib.common import Defer, vm_image, wait_for
from lib.fistpoint import FistPoint
from lib.host import Host
from lib.sr import SR
Expand Down Expand Up @@ -144,17 +144,17 @@ def test_failing_resize_on_inflate_after_setSizePhys(

@pytest.mark.small_vm
@pytest.mark.parametrize("vdi_op", ["snapshot", "clone"])
def test_coalesce(self, storage_test_vm: VM, vdi_on_lvm_sr: VDI, vdi_op: CoalesceOperation) -> None:
coalesce_integrity(storage_test_vm, vdi_on_lvm_sr, vdi_op)
def test_coalesce(self, storage_test_vm: VM, vdi_on_lvm_sr: VDI, vdi_op: CoalesceOperation, defer: Defer) -> None:
coalesce_integrity(storage_test_vm, vdi_on_lvm_sr, vdi_op, defer)

@pytest.mark.small_vm
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
def test_xva_export_import(self, vm_on_lvm_sr: VM, compression: XVACompression) -> None:
xva_export_import(vm_on_lvm_sr, compression)
def test_xva_export_import(self, vm_on_lvm_sr: VM, compression: XVACompression, defer: Defer) -> None:
xva_export_import(vm_on_lvm_sr, compression, defer)

@pytest.mark.small_vm
def test_vdi_export_import(self, storage_test_vm: VM, lvm_sr: SR, image_format: ImageFormat) -> None:
vdi_export_import(storage_test_vm, lvm_sr, image_format)
def test_vdi_export_import(self, storage_test_vm: VM, lvm_sr: SR, image_format: ImageFormat, defer: Defer) -> None:
vdi_export_import(storage_test_vm, lvm_sr, image_format, defer)

# *** tests with reboots (longer tests).

Expand Down
16 changes: 9 additions & 7 deletions tests/storage/lvmoiscsi/test_lvmoiscsi_sr.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from lib.common import vm_image, wait_for
from lib.common import Defer, vm_image, wait_for
from lib.host import Host
from lib.sr import SR
from lib.vdi import VDI, ImageFormat
Expand Down Expand Up @@ -69,17 +69,19 @@ def test_snapshot(self, vm_on_lvmoiscsi_sr: VM) -> None:

@pytest.mark.small_vm
@pytest.mark.parametrize("vdi_op", ["snapshot", "clone"])
def test_coalesce(self, storage_test_vm: VM, vdi_on_lvmoiscsi_sr: VDI, vdi_op: CoalesceOperation) -> None:
coalesce_integrity(storage_test_vm, vdi_on_lvmoiscsi_sr, vdi_op)
def test_coalesce(self, storage_test_vm: 'VM', vdi_on_lvmoiscsi_sr: 'VDI', vdi_op: CoalesceOperation,
defer: Defer) -> None:
coalesce_integrity(storage_test_vm, vdi_on_lvmoiscsi_sr, vdi_op, defer)

@pytest.mark.small_vm
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
def test_xva_export_import(self, vm_on_lvmoiscsi_sr: VM, compression: XVACompression) -> None:
xva_export_import(vm_on_lvmoiscsi_sr, compression)
def test_xva_export_import(self, vm_on_lvmoiscsi_sr: VM, compression: XVACompression, defer: Defer) -> None:
xva_export_import(vm_on_lvmoiscsi_sr, compression, defer)

@pytest.mark.small_vm
def test_vdi_export_import(self, storage_test_vm: VM, lvmoiscsi_sr: SR, image_format: ImageFormat) -> None:
vdi_export_import(storage_test_vm, lvmoiscsi_sr, image_format)
def test_vdi_export_import(self, storage_test_vm: VM, lvmoiscsi_sr: SR, image_format: ImageFormat, defer: Defer) \
-> None:
vdi_export_import(storage_test_vm, lvmoiscsi_sr, image_format, defer)

# *** tests with reboots (longer tests).

Expand Down
15 changes: 8 additions & 7 deletions tests/storage/nfs/test_nfs_sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

from lib.commands import SSHCommandFailed
from lib.common import vm_image, wait_for
from lib.common import Defer, vm_image, wait_for
from lib.host import Host
from lib.sr import SR
from lib.vdi import VDI
Expand Down Expand Up @@ -116,21 +116,22 @@ def test_snapshot(self, dispatch_nfs: VM) -> None:
@pytest.mark.small_vm
@pytest.mark.parametrize('dispatch_nfs', ['vdi_on_nfs_sr', 'vdi_on_nfs4_sr'], indirect=True)
@pytest.mark.parametrize('vdi_op', ['snapshot', 'clone'])
def test_coalesce(self, storage_test_vm: VM, dispatch_nfs: VDI, vdi_op: CoalesceOperation) -> None:
coalesce_integrity(storage_test_vm, dispatch_nfs, vdi_op)
def test_coalesce(self, storage_test_vm: VM, dispatch_nfs: VDI, vdi_op: CoalesceOperation, defer: Defer) -> None:
coalesce_integrity(storage_test_vm, dispatch_nfs, vdi_op, defer)

@pytest.mark.small_vm
# Make sure this fixture is called before the parametrized one
@pytest.mark.usefixtures('vm_ref')
@pytest.mark.parametrize('dispatch_nfs', ['vm_on_nfs_sr', 'vm_on_nfs4_sr'], indirect=True)
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
def test_xva_export_import(self, dispatch_nfs: VM, compression: XVACompression) -> None:
xva_export_import(dispatch_nfs, compression)
def test_xva_export_import(self, dispatch_nfs: VM, compression: XVACompression, defer: Defer) -> None:
xva_export_import(dispatch_nfs, compression, defer)

@pytest.mark.small_vm
@pytest.mark.parametrize('dispatch_nfs', ['nfs_sr', 'nfs4_sr'], indirect=True)
def test_vdi_export_import(self, storage_test_vm: VM, dispatch_nfs: SR, image_format: ImageFormat) -> None:
vdi_export_import(storage_test_vm, dispatch_nfs, image_format)
def test_vdi_export_import(self, storage_test_vm: VM, dispatch_nfs: SR, image_format: ImageFormat, defer: Defer) \
-> None:
vdi_export_import(storage_test_vm, dispatch_nfs, image_format, defer)

# *** tests with reboots (longer tests).

Expand Down
135 changes: 71 additions & 64 deletions tests/storage/storage.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import annotations

import pytest

import logging

from lib.commands import SSHCommandFailed
from lib.common import GiB, strtobool, wait_for, wait_for_not
from lib.common import Defer, GiB, strtobool, wait_for, wait_for_not
from lib.host import Host
from lib.sr import SR
from lib.vdi import VDI, ImageFormat
Expand Down Expand Up @@ -179,82 +181,87 @@ def install_randstream(vm: VM) -> None:

CoalesceOperation = Literal['snapshot', 'clone']

def coalesce_integrity(vm: VM, vdi: VDI, vdi_op: CoalesceOperation) -> None:
def coalesce_integrity(vm: VM, vdi: VDI, vdi_op: CoalesceOperation, defer: Defer) -> None:
vbd = vm.connect_vdi(vdi)
defer(lambda: vm.disconnect_vdi(vdi))

dev = f'/dev/{vbd.param_get("device")}'
vm.ssh(f"randstream generate -v {dev}")
# default seed is 0
vm.ssh(f"randstream validate -v --expected-checksum 65280014 {dev}")
new_vdi: VDI | None = None
try:
vm.ssh(f"randstream generate -v {dev}")
# default seed is 0
vm.ssh(f"randstream validate -v --expected-checksum 65280014 {dev}")
match vdi_op:
case 'clone': new_vdi = vdi.clone()
case 'snapshot': new_vdi = vdi.snapshot()
vm.ssh(f"randstream generate -v --seed 1 --size 128Mi {dev}")
vm.ssh(f"randstream validate -v --expected-checksum ad2ca9af {dev}")
new_vdi = vdi.wait_for_coalesce(new_vdi.destroy)
vm.ssh(f"randstream validate -v --expected-checksum ad2ca9af {dev}")
finally:
vm.disconnect_vdi(vdi)
if new_vdi is not None:
new_vdi.destroy()
match vdi_op:
case 'clone': new_vdi = vdi.clone()
case 'snapshot': new_vdi = vdi.snapshot()
defer(lambda: new_vdi.destroy() if new_vdi is not None else None)
assert vdi is not None

vm.ssh(f"randstream generate -v --seed 1 --size 128Mi {dev}")
vm.ssh(f"randstream validate -v --expected-checksum ad2ca9af {dev}")
new_vdi = vdi.wait_for_coalesce(new_vdi.destroy)
vm.ssh(f"randstream validate -v --expected-checksum ad2ca9af {dev}")

XVACompression = Literal['none', 'gzip', 'zstd']

def xva_export_import(vm: VM, compression: XVACompression) -> None:
def xva_export_import(vm: VM, compression: XVACompression, defer: Defer) -> None:
# The tests using this function are using specific fixtures to create the VM on the expected SR
# In consequence, we can't use the storage_test_vm, so we have to start the VM explicitly and install randstream
vm.start()
vm.wait_for_vm_running_and_ssh_up()
install_randstream(vm)

# 500MiB, so we have some data to check and some empty spaces in the exported image
vm.ssh("randstream generate -v --size 500MiB /root/data")
vm.ssh("randstream validate -v --expected-checksum 24e905d6 /root/data")
vm.shutdown(verify=True)

xva_path = f'/tmp/{vm.uuid}.xva'
imported_vm = None
try:
vm.export(xva_path, compression)
# check that the zero blocks are not part of the result. Most of the data is from the random stream, so
# compression has little effect. We just check the result is between 500 and 700 MiB
size_mb = int(vm.host.ssh(f'du -sm --apparent-size {xva_path}').split()[0])
assert 500 < size_mb < 700, f"unexpected xva size: {size_mb}"
imported_vm = vm.host.import_vm(xva_path, vm.vdis[0].sr.uuid)
imported_vm.start()
imported_vm.wait_for_vm_running_and_ssh_up()
imported_vm.ssh("randstream validate -v --expected-checksum 24e905d6 /root/data")
finally:
if imported_vm is not None:
imported_vm.destroy()
vm.host.ssh(f'rm -f {xva_path}')

def vdi_export_import(vm: VM, sr: SR, image_format: ImageFormat) -> None:
vdi: VDI | None = sr.create_vdi(image_format=image_format)
assert vdi is not None
image_path = f'/tmp/{vdi.uuid}.{image_format}'
try:
vbd = vm.connect_vdi(vdi)
dev = f'/dev/{vbd.param_get("device")}'
# generate 2 blocks of data of 200MiB, at position 0 and at position 500MiB
vm.ssh(f"randstream generate -v --size 200MiB {dev}")
# use a different seed to not write the same data (default seed is 0)
vm.ssh(f"randstream generate -v --seed 1 --position 500MiB --size 200MiB {dev}")
vm.ssh(f"randstream validate -v --size 200MiB --expected-checksum c6310c52 {dev}")
vm.ssh(f"randstream validate -v --position 500MiB --size 200MiB --expected-checksum 1cb4218e {dev}")
vm.disconnect_vdi(vdi)
vm.host.xe('vdi-export', {'uuid': vdi.uuid, 'filename': image_path, 'format': image_format})
vdi.destroy()
vdi = None
# check that the zero blocks are not part of the result
size_mb = int(vm.host.ssh(f'du -sm --apparent-size {image_path}').split()[0])
assert 400 < size_mb < 410, f"unexpected image size: {size_mb}"
vdi = sr.create_vdi(image_format=image_format)
vm.host.xe('vdi-import', {'uuid': vdi.uuid, 'filename': image_path, 'format': image_format})
vm.connect_vdi(vdi, 'xvdb')
vm.ssh(f"randstream validate -v --size 200MiB --expected-checksum c6310c52 {dev}")
vm.ssh(f"randstream validate -v --position 500MiB --size 200MiB --expected-checksum 1cb4218e {dev}")
finally:
if vdi is not None:
vm.disconnect_vdi(vdi)
vdi.destroy()
vm.host.ssh(f'rm -f {image_path}')
defer(lambda: vm.host.ssh(f'rm -f {xva_path}'))
vm.export(xva_path, compression)
# check that the zero blocks are not part of the result. Most of the data is from the random stream, so
# compression has little effect. We just check the result is between 500 and 700 MiB
size_mb = int(vm.host.ssh(f'du -sm --apparent-size {xva_path}').split()[0])
assert 500 < size_mb < 700, f"unexpected xva size: {size_mb}"

imported_vm = vm.host.import_vm(xva_path, vm.vdis[0].sr.uuid)
defer(lambda: imported_vm.destroy())
imported_vm.start()
imported_vm.wait_for_vm_running_and_ssh_up()
imported_vm.ssh("randstream validate -v --expected-checksum 24e905d6 /root/data")

def vdi_export_import(vm: VM, sr: SR, image_format: ImageFormat, defer: Defer) -> None:
vdi_src: VDI | None = sr.create_vdi(image_format=image_format)
defer(lambda: vdi_src.destroy() if vdi_src is not None else None)
assert vdi_src is not None

vbd = vm.connect_vdi(vdi_src)
defer(lambda: vm.disconnect_vdi(vdi_src) if vdi_src is not None and vdi_src.uuid in vm.vdis else None)
dev = f'/dev/{vbd.param_get("device")}'

# generate 2 blocks of data of 200MiB, at position 0 and at position 500MiB
vm.ssh(f"randstream generate -v --size 200MiB {dev}")
# use a different seed to not write the same data (default seed is 0)
vm.ssh(f"randstream generate -v --seed 1 --position 500MiB --size 200MiB {dev}")
vm.ssh(f"randstream validate -v --size 200MiB --expected-checksum c6310c52 {dev}")
vm.ssh(f"randstream validate -v --position 500MiB --size 200MiB --expected-checksum 1cb4218e {dev}")
vm.disconnect_vdi(vdi_src)

image_path = f'/tmp/{vdi_src.uuid}.{image_format}'
defer(lambda: vm.host.ssh(f'rm -f {image_path}'))

vm.host.xe('vdi-export', {'uuid': vdi_src.uuid, 'filename': image_path, 'format': image_format})
vdi_src.destroy()
vdi_src = None

# check that the zero blocks are not part of the result
size_mb = int(vm.host.ssh(f'du -sm --apparent-size {image_path}').split()[0])
assert 400 < size_mb < 410, f"unexpected image size: {size_mb}"
vdi_dest = sr.create_vdi(image_format=image_format)
defer(lambda: vdi_dest.destroy())

vm.host.xe('vdi-import', {'uuid': vdi_dest.uuid, 'filename': image_path, 'format': image_format})
vm.connect_vdi(vdi_dest, 'xvdb')
defer(lambda: vm.disconnect_vdi(vdi_dest))

vm.ssh(f"randstream validate -v --size 200MiB --expected-checksum c6310c52 {dev}")
vm.ssh(f"randstream validate -v --position 500MiB --size 200MiB --expected-checksum 1cb4218e {dev}")
14 changes: 7 additions & 7 deletions tests/storage/xfs/test_xfs_sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time

from lib.commands import SSHCommandFailed
from lib.common import vm_image, wait_for
from lib.common import Defer, vm_image, wait_for
from lib.host import Host
from lib.sr import SR
from lib.vdi import VDI
Expand Down Expand Up @@ -104,17 +104,17 @@ def test_snapshot(self, vm_on_xfs_sr: VM) -> None:

@pytest.mark.small_vm
@pytest.mark.parametrize("vdi_op", ["snapshot", "clone"])
def test_coalesce(self, storage_test_vm: VM, vdi_on_xfs_sr: VDI, vdi_op: CoalesceOperation) -> None:
coalesce_integrity(storage_test_vm, vdi_on_xfs_sr, vdi_op)
def test_coalesce(self, storage_test_vm: VM, vdi_on_xfs_sr: VDI, vdi_op: CoalesceOperation, defer: Defer) -> None:
coalesce_integrity(storage_test_vm, vdi_on_xfs_sr, vdi_op, defer)

@pytest.mark.small_vm
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
def test_xva_export_import(self, vm_on_xfs_sr: VM, compression: XVACompression) -> None:
xva_export_import(vm_on_xfs_sr, compression)
def test_xva_export_import(self, vm_on_xfs_sr: VM, compression: XVACompression, defer: Defer) -> None:
xva_export_import(vm_on_xfs_sr, compression, defer)

@pytest.mark.small_vm
def test_vdi_export_import(self, storage_test_vm: VM, xfs_sr: SR, image_format: ImageFormat) -> None:
vdi_export_import(storage_test_vm, xfs_sr, image_format)
def test_vdi_export_import(self, storage_test_vm: VM, xfs_sr: SR, image_format: ImageFormat, defer: Defer) -> None:
vdi_export_import(storage_test_vm, xfs_sr, image_format, defer)

# *** tests with reboots (longer tests).

Expand Down
14 changes: 7 additions & 7 deletions tests/storage/zfs/test_zfs_sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time

from lib.commands import SSHCommandFailed
from lib.common import vm_image, wait_for
from lib.common import Defer, vm_image, wait_for
from lib.host import Host
from lib.sr import SR
from lib.vdi import VDI
Expand Down Expand Up @@ -101,17 +101,17 @@ def test_snapshot(self, vm_on_zfs_sr: VM) -> None:

@pytest.mark.small_vm
@pytest.mark.parametrize("vdi_op", ["snapshot", "clone"])
def test_coalesce(self, storage_test_vm: VM, vdi_on_zfs_sr: VDI, vdi_op: CoalesceOperation) -> None:
coalesce_integrity(storage_test_vm, vdi_on_zfs_sr, vdi_op)
def test_coalesce(self, storage_test_vm: VM, vdi_on_zfs_sr: VDI, vdi_op: CoalesceOperation, defer: Defer) -> None:
coalesce_integrity(storage_test_vm, vdi_on_zfs_sr, vdi_op, defer)

@pytest.mark.small_vm
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
def test_xva_export_import(self, vm_on_zfs_sr: VM, compression: XVACompression) -> None:
xva_export_import(vm_on_zfs_sr, compression)
def test_xva_export_import(self, vm_on_zfs_sr: VM, compression: XVACompression, defer: Defer) -> None:
xva_export_import(vm_on_zfs_sr, compression, defer)

@pytest.mark.small_vm
def test_vdi_export_import(self, storage_test_vm: VM, zfs_sr: SR, image_format: ImageFormat) -> None:
vdi_export_import(storage_test_vm, zfs_sr, image_format)
def test_vdi_export_import(self, storage_test_vm: VM, zfs_sr: SR, image_format: ImageFormat, defer: Defer) -> None:
vdi_export_import(storage_test_vm, zfs_sr, image_format, defer)

# *** tests with reboots (longer tests).

Expand Down
Loading
Loading