Skip to content

Commit 6db10aa

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 cc4d36c commit 6db10aa

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.
@@ -598,11 +598,11 @@ def is_enabled(self) -> bool:
598598
# If XAPI is not ready yet, or the host is down, this will throw. We return False in that case.
599599
return False
600600

601-
def has_updates(self, enablerepo=None):
602-
enablerepo_cmd = ['--enablerepo=%s' % enablerepo] if enablerepo is not None else []
601+
def has_updates(self, enablerepo: str | None = None) -> bool:
602+
enablerepo_arg = f" --enablerepo={enablerepo}" if enablerepo is not None else ""
603603
try:
604604
# yum check-update returns 100 if there are updates, 1 if there's an error, 0 if no updates
605-
self.ssh(f"yum check-update {enablerepo_cmd}")
605+
self.ssh(f"yum check-update{enablerepo_arg}")
606606
# returned 0, else there would have been a SSHCommandFailed
607607
return False
608608
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 check_linstor_installed(host: Host) -> None:
@@ -142,10 +146,10 @@ def check_linstor_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
@@ -237,16 +239,14 @@ def test_linstor_missing(self, linstor_sr: SR, host: Host) -> None:
237239
@pytest.mark.reboot
238240
@pytest.mark.small_vm
239241
@pytest.mark.upgrade_test
240-
def test_linstor_sr_pool_update(self, linstor_sr, vm_on_linstor_sr):
242+
def test_linstor_sr_pool_update(self, linstor_sr: SR, vm_on_linstor_sr: VM) -> None:
241243
"""
242244
Perform update on the Linstor SR pool hosts while ensuring VM availability.
243245
1. Identify all hosts in the SR pool and order them with the master first.
244246
2. Update all hosts if updates are available.
245-
3. Reboot all hosts.
247+
3. Reboot updated hosts.
246248
4. Sequentially ensure that the VM can start on all hosts.
247249
"""
248-
import concurrent.futures, threading
249-
250250
sr = linstor_sr
251251
vm = vm_on_linstor_sr
252252
updates_applied = []
@@ -257,7 +257,7 @@ def test_linstor_sr_pool_update(self, linstor_sr, vm_on_linstor_sr):
257257

258258
# RPU is disabled for pools with XOSTOR SRs.
259259
# LINSTOR expects that we always use satellites and controllers with the same version on all hosts.
260-
def install_updates_on(host):
260+
def install_updates_on(host: Host) -> None:
261261
logging.info("Checking on host %s", host.hostname_or_ip)
262262
if host.has_updates(enablerepo="xcp-ng-linstor-testing"):
263263
host.install_updates(enablerepo="xcp-ng-linstor-testing")
@@ -270,11 +270,13 @@ def install_updates_on(host):
270270
executor.map(install_updates_on, hosts)
271271

272272
# Reboot updated hosts
273-
def reboot_updated(host):
273+
def reboot_updated(host: Host) -> None:
274274
host.reboot(verify=True)
275275

276-
with concurrent.futures.ThreadPoolExecutor() as executor:
277-
executor.map(reboot_updated, updates_applied)
276+
if updates_applied:
277+
with concurrent.futures.ThreadPoolExecutor() as executor:
278+
executor.map(reboot_updated, updates_applied)
279+
wait_for(sr.all_pbds_attached, "Wait for PBD attached")
278280

279281
# Ensure VM is able to boot on all the hosts
280282
for h in hosts:

0 commit comments

Comments
 (0)