Skip to content

Commit e658830

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

File tree

4 files changed

+36
-16
lines changed

4 files changed

+36
-16
lines changed

tests/storage/zfsvol/conftest.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,23 @@
66

77
from lib.host import Host
88
from lib.sr import SR
9+
from lib.vdi import VDI
10+
from lib.vm import VM
911

1012
# Explicitly import package-scoped fixtures (see explanation in pkgfixtures.py)
1113
from pkgfixtures import host_with_saved_yum_state_toolstack_restart, sr_disk_wiped
1214

15+
from typing import Generator
16+
1317
@pytest.fixture(scope='package')
14-
def host_with_zfsvol(host_with_saved_yum_state_toolstack_restart):
18+
def host_with_zfsvol(host_with_saved_yum_state_toolstack_restart: Host) -> Generator[Host, None, None]:
1519
host = host_with_saved_yum_state_toolstack_restart
1620
host.yum_install(['xcp-ng-xapi-storage-volume-zfsvol'])
1721
host.restart_toolstack(verify=True)
1822
yield host
1923

2024
@pytest.fixture(scope='package')
21-
def zfsvol_sr(host: Host, sr_disk_wiped, host_with_zfsvol):
25+
def zfsvol_sr(host: Host, sr_disk_wiped: str, host_with_zfsvol: Host) -> Generator[SR, None, None]:
2226
""" A ZFS Volume SR on first host. """
2327
device = '/dev/' + sr_disk_wiped
2428
sr = host.sr_create('zfs-vol', "ZFS-local-SR-test", {'device': device})
@@ -28,13 +32,13 @@ def zfsvol_sr(host: Host, sr_disk_wiped, host_with_zfsvol):
2832
host.ssh(f'wipefs -a {device}')
2933

3034
@pytest.fixture(scope='module')
31-
def vdi_on_zfsvol_sr(zfsvol_sr: SR):
35+
def vdi_on_zfsvol_sr(zfsvol_sr: SR) -> Generator[VDI, None, None]:
3236
vdi = zfsvol_sr.create_vdi('ZFS-local-VDI-test')
3337
yield vdi
3438
vdi.destroy()
3539

3640
@pytest.fixture(scope='module')
37-
def vm_on_zfsvol_sr(host, zfsvol_sr, vm_ref):
41+
def vm_on_zfsvol_sr(host: Host, zfsvol_sr: SR, vm_ref: str) -> Generator[VM, None, None]:
3842
vm = host.import_vm(vm_ref, sr_uuid=zfsvol_sr.uuid)
3943
yield vm
4044
# teardown

tests/storage/zfsvol/test_zfsvol_sr.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import logging
66

77
from lib.common import vm_image, wait_for
8+
from lib.host import Host
89
from lib.sr import SR
910
from lib.vdi import VDI
1011
from lib.vm import VM
@@ -16,14 +17,15 @@
1617

1718
pytestmark = pytest.mark.usefixtures("host_at_least_8_3")
1819

20+
1921
class TestZfsvolSRCreateDestroy:
2022
"""
2123
Tests that do not use fixtures that setup the SR or import VMs,
2224
because they precisely need to test SR creation and destruction,
2325
and VM import.
2426
"""
2527

26-
def test_create_and_destroy_sr(self, sr_disk_wiped, host_with_zfsvol):
28+
def test_create_and_destroy_sr(self, sr_disk_wiped: str, host_with_zfsvol: Host) -> None:
2729
host = host_with_zfsvol
2830
# Create and destroy tested in the same test to leave the host as unchanged as possible
2931
sr = host.sr_create('zfs-vol', "ZFS-local-SR-test", {'device': '/dev/' + sr_disk_wiped}, verify=True)
@@ -38,12 +40,12 @@ class TestZfsvolVm:
3840

3941
@pytest.mark.xfail
4042
@pytest.mark.quicktest
41-
def test_quicktest(self, zfsvol_sr):
43+
def test_quicktest(self, zfsvol_sr: SR) -> None:
4244
zfsvol_sr.run_quicktest()
4345

4446
@pytest.mark.small_vm # run with a small VM to test the features
4547
@pytest.mark.big_vm # and ideally with a big VM to test it scales
46-
def test_start_and_shutdown_VM(self, vm_on_zfsvol_sr):
48+
def test_start_and_shutdown_VM(self, vm_on_zfsvol_sr: VM) -> None:
4749
vm = vm_on_zfsvol_sr
4850
vm.start()
4951
vm.wait_for_os_booted()
@@ -52,7 +54,7 @@ def test_start_and_shutdown_VM(self, vm_on_zfsvol_sr):
5254
@pytest.mark.xfail # needs support for destroying snapshots
5355
@pytest.mark.small_vm
5456
@pytest.mark.big_vm
55-
def test_snapshot(self, vm_on_zfsvol_sr):
57+
def test_snapshot(self, vm_on_zfsvol_sr: VM) -> None:
5658
vm = vm_on_zfsvol_sr
5759
vm.start()
5860
try:
@@ -63,16 +65,16 @@ def test_snapshot(self, vm_on_zfsvol_sr):
6365

6466
@pytest.mark.small_vm
6567
@pytest.mark.parametrize("vdi_op", ["snapshot"]) # "clone" requires a snapshot
66-
def test_coalesce(self, storage_test_vm: VM, vdi_on_zfsvol_sr: VDI, vdi_op: CoalesceOperation):
68+
def test_coalesce(self, storage_test_vm: VM, vdi_on_zfsvol_sr: VDI, vdi_op: CoalesceOperation) -> None:
6769
coalesce_integrity(storage_test_vm, vdi_on_zfsvol_sr, vdi_op)
6870

6971
@pytest.mark.small_vm
7072
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
71-
def test_xva_export_import(self, vm_on_zfsvol_sr: VM, compression: XVACompression):
73+
def test_xva_export_import(self, vm_on_zfsvol_sr: VM, compression: XVACompression) -> None:
7274
xva_export_import(vm_on_zfsvol_sr, compression)
7375

7476
@pytest.mark.small_vm
75-
def test_vdi_export_import(self, storage_test_vm: VM, zfsvol_sr: SR, image_format: ImageFormat):
77+
def test_vdi_export_import(self, storage_test_vm: VM, zfsvol_sr: SR, image_format: ImageFormat) -> None:
7678
vm = storage_test_vm
7779
sr = zfsvol_sr
7880
vdi: VDI | None = sr.create_vdi(image_format=image_format)
@@ -111,7 +113,7 @@ def test_vdi_export_import(self, storage_test_vm: VM, zfsvol_sr: SR, image_forma
111113

112114
@pytest.mark.reboot
113115
@pytest.mark.small_vm
114-
def test_reboot(self, vm_on_zfsvol_sr, host, zfsvol_sr):
116+
def test_reboot(self, vm_on_zfsvol_sr: VM, host: Host, zfsvol_sr: SR) -> None:
115117
sr = zfsvol_sr
116118
vm = vm_on_zfsvol_sr
117119
host.reboot(verify=True)

tests/storage/zfsvol/test_zfsvol_sr_crosspool_migration.py

Lines changed: 9 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:
@@ -16,8 +19,12 @@
1619
@pytest.mark.big_vm # and ideally with a big VM to test it scales
1720
@pytest.mark.usefixtures("hostB1", "local_sr_on_hostB1")
1821
class Test:
19-
def test_cold_crosspool_migration(self, host, hostB1, vm_on_zfsvol_sr, local_sr_on_hostB1):
22+
def test_cold_crosspool_migration(
23+
self, host: Host, hostB1: Host, vm_on_zfsvol_sr: VM, local_sr_on_hostB1: SR
24+
) -> None:
2025
cold_migration_then_come_back(vm_on_zfsvol_sr, host, hostB1, local_sr_on_hostB1)
2126

22-
def test_live_crosspool_migration(self, host, hostB1, vm_on_zfsvol_sr, local_sr_on_hostB1):
27+
def test_live_crosspool_migration(
28+
self, host: Host, hostB1: Host, vm_on_zfsvol_sr: VM, local_sr_on_hostB1: SR
29+
) -> None:
2330
live_storage_migration_then_come_back(vm_on_zfsvol_sr, host, hostB1, local_sr_on_hostB1)

tests/storage/zfsvol/test_zfsvol_sr_intrapool_migration.py

Lines changed: 9 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:
@@ -16,8 +19,12 @@
1619
@pytest.mark.big_vm # and ideally with a big VM to test it scales
1720
@pytest.mark.usefixtures("hostA2", "local_sr_on_hostA2")
1821
class Test:
19-
def test_cold_intrapool_migration(self, host, hostA2, vm_on_zfsvol_sr, local_sr_on_hostA2):
22+
def test_cold_intrapool_migration(
23+
self, host: Host, hostA2: Host, vm_on_zfsvol_sr: VM, local_sr_on_hostA2: SR
24+
) -> None:
2025
cold_migration_then_come_back(vm_on_zfsvol_sr, host, hostA2, local_sr_on_hostA2)
2126

22-
def test_live_intrapool_migration(self, host, hostA2, vm_on_zfsvol_sr, local_sr_on_hostA2):
27+
def test_live_intrapool_migration(
28+
self, host: Host, hostA2: Host, vm_on_zfsvol_sr: VM, local_sr_on_hostA2: SR
29+
) -> None:
2330
live_storage_migration_then_come_back(vm_on_zfsvol_sr, host, hostA2, local_sr_on_hostA2)

0 commit comments

Comments
 (0)