-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathconftest.py
More file actions
109 lines (88 loc) · 3.81 KB
/
Copy pathconftest.py
File metadata and controls
109 lines (88 loc) · 3.81 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
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
device_list = " ".join(devices)
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", "thick"], scope="session")
def provisioning_type(request):
return request.param
@pytest.fixture(scope='package')
def pool_with_linstor(hostA2, lvm_disks, pool_with_saved_yum_state):
import concurrent.futures
pool = pool_with_saved_yum_state
def is_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(is_linstor_installed, pool.hosts)
def install_linstor(host):
logging.info(f"Installing {LINSTOR_PACKAGE} on host {host}...")
host.yum_install([LINSTOR_RELEASE_PACKAGE])
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
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)