-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathconftest.py
More file actions
62 lines (51 loc) · 1.73 KB
/
Copy pathconftest.py
File metadata and controls
62 lines (51 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from __future__ import annotations
import pytest
import json
import logging
from contextlib import contextmanager
from lib import config
from lib.common import safe_split
# explicit import for package-scope fixtures
from pkgfixtures import (
_xfs_config_on_hostA2,
_xfs_config_on_hostB1,
hostA2_with_xfsprogs,
hostB1_with_xfsprogs,
pool_with_saved_yum_state,
xfs_sr_on_hostA2,
xfs_sr_on_hostB1,
)
from typing import TYPE_CHECKING, Generator
if TYPE_CHECKING:
from lib.host import Host
from lib.sr import SR
from lib.vdi import VDI
from lib.vm import VM
@pytest.fixture(params=["thin"], scope="session")
def provisioning_type(request: pytest.FixtureRequest) -> str:
return request.param
@pytest.fixture(scope='module')
def vdi_on_linstor_sr(linstor_sr: SR) -> Generator[VDI, None, None]:
vdi = linstor_sr.create_vdi('LINSTOR-VDI-test', virtual_size=config.volume_size)
yield vdi
vdi.destroy()
@contextmanager
def _vm_on_linstor_sr(host: Host, linstor_sr: SR, vm_ref: str) -> Generator[VM]:
"""
Context manager to provide the fixture lifecycle on a VM on a Linstor SR
with different scopes without repeating the code.
"""
vm = host.import_vm(vm_ref, sr_uuid=linstor_sr.uuid)
try:
yield vm
finally:
logging.info("<< Destroy VM")
vm.destroy(verify=True)
@pytest.fixture(scope='module')
def vm_on_linstor_sr(host: Host, linstor_sr: SR, vm_ref: str) -> Generator[VM, None, None]:
with _vm_on_linstor_sr(host, linstor_sr, vm_ref) as vm:
yield vm
@pytest.fixture(scope='function')
def vm_on_linstor_sr_function(host: Host, linstor_sr: SR, vm_ref: str) -> Generator[VM]:
with _vm_on_linstor_sr(host, linstor_sr, vm_ref) as vm:
yield vm