forked from xcp-ng/xcp-ng-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
124 lines (100 loc) · 4.33 KB
/
Copy pathconftest.py
File metadata and controls
124 lines (100 loc) · 4.33 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import logging
import pytest
import lib.commands as commands
# explicit import for package-scope fixtures
from pkgfixtures import pool_with_saved_yum_state
GROUP_NAME = 'linstor_group'
STORAGE_POOL_NAME = f'{GROUP_NAME}/thin_device'
LINSTOR_RELEASE_PACKAGE = 'xcp-ng-release-linstor'
LINSTOR_PACKAGE = 'xcp-ng-linstor'
@pytest.fixture(scope='package')
def lvm_disks(host, sr_disks_for_all_hosts, provisioning_type):
devices = [f"/dev/{disk}" for disk in sr_disks_for_all_hosts]
hosts = host.pool.hosts
for host in hosts:
for device in devices:
try:
host.ssh(['pvcreate', '-ff', '-y', device])
except commands.SSHCommandFailed as e:
if e.stdout.endswith('Mounted filesystem?'):
host.ssh(['vgremove', '-f', GROUP_NAME, '-y'])
host.ssh(['pvcreate', '-ff', '-y', device])
elif e.stdout.endswith('excluded by a filter.'):
host.ssh(['wipefs', '-a', device])
host.ssh(['pvcreate', '-ff', '-y', device])
else:
raise e
host.ssh(['vgcreate', GROUP_NAME] + devices)
if provisioning_type == 'thin':
host.ssh(['lvcreate', '-l', '100%FREE', '-T', STORAGE_POOL_NAME])
yield devices
for host in hosts:
host.ssh(['vgremove', '-f', GROUP_NAME])
for device in devices:
host.ssh(['pvremove', device])
@pytest.fixture(scope="package")
def storage_pool_name(provisioning_type):
return GROUP_NAME if provisioning_type == "thick" else STORAGE_POOL_NAME
@pytest.fixture(params=["thin"], scope="session")
def provisioning_type(request):
return request.param
def pytest_configure(config):
config._linstor_upgrade_test = False
def pytest_collection_modifyitems(config, items):
for item in items:
if item.get_closest_marker("upgrade_test"):
config._linstor_upgrade_test = True
break
@pytest.fixture(scope='package')
def pool_with_linstor(hostA2, lvm_disks, pool_with_saved_yum_state, request):
import concurrent.futures
dont_use_testing_repo = request.config._linstor_upgrade_test
pool = pool_with_saved_yum_state
def check_linstor_installed(host):
if host.is_package_installed(LINSTOR_PACKAGE):
raise Exception(
f'{LINSTOR_PACKAGE} is already installed on host {host}. This should not be the case.'
)
with concurrent.futures.ThreadPoolExecutor() as executor:
executor.map(check_linstor_installed, pool.hosts)
def install_linstor(host):
logging.info(f"Installing {LINSTOR_PACKAGE} on host {host}...")
host.yum_install([LINSTOR_RELEASE_PACKAGE])
if dont_use_testing_repo:
host.yum_install([LINSTOR_PACKAGE])
else:
host.yum_install([LINSTOR_PACKAGE], enablerepo="xcp-ng-linstor-testing")
# Needed because the linstor driver is not in the xapi sm-plugins list
# before installing the LINSTOR packages.
host.ssh(["systemctl", "restart", "multipathd"])
host.restart_toolstack(verify=True)
with concurrent.futures.ThreadPoolExecutor() as executor:
executor.map(install_linstor, pool.hosts)
yield pool
# Need to remove this package as we have separate run of `test_create_sr_without_linstor`
# for `thin` and `thick` `provisioning_type`.
def remove_linstor(host):
logging.info(f"Cleaning up python-linstor from host {host}...")
host.yum_remove(["python-linstor"])
with concurrent.futures.ThreadPoolExecutor() as executor:
executor.map(remove_linstor, pool.hosts)
@pytest.fixture(scope='package')
def linstor_sr(pool_with_linstor, provisioning_type, storage_pool_name):
sr = pool_with_linstor.master.sr_create('linstor', 'LINSTOR-SR-test', {
'group-name': storage_pool_name,
'redundancy': str(min(len(pool_with_linstor.hosts), 3)),
'provisioning': provisioning_type
}, shared=True)
yield sr
sr.destroy()
@pytest.fixture(scope='module')
def vdi_on_linstor_sr(linstor_sr):
vdi = linstor_sr.create_vdi('LINSTOR-VDI-test')
yield vdi
vdi.destroy()
@pytest.fixture(scope='module')
def vm_on_linstor_sr(host, linstor_sr, vm_ref):
vm = host.import_vm(vm_ref, sr_uuid=linstor_sr.uuid)
yield vm
logging.info("<< Destroy VM")
vm.destroy(verify=True)