Skip to content
Open
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
9 changes: 7 additions & 2 deletions tests/storage/ext/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@
from lib.sr import SR

@pytest.fixture(scope='package')
def ext_sr(host: Host, unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]]) -> Generator[SR]:
def ext_sr(host: Host,
unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]],
image_format: str
) -> Generator[SR]:
""" An EXT SR on first host. """
sr_disk = unused_512B_disks[host][0]["name"]
sr = host.sr_create('ext', "EXT-local-SR-test", {'device': '/dev/' + sr_disk})
sr = host.sr_create('ext', "EXT-local-SR-test",
{'device': '/dev/' + sr_disk,
'preferred-image-formats': image_format})
yield sr
# teardown
sr.destroy()
Expand Down
21 changes: 18 additions & 3 deletions tests/storage/ext/test_ext_sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,32 @@ class TestEXTSRCreateDestroy:
def test_create_sr_with_missing_device(self, host):
try_to_create_sr_with_missing_device('ext', 'EXT-local-SR-test', host)

def test_create_and_destroy_sr(self, host: Host, unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]]) -> None:
def test_create_and_destroy_sr(self, host: Host,
unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]],
image_format: str
) -> None:
# Create and destroy tested in the same test to leave the host as unchanged as possible
sr_disk = unused_512B_disks[host][0]["name"]
sr = host.sr_create('ext', "EXT-local-SR-test", {'device': '/dev/' + sr_disk}, verify=True)
sr = host.sr_create('ext', "EXT-local-SR-test",
{'device': '/dev/' + sr_disk,
'preferred-image-formats': image_format}, verify=True)
# import a VM in order to detect vm import issues here rather than in the vm_on_xfs_fixture used in
# the next tests, because errors in fixtures break teardown
vm = host.import_vm(vm_image('mini-linux-x86_64-bios'), sr_uuid=sr.uuid)
vm.destroy(verify=True)
sr.destroy(verify=True)

@pytest.mark.usefixtures("ext_sr")
# We want to skip class tests for qcow2 if the SM does not support qcow2
@pytest.fixture(scope="class")
def for_qcow2_vdi_image_format(vdi_on_ext_sr: VDI, image_format: str):
# only check qcow2-specific behavior
if image_format != "qcow2":
return
# feature-detect: if the SM doesn't report image-format, skip this check
if not vdi_on_ext_sr.get_image_format():
pytest.skip("SM does not report sm-config:image-format; skipping qcow2 format check")

@pytest.mark.usefixtures("for_qcow2_vdi_image_format", "ext_sr")
class TestEXTSR:
@pytest.mark.quicktest
def test_quicktest(self, ext_sr):
Expand Down
8 changes: 6 additions & 2 deletions tests/storage/largeblock/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
from lib.sr import SR

@pytest.fixture(scope='package')
def largeblock_sr(host: Host, unused_4k_disks: dict[Host, list[Host.BlockDeviceInfo]]) -> Generator[SR]:
def largeblock_sr(host: Host,
unused_4k_disks: dict[Host, list[Host.BlockDeviceInfo]],
image_format: str) -> Generator[SR]:
""" A LARGEBLOCK SR on first host. """
sr_disk = unused_4k_disks[host][0]["name"]
sr = host.sr_create('largeblock', "LARGEBLOCK-local-SR-test", {'device': '/dev/' + sr_disk})
sr = host.sr_create('largeblock', "LARGEBLOCK-local-SR-test",
{'device': '/dev/' + sr_disk,
'preferred-image-formats': image_format})
yield sr
# teardown
sr.destroy()
Expand Down
21 changes: 18 additions & 3 deletions tests/storage/largeblock/test_largeblock_sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

if TYPE_CHECKING:
from lib.host import Host
from lib.vdi import VDI

# Requirements:
# - one XCP-ng host with an additional unused 4KiB disk for the SR
Expand All @@ -23,17 +24,31 @@ class TestLARGEBLOCKSRCreateDestroy:
def test_create_sr_with_missing_device(self, host):
try_to_create_sr_with_missing_device('largeblock', 'LARGEBLOCK-local-SR-test', host)

def test_create_and_destroy_sr(self, host: Host, unused_4k_disks: dict[Host, list[Host.BlockDeviceInfo]]) -> None:
def test_create_and_destroy_sr(self, host: Host,
unused_4k_disks: dict[Host, list[Host.BlockDeviceInfo]],
image_format: str) -> None:
# Create and destroy tested in the same test to leave the host as unchanged as possible
sr_disk = unused_4k_disks[host][0]["name"]
sr = host.sr_create('largeblock', "LARGEBLOCK-local-SR-test", {'device': '/dev/' + sr_disk}, verify=True)
sr = host.sr_create('largeblock', "LARGEBLOCK-local-SR-test",
{'device': '/dev/' + sr_disk,
'preferred-image-formats': image_format}, verify=True)
# import a VM in order to detect vm import issues here rather than in the vm_on_xfs_fixture used in
# the next tests, because errors in fixtures break teardown
vm = host.import_vm(vm_image('mini-linux-x86_64-bios'), sr_uuid=sr.uuid)
vm.destroy(verify=True)
sr.destroy(verify=True)

@pytest.mark.usefixtures("largeblock_sr")
# We want to skip class tests for qcow2 if the SM does not support qcow2
@pytest.fixture(scope="class")
def for_qcow2_vdi_image_format(vdi_on_largeblock_sr: VDI, image_format: str):
# only check qcow2-specific behavior
if image_format != "qcow2":
return
# feature-detect: if the SM doesn't report image-format, skip this check
if not vdi_on_largeblock_sr.get_image_format():
pytest.skip("SM does not report sm-config:image-format; skipping qcow2 format check")

@pytest.mark.usefixtures("for_qcow2_vdi_image_format", "largeblock_sr")
class TestLARGEBLOCKSR:
@pytest.mark.quicktest
def test_quicktest(self, largeblock_sr):
Expand Down
9 changes: 7 additions & 2 deletions tests/storage/lvm/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@
from lib.sr import SR

@pytest.fixture(scope='package')
def lvm_sr(host: Host, unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]]) -> Generator[SR]:
def lvm_sr(host: Host,
unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]],
image_format: str
) -> Generator[SR]:
""" An LVM SR on first host. """
sr_disk = unused_512B_disks[host][0]["name"]
sr = host.sr_create('lvm', "LVM-local-SR-test", {'device': '/dev/' + sr_disk})
sr = host.sr_create('lvm', "LVM-local-SR-test",
{'device': '/dev/' + sr_disk,
'preferred-image-formats': image_format})
yield sr
# teardown
sr.destroy()
Expand Down
22 changes: 19 additions & 3 deletions tests/storage/lvm/test_lvm_sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,33 @@ class TestLVMSRCreateDestroy:
def test_create_sr_with_missing_device(self, host):
try_to_create_sr_with_missing_device('lvm', 'LVM-local-SR-test', host)

def test_create_and_destroy_sr(self, host: Host, unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]]) -> None:
def test_create_and_destroy_sr(self, host: Host,
unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]],
image_format: str
) -> None:
sr_disk = unused_512B_disks[host][0]["name"]
# Create and destroy tested in the same test to leave the host as unchanged as possible
sr = host.sr_create('lvm', "LVM-local-SR-test", {'device': '/dev/' + sr_disk}, verify=True)
sr = host.sr_create('lvm', "LVM-local-SR-test", {
'device': '/dev/' + sr_disk,
'preferred-image-formats': image_format
}, verify=True)
# import a VM in order to detect vm import issues here rather than in the vm_on_xfs_fixture used in
# the next tests, because errors in fixtures break teardown
vm = host.import_vm(vm_image('mini-linux-x86_64-bios'), sr_uuid=sr.uuid)
vm.destroy(verify=True)
sr.destroy(verify=True)

@pytest.mark.usefixtures("lvm_sr")
# We want to skip class tests for qcow2 if the SM does not support qcow2
@pytest.fixture(scope="class")
def for_qcow2_vdi_image_format(vdi_on_lvm_sr: VDI, image_format: str):
# only check qcow2-specific behavior
if image_format != "qcow2":
return
# feature-detect: if the SM doesn't report image-format, skip this check
if not vdi_on_lvm_sr.get_image_format():
pytest.skip("SM does not report sm-config:image-format; skipping qcow2 format check")

@pytest.mark.usefixtures("for_qcow2_vdi_image_format", "lvm_sr")
class TestLVMSR:
@pytest.mark.quicktest
def test_quicktest(self, lvm_sr):
Expand Down
10 changes: 9 additions & 1 deletion tests/storage/xfs/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
class XfsConfig:
uninstall_xfs: bool = True

# NOTE: @pytest.mark.usefixtures does not parametrize this fixture.
# To recreate host_with_xfsprogs for each image_format value, accept
# image_format in the fixture arguments.
# ref https://docs.pytest.org/en/7.1.x/how-to/fixtures.html#use-fixtures-in-classes-and-modules-with-usefixtures

@pytest.fixture(scope='package')
def _xfs_config() -> XfsConfig:
return XfsConfig()
Expand All @@ -37,10 +42,13 @@ def xfs_sr(
unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]],
host_with_xfsprogs: Host,
_xfs_config: XfsConfig,
image_format: str
) -> Generator[SR]:
""" A XFS SR on first host. """
sr_disk = unused_512B_disks[host_with_xfsprogs][0]["name"]
sr = host_with_xfsprogs.sr_create('xfs', "XFS-local-SR-test", {'device': '/dev/' + sr_disk})
sr = host_with_xfsprogs.sr_create('xfs', "XFS-local-SR-test",
{'device': '/dev/' + sr_disk,
'preferred-image-formats': image_format})
yield sr
# teardown
try:
Expand Down
21 changes: 18 additions & 3 deletions tests/storage/xfs/test_xfs_sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

if TYPE_CHECKING:
from lib.host import Host
from lib.vdi import VDI

# Requirements:
# - one XCP-ng host >= 8.2 with an additional unused disk for the SR
Expand All @@ -27,15 +28,19 @@ class TestXFSSRCreateDestroy:

def test_create_xfs_sr_without_xfsprogs(self,
host: Host,
unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]]
unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]],
image_format: str
) -> None:
# This test must be the first in the series in this module
assert not host.file_exists('/usr/sbin/mkfs.xfs'), \
"xfsprogs must not be installed on the host at the beginning of the tests"
sr_disk = unused_512B_disks[host][0]["name"]
sr = None
try:
sr = host.sr_create('xfs', "XFS-local-SR-test", {'device': '/dev/' + sr_disk})
sr = host.sr_create('xfs', "XFS-local-SR-test", {
'device': '/dev/' + sr_disk,
'preferred-image-formats': image_format
})
except Exception:
logging.info("SR creation failed, as expected.")
if sr is not None:
Expand All @@ -56,7 +61,17 @@ def test_create_and_destroy_sr(self,
vm.destroy(verify=True)
sr.destroy(verify=True)

@pytest.mark.usefixtures("xfs_sr")
# We want to skip class tests for qcow2 if the SM does not support qcow2
@pytest.fixture(scope="class")
def for_qcow2_vdi_image_format(vdi_on_xfs_sr: VDI, image_format: str):
# only check qcow2-specific behavior
if image_format != "qcow2":
return
# feature-detect: if the SM doesn't report image-format, skip this check
if not vdi_on_xfs_sr.get_image_format():
pytest.skip("SM does not report sm-config:image-format; skipping qcow2 format check")

@pytest.mark.usefixtures("for_qcow2_vdi_image_format", "xfs_sr")
class TestXFSSR:
@pytest.mark.quicktest
def test_quicktest(self, xfs_sr):
Expand Down
24 changes: 21 additions & 3 deletions tests/storage/zfs/conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
from __future__ import annotations

import pytest

import logging

# Explicitly import package-scoped fixtures (see explanation in pkgfixtures.py)
from pkgfixtures import host_with_saved_yum_state, sr_disk_wiped

from typing import TYPE_CHECKING, Generator

if TYPE_CHECKING:
from lib.host import Host
from lib.sr import SR

POOL_NAME = 'pool0'
POOL_PATH = '/' + POOL_NAME

Expand All @@ -13,8 +21,15 @@ def host_without_zfs(host):
assert not host.file_exists('/usr/sbin/zpool'), \
"zfs must not be installed on the host at the beginning of the tests"

# NOTE: @pytest.mark.usefixtures does not parametrize this fixture.
# To recreate host_with_zfs for each image_format value, accept
# image_format in the fixture arguments.
# ref https://docs.pytest.org/en/7.1.x/how-to/fixtures.html#use-fixtures-in-classes-and-modules-with-usefixtures
@pytest.fixture(scope='package')
def host_with_zfs(host_without_zfs, host_with_saved_yum_state):
def host_with_zfs(host_without_zfs: Host,
host_with_saved_yum_state: Host,
image_format: str
) -> Generator[Host]:
host = host_with_saved_yum_state
host.yum_install(['zfs'])
host.ssh(['modprobe', 'zfs'])
Expand All @@ -28,9 +43,12 @@ def zpool_vol0(sr_disk_wiped, host_with_zfs):
host_with_zfs.ssh(['zpool', 'destroy', POOL_NAME])

@pytest.fixture(scope='package')
def zfs_sr(host, zpool_vol0):
def zfs_sr(host: Host, image_format: str, zpool_vol0: None) -> Generator[SR]:
""" A ZFS SR on first host. """
sr = host.sr_create('zfs', "ZFS-local-SR-test", {'location': POOL_PATH})
sr = host.sr_create('zfs', "ZFS-local-SR-test", {
'location': POOL_PATH,
'preferred-image-formats': image_format
}, verify=True)
yield sr
# teardown
sr.destroy()
Expand Down
34 changes: 29 additions & 5 deletions tests/storage/zfs/test_zfs_sr.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

import logging
Expand All @@ -7,6 +9,12 @@
from lib.common import vm_image, wait_for
from tests.storage import vdi_is_open

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from lib.host import Host
from lib.vdi import VDI

from .conftest import POOL_NAME, POOL_PATH

# Requirements:
Expand All @@ -21,30 +29,46 @@ class TestZFSSRCreateDestroy:
and VM import.
"""

def test_create_zfs_sr_without_zfs(self, host):
def test_create_zfs_sr_without_zfs(self, host: Host, image_format: str) -> None:
# This test must be the first in the series in this module
assert not host.file_exists('/usr/sbin/zpool'), \
"zfs must not be installed on the host at the beginning of the tests"
sr = None
try:
sr = host.sr_create('zfs', "ZFS-local-SR-test", {'location': POOL_PATH})
sr = host.sr_create('zfs', "ZFS-local-SR-test", {
'location': POOL_PATH,
'preferred-image-formats': image_format
}, verify=True)
except Exception:
logging.info("SR creation failed, as expected.")
if sr is not None:
sr.destroy()
assert False, "SR creation should not have succeeded!"

@pytest.mark.usefixtures("zpool_vol0")
def test_create_and_destroy_sr(self, host):
def test_create_and_destroy_sr(self, host: Host, image_format: str) -> None:
# Create and destroy tested in the same test to leave the host as unchanged as possible
sr = host.sr_create('zfs', "ZFS-local-SR-test", {'location': POOL_PATH}, verify=True)
sr = host.sr_create('zfs', "ZFS-local-SR-test", {
'location': POOL_PATH,
'preferred-image-formats': image_format
}, verify=True)
# import a VM in order to detect vm import issues here rather than in the vm_on_xfs_fixture used in
# the next tests, because errors in fixtures break teardown
vm = host.import_vm(vm_image('mini-linux-x86_64-bios'), sr_uuid=sr.uuid)
vm.destroy(verify=True)
sr.destroy(verify=True)

@pytest.mark.usefixtures("zpool_vol0")
# We want to skip class tests for qcow2 if the SM does not support qcow2
@pytest.fixture(scope="class")
def for_qcow2_vdi_image_format(vdi_on_zfs_sr: VDI, image_format: str):
# only check qcow2-specific behavior
if image_format != "qcow2":
return
# feature-detect: if the SM doesn't report image-format, skip this check
if not vdi_on_zfs_sr.get_image_format():
pytest.skip("SM does not report sm-config:image-format; skipping qcow2 format check")

@pytest.mark.usefixtures("for_qcow2_vdi_image_format", "zpool_vol0")
class TestZFSSR:
@pytest.mark.quicktest
def test_quicktest(self, zfs_sr):
Expand Down