Skip to content

Commit d8be92d

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

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-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: 17 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,11 @@
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+
1017
from .conftest import POOL_NAME, POOL_PATH
1118

1219
# Requirements:
@@ -21,23 +28,29 @@ class TestZFSSRCreateDestroy:
2128
and VM import.
2229
"""
2330

24-
def test_create_zfs_sr_without_zfs(self, host):
31+
def test_create_zfs_sr_without_zfs(self, host: Host, image_format: str) -> None:
2532
# This test must be the first in the series in this module
2633
assert not host.file_exists('/usr/sbin/zpool'), \
2734
"zfs must not be installed on the host at the beginning of the tests"
2835
sr = None
2936
try:
30-
sr = host.sr_create('zfs', "ZFS-local-SR-test", {'location': POOL_PATH})
37+
sr = host.sr_create('zfs', "ZFS-local-SR-test", {
38+
'location': POOL_PATH,
39+
'preferred-image-formats': image_format
40+
}, verify=True)
3141
except Exception:
3242
logging.info("SR creation failed, as expected.")
3343
if sr is not None:
3444
sr.destroy()
3545
assert False, "SR creation should not have succeeded!"
3646

3747
@pytest.mark.usefixtures("zpool_vol0")
38-
def test_create_and_destroy_sr(self, host):
48+
def test_create_and_destroy_sr(self, host: Host, image_format: str) -> None:
3949
# 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)
50+
sr = host.sr_create('zfs', "ZFS-local-SR-test", {
51+
'location': POOL_PATH,
52+
'preferred-image-formats': image_format
53+
}, verify=True)
4154
# import a VM in order to detect vm import issues here rather than in the vm_on_xfs_fixture used in
4255
# the next tests, because errors in fixtures break teardown
4356
vm = host.import_vm(vm_image('mini-linux-x86_64-bios'), sr_uuid=sr.uuid)

0 commit comments

Comments
 (0)