Skip to content

Commit 2d17a45

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 4b00118 commit 2d17a45

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
@@ -105,13 +105,19 @@ def storage_pool_name(provisioning_type: str) -> str:
105105
def provisioning_type(request: pytest.FixtureRequest) -> str:
106106
return request.param
107107

108+
_linstor_upgrade_test = False
109+
110+
# pytest hook: called once at startup, before test collection.
108111
def pytest_configure(config):
109-
config._linstor_upgrade_test = False
112+
global _linstor_upgrade_test
113+
_linstor_upgrade_test = False
110114

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

117123
@pytest.fixture(scope='package')
@@ -120,11 +126,9 @@ def pool_with_linstor(
120126
lvm_disks: None,
121127
pool_with_saved_yum_state: Pool,
122128
_linstor_config: LinstorConfig,
123-
request
124129
) -> Generator[Pool, None, None]:
125130
import concurrent.futures
126131

127-
dont_use_testing_repo = request.config._linstor_upgrade_test
128132
pool = pool_with_saved_yum_state
129133

130134
def check_linstor_installed(host: Host) -> None:
@@ -139,10 +143,10 @@ def check_linstor_installed(host: Host) -> None:
139143
def install_linstor(host: Host) -> None:
140144
logging.info(f"Installing {LINSTOR_PACKAGE} on host {host}...")
141145
host.yum_install([LINSTOR_RELEASE_PACKAGE])
142-
if dont_use_testing_repo:
143-
host.yum_install([LINSTOR_PACKAGE])
144-
else:
146+
if _linstor_upgrade_test:
145147
host.yum_install([LINSTOR_PACKAGE], enablerepo="xcp-ng-linstor-testing")
148+
else:
149+
host.yum_install([LINSTOR_PACKAGE])
146150
# Needed because the linstor driver is not in the xapi sm-plugins list
147151
# before installing the LINSTOR packages.
148152
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,6 +1,8 @@
11
import pytest
22

3+
import concurrent.futures
34
import logging
5+
import threading
46
import time
57

68
from lib.commands import SSHCommandFailed
@@ -102,16 +104,14 @@ def test_linstor_missing(self, linstor_sr: SR, host: Host) -> None:
102104
@pytest.mark.reboot
103105
@pytest.mark.small_vm
104106
@pytest.mark.upgrade_test
105-
def test_linstor_sr_pool_update(self, linstor_sr, vm_on_linstor_sr):
107+
def test_linstor_sr_pool_update(self, linstor_sr: SR, vm_on_linstor_sr: VM) -> None:
106108
"""
107109
Perform update on the Linstor SR pool hosts while ensuring VM availability.
108110
1. Identify all hosts in the SR pool and order them with the master first.
109111
2. Update all hosts if updates are available.
110-
3. Reboot all hosts.
112+
3. Reboot updated hosts.
111113
4. Sequentially ensure that the VM can start on all hosts.
112114
"""
113-
import concurrent.futures, threading
114-
115115
sr = linstor_sr
116116
vm = vm_on_linstor_sr
117117
updates_applied = []
@@ -122,7 +122,7 @@ def test_linstor_sr_pool_update(self, linstor_sr, vm_on_linstor_sr):
122122

123123
# RPU is disabled for pools with XOSTOR SRs.
124124
# LINSTOR expects that we always use satellites and controllers with the same version on all hosts.
125-
def install_updates_on(host):
125+
def install_updates_on(host: Host) -> None:
126126
logging.info("Checking on host %s", host.hostname_or_ip)
127127
if host.has_updates(enablerepo="xcp-ng-linstor-testing"):
128128
host.install_updates(enablerepo="xcp-ng-linstor-testing")
@@ -135,11 +135,13 @@ def install_updates_on(host):
135135
executor.map(install_updates_on, hosts)
136136

137137
# Reboot updated hosts
138-
def reboot_updated(host):
138+
def reboot_updated(host: Host) -> None:
139139
host.reboot(verify=True)
140140

141-
with concurrent.futures.ThreadPoolExecutor() as executor:
142-
executor.map(reboot_updated, updates_applied)
141+
if updates_applied:
142+
with concurrent.futures.ThreadPoolExecutor() as executor:
143+
executor.map(reboot_updated, updates_applied)
144+
wait_for(sr.all_pbds_attached, "Wait for PBD attached")
143145

144146
# Ensure VM is able to boot on all the hosts
145147
for h in hosts:

0 commit comments

Comments
 (0)