Skip to content

Commit 51d6dd5

Browse files
committed
xfs: Don't uninstall xfs tools when SR couldn't be destroyed
Leave xfs tools in place for manual cleanup after a failed SR cleanup Signed-off-by: Antoine Bartuccio <[email protected]>
1 parent 46cd8ab commit 51d6dd5

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

tests/storage/xfs/conftest.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,60 @@
33
import pytest
44

55
import logging
6+
from dataclasses import dataclass
67

78
from typing import TYPE_CHECKING, Generator
89

910
if TYPE_CHECKING:
1011
from lib.host import Host
1112
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()
1223

1324
@pytest.fixture(scope='package')
14-
def host_with_xfsprogs(host):
25+
def host_with_xfsprogs(host: Host, _xfs_config: XfsConfig) -> Generator[Host]:
1526
assert not host.file_exists('/usr/sbin/mkfs.xfs'), \
1627
"xfsprogs must not be installed on the host at the beginning of the tests"
1728
host.yum_save_state()
1829
host.yum_install(['xfsprogs'])
1930
yield host
2031
# teardown
21-
host.yum_restore_saved_state()
32+
if _xfs_config.uninstall_xfs:
33+
host.yum_restore_saved_state()
2234

2335
@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]:
2641
""" A XFS SR on first host. """
2742
sr_disk = unused_512B_disks[host_with_xfsprogs][0]["name"]
2843
sr = host_with_xfsprogs.sr_create('xfs', "XFS-local-SR-test", {'device': '/dev/' + sr_disk})
2944
yield sr
3045
# teardown
31-
sr.destroy()
46+
try:
47+
sr.destroy()
48+
except Exception as e:
49+
_xfs_config.uninstall_xfs = False
50+
raise e
3251

3352
@pytest.fixture(scope='module')
34-
def vdi_on_xfs_sr(xfs_sr):
53+
def vdi_on_xfs_sr(xfs_sr: SR) -> Generator[VDI]:
3554
vdi = xfs_sr.create_vdi('XFS-local-VDI-test')
3655
yield vdi
3756
vdi.destroy()
3857

3958
@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]:
4160
vm = host.import_vm(vm_ref, sr_uuid=xfs_sr.uuid)
4261
yield vm
4362
# teardown

0 commit comments

Comments
 (0)