Skip to content

Commit 9e85115

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

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

tests/storage/lvm/conftest.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@
1111
from lib.sr import SR
1212

1313
@pytest.fixture(scope='package')
14-
def lvm_sr(host: Host, unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]]) -> Generator[SR]:
14+
def lvm_sr(host: Host,
15+
unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]],
16+
image_format: str
17+
) -> Generator[SR]:
1518
""" An LVM SR on first host. """
1619
sr_disk = unused_512B_disks[host][0]["name"]
17-
sr = host.sr_create('lvm', "LVM-local-SR-test", {'device': '/dev/' + sr_disk})
20+
sr = host.sr_create('lvm', "LVM-local-SR-test",
21+
{'device': '/dev/' + sr_disk,
22+
'preferred-image-formats': image_format})
1823
yield sr
1924
# teardown
2025
sr.destroy()

tests/storage/lvm/test_lvm_sr.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,33 @@ class TestLVMSRCreateDestroy:
2828
def test_create_sr_with_missing_device(self, host):
2929
try_to_create_sr_with_missing_device('lvm', 'LVM-local-SR-test', host)
3030

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

41-
@pytest.mark.usefixtures("lvm_sr")
47+
# We want to skip class tests for qcow2 if the SM does not support qcow2
48+
@pytest.fixture(scope="class")
49+
def for_qcow2_vdi_image_format(vdi_on_lvm_sr: VDI, image_format: str):
50+
# only check qcow2-specific behavior
51+
if image_format != "qcow2":
52+
return
53+
# feature-detect: if the SM doesn't report image-format, skip this check
54+
if not vdi_on_lvm_sr.get_image_format():
55+
pytest.skip("SM does not report sm-config:image-format; skipping qcow2 format check")
56+
57+
@pytest.mark.usefixtures("for_qcow2_vdi_image_format", "lvm_sr")
4258
class TestLVMSR:
4359
@pytest.mark.quicktest
4460
def test_quicktest(self, lvm_sr):

0 commit comments

Comments
 (0)