Skip to content

Commit 6ea9409

Browse files
committed
tests/storage/zfs: add type hints
Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
1 parent 9a0efe8 commit 6ea9409

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

tests/storage/zfs/conftest.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,24 @@
44

55
import logging
66

7+
from lib.host import Host
78
from lib.sr import SR
9+
from lib.vdi import VDI, ImageFormat
10+
from lib.vm import VM
811

912
# Explicitly import package-scoped fixtures (see explanation in pkgfixtures.py)
10-
from lib.vdi import ImageFormat
1113
from pkgfixtures import host_with_saved_yum_state, sr_disk_wiped
1214

13-
from typing import TYPE_CHECKING, Generator
14-
15-
if TYPE_CHECKING:
16-
from lib.host import Host
17-
from lib.sr import SR
15+
from typing import Generator
1816

1917
POOL_NAME = 'pool0'
2018
POOL_PATH = '/' + POOL_NAME
2119

2220
@pytest.fixture(scope='package')
23-
def host_without_zfs(host):
21+
def host_without_zfs(host: Host) -> Generator[Host, None, None]:
2422
assert not host.file_exists('/usr/sbin/zpool'), \
2523
"zfs must not be installed on the host at the beginning of the tests"
24+
yield host
2625

2726
# NOTE: @pytest.mark.usefixtures does not parametrize this fixture.
2827
# To recreate host_with_zfs for each image_format value, accept
@@ -32,21 +31,21 @@ def host_without_zfs(host):
3231
def host_with_zfs(host_without_zfs: Host,
3332
host_with_saved_yum_state: Host,
3433
image_format: ImageFormat
35-
) -> Generator[Host]:
34+
) -> Generator[Host, None, None]:
3635
host = host_with_saved_yum_state
3736
host.yum_install(['zfs'])
3837
host.ssh('modprobe zfs')
3938
yield host
4039

4140
@pytest.fixture(scope='package')
42-
def zpool_vol0(sr_disk_wiped, host_with_zfs: Host):
41+
def zpool_vol0(sr_disk_wiped: str, host_with_zfs: Host) -> Generator[None, None, None]:
4342
host_with_zfs.ssh(f'zpool create -f {POOL_NAME} /dev/{sr_disk_wiped}')
4443
yield
4544
# teardown
4645
host_with_zfs.ssh(f'zpool destroy {POOL_NAME}')
4746

4847
@pytest.fixture(scope='package')
49-
def zfs_sr(host: Host, image_format: ImageFormat, zpool_vol0: None) -> Generator[SR]:
48+
def zfs_sr(host: Host, image_format: ImageFormat, zpool_vol0: None) -> Generator[SR, None, None]:
5049
""" A ZFS SR on first host. """
5150
sr = host.sr_create('zfs', "ZFS-local-SR-test", {
5251
'location': POOL_PATH,
@@ -57,13 +56,13 @@ def zfs_sr(host: Host, image_format: ImageFormat, zpool_vol0: None) -> Generator
5756
sr.destroy()
5857

5958
@pytest.fixture(scope='module')
60-
def vdi_on_zfs_sr(zfs_sr: SR):
59+
def vdi_on_zfs_sr(zfs_sr: SR) -> Generator[VDI, None, None]:
6160
vdi = zfs_sr.create_vdi('ZFS-local-VDI-test')
6261
yield vdi
6362
vdi.destroy()
6463

6564
@pytest.fixture(scope='module')
66-
def vm_on_zfs_sr(host, zfs_sr, vm_ref):
65+
def vm_on_zfs_sr(host: Host, zfs_sr: SR, vm_ref: str) -> Generator[VM, None, None]:
6766
vm = host.import_vm(vm_ref, sr_uuid=zfs_sr.uuid)
6867
yield vm
6968
# teardown

tests/storage/zfs/test_zfs_sr.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from lib.commands import SSHCommandFailed
99
from lib.common import vm_image, wait_for
10+
from lib.host import Host
1011
from lib.sr import SR
1112
from lib.vdi import VDI
1213
from lib.vm import VM
@@ -20,12 +21,6 @@
2021
xva_export_import,
2122
)
2223

23-
from typing import TYPE_CHECKING
24-
25-
if TYPE_CHECKING:
26-
from lib.host import Host
27-
from lib.vdi import VDI
28-
2924
from .conftest import POOL_NAME, POOL_PATH
3025

3126
# Requirements:
@@ -72,13 +67,13 @@ def test_create_and_destroy_sr(self, host: Host, image_format: ImageFormat) -> N
7267
@pytest.mark.usefixtures("zpool_vol0")
7368
class TestZFSSR:
7469
@pytest.mark.quicktest
75-
def test_quicktest(self, zfs_sr):
70+
def test_quicktest(self, zfs_sr: SR) -> None:
7671
zfs_sr.run_quicktest()
7772

78-
def test_vdi_is_not_open(self, vdi_on_zfs_sr):
73+
def test_vdi_is_not_open(self, vdi_on_zfs_sr: VDI) -> None:
7974
assert not vdi_is_open(vdi_on_zfs_sr)
8075

81-
def test_vdi_image_format(self, vdi_on_zfs_sr: VDI, image_format: ImageFormat):
76+
def test_vdi_image_format(self, vdi_on_zfs_sr: VDI, image_format: ImageFormat) -> None:
8277
fmt = vdi_on_zfs_sr.get_image_format()
8378
# feature-detect: if the SM doesn't report image-format, skip this check
8479
if not fmt:
@@ -87,15 +82,15 @@ def test_vdi_image_format(self, vdi_on_zfs_sr: VDI, image_format: ImageFormat):
8782

8883
@pytest.mark.small_vm # run with a small VM to test the features
8984
@pytest.mark.big_vm # and ideally with a big VM to test it scales
90-
def test_start_and_shutdown_VM(self, vm_on_zfs_sr):
85+
def test_start_and_shutdown_VM(self, vm_on_zfs_sr: VM) -> None:
9186
vm = vm_on_zfs_sr
9287
vm.start()
9388
vm.wait_for_os_booted()
9489
vm.shutdown(verify=True)
9590

9691
@pytest.mark.small_vm
9792
@pytest.mark.big_vm
98-
def test_snapshot(self, vm_on_zfs_sr):
93+
def test_snapshot(self, vm_on_zfs_sr: VM) -> None:
9994
vm = vm_on_zfs_sr
10095
vm.start()
10196
try:
@@ -106,23 +101,23 @@ def test_snapshot(self, vm_on_zfs_sr):
106101

107102
@pytest.mark.small_vm
108103
@pytest.mark.parametrize("vdi_op", ["snapshot", "clone"])
109-
def test_coalesce(self, storage_test_vm: VM, vdi_on_zfs_sr: VDI, vdi_op: CoalesceOperation):
104+
def test_coalesce(self, storage_test_vm: VM, vdi_on_zfs_sr: VDI, vdi_op: CoalesceOperation) -> None:
110105
coalesce_integrity(storage_test_vm, vdi_on_zfs_sr, vdi_op)
111106

112107
@pytest.mark.small_vm
113108
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
114-
def test_xva_export_import(self, vm_on_zfs_sr: VM, compression: XVACompression):
109+
def test_xva_export_import(self, vm_on_zfs_sr: VM, compression: XVACompression) -> None:
115110
xva_export_import(vm_on_zfs_sr, compression)
116111

117112
@pytest.mark.small_vm
118-
def test_vdi_export_import(self, storage_test_vm: VM, zfs_sr: SR, image_format: ImageFormat):
113+
def test_vdi_export_import(self, storage_test_vm: VM, zfs_sr: SR, image_format: ImageFormat) -> None:
119114
vdi_export_import(storage_test_vm, zfs_sr, image_format)
120115

121116
# *** tests with reboots (longer tests).
122117

123118
@pytest.mark.reboot
124119
@pytest.mark.small_vm
125-
def test_reboot(self, vm_on_zfs_sr, host, zfs_sr):
120+
def test_reboot(self, vm_on_zfs_sr: VM, host: Host, zfs_sr: SR) -> None:
126121
sr = zfs_sr
127122
vm = vm_on_zfs_sr
128123
host.reboot(verify=True)
@@ -133,7 +128,7 @@ def test_reboot(self, vm_on_zfs_sr, host, zfs_sr):
133128
vm.shutdown(verify=True)
134129

135130
@pytest.mark.reboot
136-
def test_zfs_missing(self, host: Host, zfs_sr):
131+
def test_zfs_missing(self, host: Host, zfs_sr: SR) -> None:
137132
sr = zfs_sr
138133
zfs_installed = True
139134
try:
@@ -161,7 +156,7 @@ def test_zfs_missing(self, host: Host, zfs_sr):
161156
host.ssh('modprobe zfs')
162157

163158
@pytest.mark.reboot
164-
def test_zfs_unmounted(self, host: Host, zfs_sr):
159+
def test_zfs_unmounted(self, host: Host, zfs_sr: SR) -> None:
165160
sr = zfs_sr
166161
zpool_imported = True
167162
try:

tests/storage/zfs/test_zfs_sr_crosspool_migration.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import pytest
22

3+
from lib.host import Host
4+
from lib.sr import SR
5+
from lib.vm import VM
36
from tests.storage import cold_migration_then_come_back, live_storage_migration_then_come_back
47

58
# Requirements:
@@ -15,8 +18,8 @@
1518
@pytest.mark.big_vm # and ideally with a big VM to test it scales
1619
@pytest.mark.usefixtures("hostB1", "local_sr_on_hostB1")
1720
class Test:
18-
def test_cold_crosspool_migration(self, host, hostB1, vm_on_zfs_sr, local_sr_on_hostB1):
21+
def test_cold_crosspool_migration(self, host: Host, hostB1: Host, vm_on_zfs_sr: VM, local_sr_on_hostB1: SR) -> None:
1922
cold_migration_then_come_back(vm_on_zfs_sr, host, hostB1, local_sr_on_hostB1)
2023

21-
def test_live_crosspool_migration(self, host, hostB1, vm_on_zfs_sr, local_sr_on_hostB1):
24+
def test_live_crosspool_migration(self, host: Host, hostB1: Host, vm_on_zfs_sr: VM, local_sr_on_hostB1: SR) -> None:
2225
live_storage_migration_then_come_back(vm_on_zfs_sr, host, hostB1, local_sr_on_hostB1)

tests/storage/zfs/test_zfs_sr_intrapool_migration.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import pytest
22

3+
from lib.host import Host
4+
from lib.sr import SR
5+
from lib.vm import VM
36
from tests.storage import cold_migration_then_come_back, live_storage_migration_then_come_back
47

58
# Requirements:
@@ -15,8 +18,8 @@
1518
@pytest.mark.big_vm # and ideally with a big VM to test it scales
1619
@pytest.mark.usefixtures("hostA2", "local_sr_on_hostA2")
1720
class Test:
18-
def test_cold_intrapool_migration(self, host, hostA2, vm_on_zfs_sr, local_sr_on_hostA2):
21+
def test_cold_intrapool_migration(self, host: Host, hostA2: Host, vm_on_zfs_sr: VM, local_sr_on_hostA2: SR) -> None:
1922
cold_migration_then_come_back(vm_on_zfs_sr, host, hostA2, local_sr_on_hostA2)
2023

21-
def test_live_intrapool_migration(self, host, hostA2, vm_on_zfs_sr, local_sr_on_hostA2):
24+
def test_live_intrapool_migration(self, host: Host, hostA2: Host, vm_on_zfs_sr: VM, local_sr_on_hostA2: SR) -> None:
2225
live_storage_migration_then_come_back(vm_on_zfs_sr, host, hostA2, local_sr_on_hostA2)

0 commit comments

Comments
 (0)