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
16 changes: 14 additions & 2 deletions tests/storage/ext/test_ext_sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ 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)
Expand All @@ -47,6 +52,13 @@ def test_quicktest(self, ext_sr):
def test_vdi_is_not_open(self, vdi_on_ext_sr):
assert not vdi_is_open(vdi_on_ext_sr)

def test_vdi_image_format(self, vdi_on_ext_sr: VDI, image_format: str):
fmt = vdi_on_ext_sr.get_image_format()
# feature-detect: if the SM doesn't report image-format, skip this check
if not fmt:
pytest.skip("SM does not report sm-config:image-format; skipping format check")
assert fmt == image_format

@pytest.mark.small_vm # run with a small VM to test the features
@pytest.mark.big_vm # and ideally with a big VM to test it scales
def test_start_and_shutdown_VM(self, vm_on_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
16 changes: 14 additions & 2 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,10 +24,14 @@ 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)
Expand All @@ -42,6 +47,13 @@ def test_quicktest(self, largeblock_sr):
def test_vdi_is_not_open(self, vdi_on_largeblock_sr):
assert not vdi_is_open(vdi_on_largeblock_sr)

def test_vdi_image_format(self, vdi_on_largeblock_sr: VDI, image_format: str):
fmt = vdi_on_largeblock_sr.get_image_format()
# feature-detect: if the SM doesn't report image-format, skip this check
if not fmt:
pytest.skip("SM does not report sm-config:image-format; skipping format check")
assert fmt == image_format

@pytest.mark.small_vm # run with a small VM to test the features
@pytest.mark.big_vm # and ideally with a big VM to test it scales
def test_start_and_shutdown_VM(self, vm_on_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
17 changes: 15 additions & 2 deletions tests/storage/lvm/test_lvm_sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ 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)
Expand All @@ -47,6 +53,13 @@ def test_quicktest(self, lvm_sr):
def test_vdi_is_not_open(self, vdi_on_lvm_sr):
assert not vdi_is_open(vdi_on_lvm_sr)

def test_vdi_image_format(self, vdi_on_lvm_sr: VDI, image_format: str):
fmt = vdi_on_lvm_sr.get_image_format()
# feature-detect: if the SM doesn't report image-format, skip this check
if not fmt:
pytest.skip("SM does not report sm-config:image-format; skipping format check")
assert fmt == image_format

@pytest.mark.small_vm # run with a small VM to test the features
@pytest.mark.big_vm # and ideally with a big VM to test it scales
def test_start_and_shutdown_VM(self, vm_on_lvm_sr):
Expand Down
14 changes: 11 additions & 3 deletions tests/storage/xfs/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
from lib.host import Host
from lib.sr import SR

# 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 host_with_xfsprogs(host):
def host_with_xfsprogs(host: Host, image_format: str):
assert not host.file_exists('/usr/sbin/mkfs.xfs'), \
"xfsprogs must not be installed on the host at the beginning of the tests"
host.yum_save_state()
Expand All @@ -21,11 +25,15 @@ def host_with_xfsprogs(host):
host.yum_restore_saved_state()

@pytest.fixture(scope='package')
def xfs_sr(unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]], host_with_xfsprogs: Host
def xfs_sr(unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]],
host_with_xfsprogs: Host,
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
sr.destroy()
Expand Down
16 changes: 14 additions & 2 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 Down Expand Up @@ -65,6 +70,13 @@ def test_quicktest(self, xfs_sr):
def test_vdi_is_not_open(self, vdi_on_xfs_sr):
assert not vdi_is_open(vdi_on_xfs_sr)

def test_vdi_image_format(self, vdi_on_xfs_sr: VDI, image_format: str):
fmt = vdi_on_xfs_sr.get_image_format()
# feature-detect: if the SM doesn't report image-format, skip this check
if not fmt:
pytest.skip("SM does not report sm-config:image-format; skipping format check")
assert fmt == image_format

@pytest.mark.small_vm # run with a small VM to test the features
@pytest.mark.big_vm # and ideally with a big VM to test it scales
def test_start_and_shutdown_VM(self, vm_on_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
29 changes: 25 additions & 4 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,23 +29,29 @@ 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)
Expand All @@ -53,6 +67,13 @@ def test_quicktest(self, zfs_sr):
def test_vdi_is_not_open(self, vdi_on_zfs_sr):
assert not vdi_is_open(vdi_on_zfs_sr)

def test_vdi_image_format(self, vdi_on_zfs_sr: VDI, image_format: str):
fmt = vdi_on_zfs_sr.get_image_format()
# feature-detect: if the SM doesn't report image-format, skip this check
if not fmt:
pytest.skip("SM does not report sm-config:image-format; skipping format check")
assert fmt == image_format

@pytest.mark.small_vm # run with a small VM to test the features
@pytest.mark.big_vm # and ideally with a big VM to test it scales
def test_start_and_shutdown_VM(self, vm_on_zfs_sr):
Expand Down