|
3 | 3 | import pytest |
4 | 4 |
|
5 | 5 | import logging |
| 6 | +from dataclasses import dataclass |
6 | 7 |
|
7 | 8 | from typing import TYPE_CHECKING, Generator |
8 | 9 |
|
9 | 10 | if TYPE_CHECKING: |
10 | 11 | from lib.host import Host |
11 | 12 | from lib.sr import SR |
| 13 | + from lib.vdi import VDI |
| 14 | + from lib.vm import VM |
| 15 | + |
| 16 | +@dataclass |
| 17 | +class XfsConfig: |
| 18 | + uninstall_xfs: bool = True |
| 19 | + |
| 20 | +@pytest.fixture(scope='package') |
| 21 | +def _xfs_config() -> XfsConfig: |
| 22 | + return XfsConfig() |
12 | 23 |
|
13 | 24 | @pytest.fixture(scope='package') |
14 | | -def host_with_xfsprogs(host): |
| 25 | +def host_with_xfsprogs(host: Host, _xfs_config: XfsConfig) -> Generator[Host]: |
15 | 26 | assert not host.file_exists('/usr/sbin/mkfs.xfs'), \ |
16 | 27 | "xfsprogs must not be installed on the host at the beginning of the tests" |
17 | 28 | host.yum_save_state() |
18 | 29 | host.yum_install(['xfsprogs']) |
19 | 30 | yield host |
20 | 31 | # teardown |
21 | | - host.yum_restore_saved_state() |
| 32 | + if _xfs_config.uninstall_xfs: |
| 33 | + host.yum_restore_saved_state() |
22 | 34 |
|
23 | 35 | @pytest.fixture(scope='package') |
24 | | -def xfs_sr(unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]], host_with_xfsprogs: Host |
25 | | - ) -> Generator[SR]: |
| 36 | +def xfs_sr( |
| 37 | + unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]], |
| 38 | + host_with_xfsprogs: Host, |
| 39 | + _xfs_config: XfsConfig, |
| 40 | +) -> Generator[SR]: |
26 | 41 | """ A XFS SR on first host. """ |
27 | 42 | sr_disk = unused_512B_disks[host_with_xfsprogs][0]["name"] |
28 | 43 | sr = host_with_xfsprogs.sr_create('xfs', "XFS-local-SR-test", {'device': '/dev/' + sr_disk}) |
29 | 44 | yield sr |
30 | 45 | # teardown |
31 | | - sr.destroy() |
| 46 | + try: |
| 47 | + sr.destroy() |
| 48 | + except Exception as e: |
| 49 | + _xfs_config.uninstall_xfs = False |
| 50 | + raise pytest.fail("Could not destroy xfs SR, leaving packages in place for manual cleanup") from e |
32 | 51 |
|
33 | 52 | @pytest.fixture(scope='module') |
34 | | -def vdi_on_xfs_sr(xfs_sr): |
| 53 | +def vdi_on_xfs_sr(xfs_sr: SR) -> Generator[VDI]: |
35 | 54 | vdi = xfs_sr.create_vdi('XFS-local-VDI-test') |
36 | 55 | yield vdi |
37 | 56 | vdi.destroy() |
38 | 57 |
|
39 | 58 | @pytest.fixture(scope='module') |
40 | | -def vm_on_xfs_sr(host, xfs_sr, vm_ref): |
| 59 | +def vm_on_xfs_sr(host: Host, xfs_sr: SR, vm_ref: str) -> Generator[VM]: |
41 | 60 | vm = host.import_vm(vm_ref, sr_uuid=xfs_sr.uuid) |
42 | 61 | yield vm |
43 | 62 | # teardown |
|
0 commit comments