1+ from __future__ import annotations
2+
13import pytest
24
35import logging
79from lib .common import vm_image , wait_for
810from 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+
1018from .conftest import POOL_NAME , POOL_PATH
1119
1220# Requirements:
@@ -21,30 +29,46 @@ 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 )
4458 vm .destroy (verify = True )
4559 sr .destroy (verify = True )
4660
47- @pytest .mark .usefixtures ("zpool_vol0" )
61+ # We want to skip class tests for qcow2 if the SM does not support qcow2
62+ @pytest .fixture (scope = "class" )
63+ def for_qcow2_vdi_image_format (vdi_on_zfs_sr : VDI , image_format : str ):
64+ # only check qcow2-specific behavior
65+ if image_format != "qcow2" :
66+ return
67+ # feature-detect: if the SM doesn't report image-format, skip this check
68+ if not vdi_on_zfs_sr .get_image_format ():
69+ pytest .skip ("SM does not report sm-config:image-format; skipping qcow2 format check" )
70+
71+ @pytest .mark .usefixtures ("for_qcow2_vdi_image_format" , "zpool_vol0" )
4872class TestZFSSR :
4973 @pytest .mark .quicktest
5074 def test_quicktest (self , zfs_sr ):
0 commit comments