Skip to content

Commit 6e260a4

Browse files
committed
Robustify LINSTOR _get_diskful_hosts test regarding coalesce
It's possible that the test fails due to an incorrect verification on the resource linked to a VDI. Indeed, if a coalesce occurs just after fetching the diskless resource to be monitored, it may be deleted which causes the test to fail. The fix is therefore to refetch the resource associated with a VDI rather than caching it. Signed-off-by: Ronan Abhamon <ronan.abhamon@vates.tech>
1 parent 2f30ecc commit 6e260a4

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

tests/storage/linstor/test_linstor_sr.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,21 @@ def test_linstor_missing(self, linstor_sr, host):
137137

138138
# --- Test diskless resources --------------------------------------------------
139139

140-
def _get_diskful_hosts(host, controller_option, volume_name):
140+
def _get_diskful_hosts(host, controller_option, sr_group_name, vdi_uuid):
141141
# TODO: If any resource is in a temporary creation state or unknown, then need to wait intelligently.
142142
attempt = 0
143143
retries = 3
144144
sleep_sec = 5
145145

146146
while attempt < retries:
147147
try:
148+
# Get volume name from VDI UUID
149+
# "xcp/volume/{vdi_uuid}/volume-name": "{volume_name}"
150+
volume_name = host.ssh([
151+
"linstor-kv-tool", "--dump-volumes", "-g", sr_group_name,
152+
"|", "grep", "volume-name", "|", "grep", f"/{vdi_uuid}/"
153+
]).split(': ')[1].split('"')[1]
154+
148155
# Find host where volume is UpToDate
149156
# | {volume_name} | {host} | 7017 | Unused | Ok | UpToDate | 2023-10-24 18:52:05 |
150157
lines = host.ssh([
@@ -163,8 +170,8 @@ def _get_diskful_hosts(host, controller_option, volume_name):
163170
raise
164171
time.sleep(sleep_sec)
165172

166-
def _ensure_resource_remain_diskless(host, controller_option, volume_name, diskless):
167-
diskfuls = _get_diskful_hosts(host, controller_option, volume_name)
173+
def _ensure_resource_remain_diskless(host, controller_option, sr_group_name, vdi_uuid, diskless):
174+
diskfuls = _get_diskful_hosts(host, controller_option, sr_group_name, vdi_uuid)
168175
for diskless_host in diskless:
169176
assert diskless_host.param_get("name-label").lower() not in diskfuls
170177

@@ -181,16 +188,7 @@ def test_diskless_kept(self, host, linstor_sr, vm_on_linstor_sr, storage_pool_na
181188
controller_option += f"{member.hostname_or_ip},"
182189

183190
sr_group_name = "xcp-sr-" + storage_pool_name.replace("/", "_")
184-
185-
# Get volume name from VDI uuid
186-
# "xcp/volume/{vdi_uuid}/volume-name": "{volume_name}"
187-
output = host.ssh([
188-
"linstor-kv-tool", "--dump-volumes", "-g", sr_group_name,
189-
"|", "grep", "volume-name", "|", "grep", f"/{vdi_uuid}/"
190-
])
191-
volume_name = output.split(': ')[1].split('"')[1]
192-
193-
diskfuls = _get_diskful_hosts(host, controller_option, volume_name)
191+
diskfuls = _get_diskful_hosts(host, controller_option, sr_group_name, vdi_uuid)
194192
diskless = []
195193
for member in host.pool.hosts:
196194
if member.param_get("name-label").lower() not in diskfuls:
@@ -200,7 +198,7 @@ def test_diskless_kept(self, host, linstor_sr, vm_on_linstor_sr, storage_pool_na
200198
# Start VM on host with diskless resource
201199
vm.start(on=diskless[0].uuid)
202200
vm.wait_for_os_booted()
203-
_ensure_resource_remain_diskless(host, controller_option, volume_name, diskless)
201+
_ensure_resource_remain_diskless(host, controller_option, sr_group_name, vdi_uuid, diskless)
204202

205203
vm.shutdown(verify=True)
206-
_ensure_resource_remain_diskless(host, controller_option, volume_name, diskless)
204+
_ensure_resource_remain_diskless(host, controller_option, sr_group_name, vdi_uuid, diskless)

0 commit comments

Comments
 (0)