Skip to content

Add disk failure test to validate SR and VM resilience #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion tests/storage/linstor/test_linstor_sr.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this test break in a way that the teardown fails and leaves the pool in a bad state?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Short answer - No, because if test fails to mark a disk offline, it stays online and normal operations/teardown continues.

Long version -

In XOSTOR, each host has a dedicated LVM pool. Therefore, a disk failure within the pool effectively results in a failure of the entire Volume Group (VG) on that host — making it equivalent to a host-level failure from the storage perspective.

This test ensures that even if the VG on a host fails (while the host itself remains operational), the virtual machine (VM) should still be able to boot from any host — whether it's diskful or diskless. The goal is to confirm that a single disk or VG failure does not impact overall VM availability. (We can improvise test to consider an already running VMs scenario on the failing host.)

If the test fails due to issues like the disk not properly going offline, we reboot the affected host. In most cases, this brings the storage pool online and overall teardown is not affected.

An important caveat arises during failure conditions: if the random_host has open xcp-persistent-database and its VG fails due to disk loss, operations like VDI creation will fail. These will only resume once the xcp-persistent-database is reopened and functional on another healthy host — typically after rebooting the failed one. (We don't test additional VDI operations in this test.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving this to Draft as the caveat scenario needs extra work. Essentially when the xcp-persistent-database is InUse on failing disk-host, the VM.start operation gets stuck. As the Data and Metadata volume are not healthy underneath, normal SR operation does not work.

If VM.start, xcp-persistent-database is InUse, and failing disk-host are not together then the test works fine. This combination coming together is random.

@Wescoeur @Nambrok Can you review this scenario? and suggest if its known LINSTOR issue or a workaround can be applied to recover from hung VM.start case. For now, I'll use multiprocessing.Process to recover.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest
import time

from .conftest import LINSTOR_PACKAGE
from .conftest import GROUP_NAME, LINSTOR_PACKAGE
from lib.commands import SSHCommandFailed
from lib.common import wait_for, vm_image
from tests.storage import vdi_is_open
Expand Down Expand Up @@ -131,6 +131,67 @@ def test_linstor_missing(self, linstor_sr, host):
if not linstor_installed:
host.yum_install([LINSTOR_PACKAGE])

@pytest.mark.reboot
@pytest.mark.small_vm
def test_linstor_sr_fail_disk(self, linstor_sr, vm_on_linstor_sr, provisioning_type):
"""
Identify random host within the same pool, detect used disks, fail one, and test VM useability on LINSTOR SR.
"""
import random
import multiprocessing

sr = linstor_sr
if provisioning_type == "thick":
time.sleep(45) # Let xcp-persistent-database come in sync across the nodes

vm = vm_on_linstor_sr

# Fail a disk from random host of Linstor pool
try:
random_host = random.choice(sr.pool.hosts) # TBD: Choose Linstor Diskfull node
logging.info("Working on %s", random_host.hostname_or_ip)
devices = random_host.ssh('vgs ' + GROUP_NAME + ' -o pv_name --no-headings').split("\n")
# Choosing last device from list, assuming its least filled
fail_device = devices[-1].strip() # /dev/sdb
fail_device = random_host.ssh(['lsblk', fail_device, '--nodeps --output NAME --noheadings']) # sdb
logging.info("Attempting to fail device: %s", fail_device)
random_host.ssh(['echo', '"offline"', '>', '/sys/block/' + fail_device + '/device/state'])
except Exception as e:
# Offline disk shall connect back after host reboot. Teardown normally.
random_host.reboot(verify=True)
pytest.fail("Failed to simulate device failure. Error %s", e)

# Ensure that VM is able to start on all hosts despite Linstor pool disk failure
for h in sr.pool.hosts:
logging.info("Checking VM on host %s", h.hostname_or_ip)
try:
proc = multiprocessing.Process(target=vm.start, kwargs={'on': h.uuid})
proc.start()
proc.join(timeout=30)
if proc.is_alive():
proc.terminate()
proc.join()
logging.warning("VM start on host %s timed out. Recovering failed disk.", h.hostname_or_ip)
random_host.ssh(['echo', '"running"', '>', f'/sys/block/{fail_device}/device/state'])
# Handle in case VM.start succeed after disk becomes online
if vm.is_running():
vm.shutdown(verify=True, force_if_fails=True)
pytest.fail("VM start timed out on host %s after 30s. Disk recovered.", h.hostname_or_ip)
else: # VM booted fine
vm.wait_for_os_booted()
vm.shutdown(verify=True)
except Exception as e:
logging.info("Caught exception in multiprocessing: %s", e)

random_host.reboot(verify=True)

# Ensure PBDs are attached post reboot
if not sr.all_pbds_attached():
sr.plug_pbds()

# Ensure SR scan works and proceed for teardown
sr.scan()

# *** End of tests with reboots

# --- Test diskless resources --------------------------------------------------
Expand Down