Skip to content

Commit 9454cff

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 7ad889e commit 9454cff

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

tests/storage/xfs/conftest.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
from lib.host import Host
1111
from lib.sr import SR
1212

13+
# NOTE: @pytest.mark.usefixtures does not parametrize this fixture.
14+
# To recreate host_with_xfsprogs for each image_format value, accept
15+
# image_format in the fixture arguments.
16+
# ref https://docs.pytest.org/en/7.1.x/how-to/fixtures.html#use-fixtures-in-classes-and-modules-with-usefixtures
1317
@pytest.fixture(scope='package')
14-
def host_with_xfsprogs(host):
18+
def host_with_xfsprogs(host: Host, image_format: str):
1519
assert not host.file_exists('/usr/sbin/mkfs.xfs'), \
1620
"xfsprogs must not be installed on the host at the beginning of the tests"
1721
host.yum_save_state()
@@ -21,11 +25,15 @@ def host_with_xfsprogs(host):
2125
host.yum_restore_saved_state()
2226

2327
@pytest.fixture(scope='package')
24-
def xfs_sr(unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]], host_with_xfsprogs: Host
28+
def xfs_sr(unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]],
29+
host_with_xfsprogs: Host,
30+
image_format: str
2531
) -> Generator[SR]:
2632
""" A XFS SR on first host. """
2733
sr_disk = unused_512B_disks[host_with_xfsprogs][0]["name"]
28-
sr = host_with_xfsprogs.sr_create('xfs', "XFS-local-SR-test", {'device': '/dev/' + sr_disk})
34+
sr = host_with_xfsprogs.sr_create('xfs', "XFS-local-SR-test",
35+
{'device': '/dev/' + sr_disk,
36+
'preferred-image-formats': image_format})
2937
yield sr
3038
# teardown
3139
sr.destroy()

tests/storage/xfs/test_xfs_sr.py

Lines changed: 14 additions & 2 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:
@@ -65,6 +70,13 @@ def test_quicktest(self, xfs_sr):
6570
def test_vdi_is_not_open(self, vdi_on_xfs_sr):
6671
assert not vdi_is_open(vdi_on_xfs_sr)
6772

73+
def test_vdi_image_format(self, vdi_on_xfs_sr: VDI, image_format: str):
74+
fmt = vdi_on_xfs_sr.get_image_format()
75+
# feature-detect: if the SM doesn't report image-format, skip this check
76+
if not fmt:
77+
pytest.skip("SM does not report sm-config:image-format; skipping format check")
78+
assert fmt == image_format
79+
6880
@pytest.mark.small_vm # run with a small VM to test the features
6981
@pytest.mark.big_vm # and ideally with a big VM to test it scales
7082
def test_start_and_shutdown_VM(self, vm_on_xfs_sr):

0 commit comments

Comments
 (0)