Skip to content

Commit 3840f13

Browse files
tests/storage/xfs: Updated xfs to handle both vhd and qcow2 vdi image format
Signed-off-by: Rushikesh Jadhav <rushikesh7@gmail.com>
1 parent 9e85115 commit 3840f13

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

tests/storage/xfs/conftest.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
class XfsConfig:
1818
uninstall_xfs: bool = True
1919

20+
# NOTE: @pytest.mark.usefixtures does not parametrize this fixture.
21+
# To recreate host_with_xfsprogs for each image_format value, accept
22+
# image_format in the fixture arguments.
23+
# ref https://docs.pytest.org/en/7.1.x/how-to/fixtures.html#use-fixtures-in-classes-and-modules-with-usefixtures
24+
2025
@pytest.fixture(scope='package')
2126
def _xfs_config() -> XfsConfig:
2227
return XfsConfig()
@@ -37,10 +42,13 @@ def xfs_sr(
3742
unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]],
3843
host_with_xfsprogs: Host,
3944
_xfs_config: XfsConfig,
45+
image_format: str
4046
) -> Generator[SR]:
4147
""" A XFS SR on first host. """
4248
sr_disk = unused_512B_disks[host_with_xfsprogs][0]["name"]
43-
sr = host_with_xfsprogs.sr_create('xfs', "XFS-local-SR-test", {'device': '/dev/' + sr_disk})
49+
sr = host_with_xfsprogs.sr_create('xfs', "XFS-local-SR-test",
50+
{'device': '/dev/' + sr_disk,
51+
'preferred-image-formats': image_format})
4452
yield sr
4553
# teardown
4654
try:

tests/storage/xfs/test_xfs_sr.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
if TYPE_CHECKING:
1515
from lib.host import Host
16+
from lib.vdi import VDI
1617

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

2829
def test_create_xfs_sr_without_xfsprogs(self,
2930
host: Host,
30-
unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]]
31+
unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]],
32+
image_format: str
3133
) -> None:
3234
# This test must be the first in the series in this module
3335
assert not host.file_exists('/usr/sbin/mkfs.xfs'), \
3436
"xfsprogs must not be installed on the host at the beginning of the tests"
3537
sr_disk = unused_512B_disks[host][0]["name"]
3638
sr = None
3739
try:
38-
sr = host.sr_create('xfs', "XFS-local-SR-test", {'device': '/dev/' + sr_disk})
40+
sr = host.sr_create('xfs', "XFS-local-SR-test", {
41+
'device': '/dev/' + sr_disk,
42+
'preferred-image-formats': image_format
43+
})
3944
except Exception:
4045
logging.info("SR creation failed, as expected.")
4146
if sr is not None:
@@ -56,7 +61,17 @@ def test_create_and_destroy_sr(self,
5661
vm.destroy(verify=True)
5762
sr.destroy(verify=True)
5863

59-
@pytest.mark.usefixtures("xfs_sr")
64+
# We want to skip class tests for qcow2 if the SM does not support qcow2
65+
@pytest.fixture(scope="class")
66+
def for_qcow2_vdi_image_format(vdi_on_xfs_sr: VDI, image_format: str):
67+
# only check qcow2-specific behavior
68+
if image_format != "qcow2":
69+
return
70+
# feature-detect: if the SM doesn't report image-format, skip this check
71+
if not vdi_on_xfs_sr.get_image_format():
72+
pytest.skip("SM does not report sm-config:image-format; skipping qcow2 format check")
73+
74+
@pytest.mark.usefixtures("for_qcow2_vdi_image_format", "xfs_sr")
6075
class TestXFSSR:
6176
@pytest.mark.quicktest
6277
def test_quicktest(self, xfs_sr):

0 commit comments

Comments
 (0)