-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: BenjiReis <[email protected]>
- Loading branch information
1 parent
80556b1
commit bdb84ec
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import pytest | ||
|
||
# Requirements: | ||
# From --hosts parameter: | ||
# - host(A1): first XCP-ng host >= 8.2 with an additional unused disk for the SR. | ||
# From --vm parameter | ||
# - A VM to import to the LINSTOR SR | ||
# And: | ||
# - access to XCP-ng RPM repository from hostA1 | ||
|
||
class TestLinstorDisklessResource: | ||
@pytest.mark.small_vm | ||
def test_diskless_kept(self, host, linstor_sr, vm_on_linstor_sr): | ||
vm = vm_on_linstor_sr | ||
vdi_uuids = vm.vdi_uuids() | ||
vdi_uuid = None | ||
for v in vdi_uuids: | ||
if vm.get_vdi_sr_uuid(v) == linstor_sr.uuid: | ||
vdi_uuid = v | ||
break | ||
assert vdi_uuid is not None | ||
|
||
controller_option="--controllers=" | ||
for h in host.pool.hosts: | ||
controller_option += f"{h.hostname_or_ip}," | ||
|
||
# Get volume name from VDI uuid | ||
# "xcp/volume/{vdi_uuid}/volume-name": "{volume_name}" | ||
output = host.ssh([ | ||
"linstor-kv-tool", "--dump-volumes", "-g", "xcp-sr-linstor_group_thin_device", | ||
"|", "grep", "volume-name", "|", "grep", vdi_uuid | ||
]) | ||
volume_name = output.split(': ')[1].split('"')[1] | ||
|
||
# Find host where volume is diskless | ||
# | {volume_name} | {host} | 7017 | Unused | Ok | UpToDate | 2023-10-24 18:52:05 | | ||
lines = host.ssh([ | ||
"linstor", controller_option, "resource", "list", | ||
"|", "grep", volume_name, "|", "grep", "UpToDate" | ||
]).splitlines() | ||
diskfulls = [] | ||
for line in lines: | ||
hostname = line.split('|')[2].strip() | ||
diskfulls += hostname | ||
|
||
diskless = None | ||
for h in host.pool.hosts: | ||
if h.param_get("name-label").lower() not in diskfulls: | ||
diskless = h | ||
assert diskless | ||
|
||
# Start VM on host with diskless resource | ||
vm.start(on=diskless.uuid) | ||
vm.wait_for_os_booted() | ||
|
||
# Ensure resource remains diskless | ||
lines = host.ssh([ | ||
"linstor", controller_option, "resource", "list", | ||
"|", "grep", volume_name, "|", "grep", "UpToDate" | ||
]).splitlines() | ||
diskfulls = [] | ||
for line in lines: | ||
hostname = line.split('|')[2].strip() | ||
diskfulls += hostname | ||
assert diskless.param_get("name-label").lower() not in diskfulls | ||
|
||
vm.shutdown(verify=True) | ||
|
||
# Ensure resource remains diskless | ||
lines = host.ssh([ | ||
"linstor", controller_option, "resource", "list", | ||
"|", "grep", volume_name, "|", "grep", "UpToDate" | ||
]).splitlines() | ||
diskfulls = [] | ||
for line in lines: | ||
hostname = line.split('|')[2].strip() | ||
diskfulls += hostname | ||
assert diskless.param_get("name-label").lower() not in diskfulls |