Skip to content

Commit 0b80377

Browse files
committed
Rebase and change from comment of the PR for test_linstor_sr_pool_update
Signed-off-by: Erwan Croze <erwan.croze@vates.tech>
1 parent e05c5e6 commit 0b80377

3 files changed

Lines changed: 27 additions & 21 deletions

File tree

lib/host.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,10 @@ def pool_has_vm(self, vm_uuid: str, vm_type: str = 'vm') -> bool:
480480
else:
481481
return self.xe('vm-list', {'uuid': vm_uuid}, minimal=True) == vm_uuid
482482

483-
def install_updates(self, enablerepo=None):
483+
def install_updates(self, enablerepo: str | None = None) -> str:
484484
logging.info("Install updates on host %s" % self)
485-
enablerepo_cmd = ['--enablerepo=%s' % enablerepo] if enablerepo is not None else []
486-
return self.ssh(f"yum update -y {enablerepo_cmd}")
485+
enablerepo_arg = f" --enablerepo={enablerepo}" if enablerepo is not None else ""
486+
return self.ssh(f"yum update -y{enablerepo_arg}")
487487

488488
def get_system_uuid(self) -> str:
489489
"""Get system uuid of current host.
@@ -611,11 +611,11 @@ def is_enabled(self) -> bool:
611611
# If XAPI is not ready yet, or the host is down, this will throw. We return False in that case.
612612
return False
613613

614-
def has_updates(self, enablerepo=None):
615-
enablerepo_cmd = ['--enablerepo=%s' % enablerepo] if enablerepo is not None else []
614+
def has_updates(self, enablerepo: str | None = None) -> bool:
615+
enablerepo_arg = f" --enablerepo={enablerepo}" if enablerepo is not None else ""
616616
try:
617617
# yum check-update returns 100 if there are updates, 1 if there's an error, 0 if no updates
618-
self.ssh(f"yum check-update {enablerepo_cmd}")
618+
self.ssh(f"yum check-update{enablerepo_arg}")
619619
# returned 0, else there would have been a SSHCommandFailed
620620
return False
621621
except commands.SSHCommandFailed as e:

tests/storage/linstor/conftest.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,19 @@ def storage_pool_name(provisioning_type: str) -> str:
108108
def provisioning_type(request: pytest.FixtureRequest) -> str:
109109
return request.param
110110

111+
_linstor_upgrade_test = False
112+
113+
# pytest hook: called once at startup, before test collection.
111114
def pytest_configure(config):
112-
config._linstor_upgrade_test = False
115+
global _linstor_upgrade_test
116+
_linstor_upgrade_test = False
113117

118+
# pytest hook: called after all tests are collected, before any test runs.
114119
def pytest_collection_modifyitems(config, items):
120+
global _linstor_upgrade_test
115121
for item in items:
116122
if item.get_closest_marker("upgrade_test"):
117-
config._linstor_upgrade_test = True
123+
_linstor_upgrade_test = True
118124
break
119125

120126
@pytest.fixture(scope='package')
@@ -123,11 +129,9 @@ def pool_with_linstor(
123129
lvm_disks: None,
124130
pool_with_saved_yum_state: Pool,
125131
_linstor_config: LinstorConfig,
126-
request
127132
) -> Generator[Pool, None, None]:
128133
import concurrent.futures
129134

130-
dont_use_testing_repo = request.config._linstor_upgrade_test
131135
pool = pool_with_saved_yum_state
132136

133137
def ensure_linstor_not_installed(host: Host) -> None:
@@ -142,10 +146,10 @@ def ensure_linstor_not_installed(host: Host) -> None:
142146
def install_linstor(host: Host) -> None:
143147
logging.info(f"Installing {LINSTOR_PACKAGE} on host {host}...")
144148
host.yum_install([LINSTOR_RELEASE_PACKAGE])
145-
if dont_use_testing_repo:
146-
host.yum_install([LINSTOR_PACKAGE])
147-
else:
149+
if _linstor_upgrade_test:
148150
host.yum_install([LINSTOR_PACKAGE], enablerepo="xcp-ng-linstor-testing")
151+
else:
152+
host.yum_install([LINSTOR_PACKAGE])
149153
# Needed because the linstor driver is not in the xapi sm-plugins list
150154
# before installing the LINSTOR packages.
151155
host.ssh('systemctl restart multipathd')

tests/storage/linstor/test_linstor_sr.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import pytest
22

3+
import concurrent.futures
34
import json
45
import logging
56
import shlex
7+
import threading
68
import time
79

810
from lib.commands import SSHCommandFailed
@@ -254,16 +256,14 @@ def test_linstor_missing(self, linstor_sr: SR, host: Host) -> None:
254256
@pytest.mark.reboot
255257
@pytest.mark.small_vm
256258
@pytest.mark.upgrade_test
257-
def test_linstor_sr_pool_update(self, linstor_sr, vm_on_linstor_sr):
259+
def test_linstor_sr_pool_update(self, linstor_sr: SR, vm_on_linstor_sr: VM) -> None:
258260
"""
259261
Perform update on the Linstor SR pool hosts while ensuring VM availability.
260262
1. Identify all hosts in the SR pool and order them with the master first.
261263
2. Update all hosts if updates are available.
262-
3. Reboot all hosts.
264+
3. Reboot updated hosts.
263265
4. Sequentially ensure that the VM can start on all hosts.
264266
"""
265-
import concurrent.futures, threading
266-
267267
sr = linstor_sr
268268
vm = vm_on_linstor_sr
269269
updates_applied = []
@@ -274,7 +274,7 @@ def test_linstor_sr_pool_update(self, linstor_sr, vm_on_linstor_sr):
274274

275275
# RPU is disabled for pools with XOSTOR SRs.
276276
# LINSTOR expects that we always use satellites and controllers with the same version on all hosts.
277-
def install_updates_on(host):
277+
def install_updates_on(host: Host) -> None:
278278
logging.info("Checking on host %s", host.hostname_or_ip)
279279
if host.has_updates(enablerepo="xcp-ng-linstor-testing"):
280280
host.install_updates(enablerepo="xcp-ng-linstor-testing")
@@ -287,11 +287,13 @@ def install_updates_on(host):
287287
executor.map(install_updates_on, hosts)
288288

289289
# Reboot updated hosts
290-
def reboot_updated(host):
290+
def reboot_updated(host: Host) -> None:
291291
host.reboot(verify=True)
292292

293-
with concurrent.futures.ThreadPoolExecutor() as executor:
294-
executor.map(reboot_updated, updates_applied)
293+
if updates_applied:
294+
with concurrent.futures.ThreadPoolExecutor() as executor:
295+
executor.map(reboot_updated, updates_applied)
296+
wait_for(sr.all_pbds_attached, "Wait for PBD attached")
295297

296298
# Ensure VM is able to boot on all the hosts
297299
for h in hosts:

0 commit comments

Comments
 (0)