1+ from __future__ import annotations
2+
13import pytest
24
35import logging
46
57# Explicitly import package-scoped fixtures (see explanation in pkgfixtures.py)
68from 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+
816POOL_NAME = 'pool0'
917POOL_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 ()
0 commit comments