Skip to content

Commit 6965c05

Browse files
tests/storage/zfs: Updated zfs to handle both vhd and qcow2 vdi image format
Signed-off-by: Rushikesh Jadhav <[email protected]>
1 parent 2ecd7a9 commit 6965c05

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

tests/storage/zfs/conftest.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
from __future__ import annotations
2+
13
import pytest
24

35
import logging
46

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

10+
from typing import TYPE_CHECKING, Generator
11+
12+
if TYPE_CHECKING:
13+
from lib.host import Host
14+
from lib.sr import SR
15+
816
POOL_NAME = 'pool0'
917
POOL_PATH = '/' + POOL_NAME
1018

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

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

3045
@pytest.fixture(scope='package')
31-
def zfs_sr(host, zpool_vol0):
46+
def zfs_sr(host: Host, image_format: str, zpool_vol0: None) -> Generator[SR]:
3247
""" A ZFS SR on first host. """
33-
sr = host.sr_create('zfs', "ZFS-local-SR-test", {'location': POOL_PATH})
48+
sr = host.sr_create('zfs', "ZFS-local-SR-test", {
49+
'location': POOL_PATH,
50+
'preferred-image-formats': image_format
51+
}, verify=True)
3452
yield sr
3553
# teardown
3654
sr.destroy()

tests/storage/zfs/test_zfs_sr.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import pytest
24

35
import logging
@@ -7,6 +9,12 @@
79
from lib.common import vm_image, wait_for
810
from tests.storage import vdi_is_open
911

12+
from typing import TYPE_CHECKING
13+
14+
if TYPE_CHECKING:
15+
from lib.host import Host
16+
from lib.vdi import VDI
17+
1018
from .conftest import POOL_NAME, POOL_PATH
1119

1220
# Requirements:
@@ -21,23 +29,29 @@ class TestZFSSRCreateDestroy:
2129
and VM import.
2230
"""
2331

24-
def test_create_zfs_sr_without_zfs(self, host):
32+
def test_create_zfs_sr_without_zfs(self, host: Host, image_format: str) -> None:
2533
# This test must be the first in the series in this module
2634
assert not host.file_exists('/usr/sbin/zpool'), \
2735
"zfs must not be installed on the host at the beginning of the tests"
2836
sr = None
2937
try:
30-
sr = host.sr_create('zfs', "ZFS-local-SR-test", {'location': POOL_PATH})
38+
sr = host.sr_create('zfs', "ZFS-local-SR-test", {
39+
'location': POOL_PATH,
40+
'preferred-image-formats': image_format
41+
}, verify=True)
3142
except Exception:
3243
logging.info("SR creation failed, as expected.")
3344
if sr is not None:
3445
sr.destroy()
3546
assert False, "SR creation should not have succeeded!"
3647

3748
@pytest.mark.usefixtures("zpool_vol0")
38-
def test_create_and_destroy_sr(self, host):
49+
def test_create_and_destroy_sr(self, host: Host, image_format: str) -> None:
3950
# Create and destroy tested in the same test to leave the host as unchanged as possible
40-
sr = host.sr_create('zfs', "ZFS-local-SR-test", {'location': POOL_PATH}, verify=True)
51+
sr = host.sr_create('zfs', "ZFS-local-SR-test", {
52+
'location': POOL_PATH,
53+
'preferred-image-formats': image_format
54+
}, verify=True)
4155
# import a VM in order to detect vm import issues here rather than in the vm_on_xfs_fixture used in
4256
# the next tests, because errors in fixtures break teardown
4357
vm = host.import_vm(vm_image('mini-linux-x86_64-bios'), sr_uuid=sr.uuid)
@@ -53,6 +67,9 @@ def test_quicktest(self, zfs_sr):
5367
def test_vdi_is_not_open(self, vdi_on_zfs_sr):
5468
assert not vdi_is_open(vdi_on_zfs_sr)
5569

70+
def test_vdi_image_format(self, vdi_on_zfs_sr: VDI, image_format: str):
71+
assert vdi_on_zfs_sr.get_image_format() == image_format
72+
5673
@pytest.mark.small_vm # run with a small VM to test the features
5774
@pytest.mark.big_vm # and ideally with a big VM to test it scales
5875
def test_start_and_shutdown_VM(self, vm_on_zfs_sr):

0 commit comments

Comments
 (0)