Skip to content

Commit

Permalink
Rewrite generic storage tests to deduplicate
Browse files Browse the repository at this point in the history
Signed-off-by: Damien Thenot <damien.thenot@vates.tech>
  • Loading branch information
Nambrok committed Mar 10, 2025
1 parent 3052845 commit 1157685
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 181 deletions.
7 changes: 7 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ def pytest_addoption(parser):
"4KiB blocksize to be formatted and used in storage tests. "
"Set it to 'auto' to let the fixtures auto-detect available disks."
)
parser.addoption(
"--sr-type",
action="append",
default=[],
help="Name of SR type to run on generic SR tests. "
"Set it to 'all' to run on all generic SR types."
)

def pytest_configure(config):
global_config.ignore_ssh_banner = config.getoption('--ignore-ssh-banner')
Expand Down
24 changes: 0 additions & 24 deletions tests/storage/ext/conftest.py

This file was deleted.

69 changes: 0 additions & 69 deletions tests/storage/ext/test_ext_sr.py

This file was deleted.

File renamed without changes.
35 changes: 35 additions & 0 deletions tests/storage/generic/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import logging
import pytest

SR_TYPES = ["ext", "lvm"]

def pytest_generate_tests(metafunc):
if "sr_type" in metafunc.fixturenames:
cmdline_sr_type = metafunc.config.getoption("sr_type")
if "all" in cmdline_sr_type:
metafunc.parametrize("sr_type", SR_TYPES, scope="package")
else:
metafunc.parametrize("sr_type", cmdline_sr_type, scope="package")

@pytest.fixture(scope='package')
def generic_sr(host, sr_disk, sr_type):
""" A sr_type SR on first host. """
sr_name = "{}-local-SR-test".format(sr_type.upper())
sr = host.sr_create(sr_type, sr_name, {'device': '/dev/' + sr_disk})
yield sr
# teardown
sr.destroy()

@pytest.fixture(scope='module')
def vdi_on_generic_sr(generic_sr):
vdi = generic_sr.create_vdi('GEN-local-VDI-test')
yield vdi
vdi.destroy()

@pytest.fixture(scope='module')
def vm_on_generic_sr(host, generic_sr, vm_ref):
vm = host.import_vm(vm_ref, sr_uuid=generic_sr.uuid)
yield vm
# teardown
logging.info("<< Destroy VM")
vm.destroy(verify=True)
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,48 @@
# Requirements:
# - one XCP-ng host with an additional unused disk for the SR

class TestLVMSRCreateDestroy:
class TestGENSRCreateDestroy:
"""
Tests that do not use fixtures that setup the SR or import VMs,
because they precisely need to test SR creation and destruction,
and VM import.
"""

def test_create_sr_with_missing_device(self, host):
try_to_create_sr_with_missing_device('lvm', 'LVM-local-SR-test', host)
def test_create_sr_with_missing_device(self, host, sr_type):
sr_name = "{}-local-SR-test".format(sr_type.upper())
try_to_create_sr_with_missing_device(sr_type, sr_name, host)

def test_create_and_destroy_sr(self, host, sr_disk):
def test_create_and_destroy_sr(self, host, sr_disk, sr_type):
# Create and destroy tested in the same test to leave the host as unchanged as possible
sr = host.sr_create('lvm', "LVM-local-SR-test", {'device': '/dev/' + sr_disk}, verify=True)
sr_name = "{}-local-SR-test".format(sr_type.upper())
sr = host.sr_create(sr_type, sr_name, {'device': '/dev/' + sr_disk}, verify=True)
# import a VM in order to detect vm import issues here rather than in the vm_on_xfs_fixture used in
# the next tests, because errors in fixtures break teardown
vm = host.import_vm(vm_image('mini-linux-x86_64-bios'), sr_uuid=sr.uuid)
vm.destroy(verify=True)
sr.destroy(verify=True)

@pytest.mark.usefixtures("lvm_sr")
class TestLVMSR:
@pytest.mark.usefixtures("generic_sr")
class TestGENSR:
@pytest.mark.quicktest
def test_quicktest(self, lvm_sr):
lvm_sr.run_quicktest()
def test_quicktest(self, generic_sr):
generic_sr.run_quicktest()

def test_vdi_is_not_open(self, vdi_on_lvm_sr):
assert not vdi_is_open(vdi_on_lvm_sr)
def test_vdi_is_not_open(self, vdi_on_generic_sr):
assert not vdi_is_open(vdi_on_generic_sr)

@pytest.mark.small_vm # run with a small VM to test the features
@pytest.mark.big_vm # and ideally with a big VM to test it scales
def test_start_and_shutdown_VM(self, vm_on_lvm_sr):
vm = vm_on_lvm_sr
def test_start_and_shutdown_VM(self, vm_on_generic_sr):
vm = vm_on_generic_sr
vm.start()
vm.wait_for_os_booted()
vm.shutdown(verify=True)

@pytest.mark.small_vm
@pytest.mark.big_vm
def test_snapshot(self, vm_on_lvm_sr):
vm = vm_on_lvm_sr
def test_snapshot(self, vm_on_generic_sr):
vm = vm_on_generic_sr
vm.start()
try:
vm.wait_for_os_booted()
Expand All @@ -56,9 +58,9 @@ def test_snapshot(self, vm_on_lvm_sr):

@pytest.mark.reboot
@pytest.mark.small_vm
def test_reboot(self, host, lvm_sr, vm_on_lvm_sr):
sr = lvm_sr
vm = vm_on_lvm_sr
def test_reboot(self, host, generic_sr, vm_on_generic_sr):
sr = generic_sr
vm = vm_on_generic_sr
host.reboot(verify=True)
wait_for(sr.all_pbds_attached, "Wait for PBD attached")
# start the VM as a way to check that the underlying SR is operational
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
@pytest.mark.big_vm # and ideally with a big VM to test it scales
@pytest.mark.usefixtures("hostB1", "local_sr_on_hostB1")
class Test:
def test_cold_crosspool_migration(self, host, hostB1, vm_on_ext_sr, local_sr_on_hostB1):
cold_migration_then_come_back(vm_on_ext_sr, host, hostB1, local_sr_on_hostB1)
def test_cold_crosspool_migration(self, host, hostB1, vm_on_generic_sr, local_sr_on_hostB1):
cold_migration_then_come_back(vm_on_generic_sr, host, hostB1, local_sr_on_hostB1)

def test_live_crosspool_migration(self, host, hostB1, vm_on_ext_sr, local_sr_on_hostB1):
live_storage_migration_then_come_back(vm_on_ext_sr, host, hostB1, local_sr_on_hostB1)
def test_live_crosspool_migration(self, host, hostB1, vm_on_generic_sr, local_sr_on_hostB1):
live_storage_migration_then_come_back(vm_on_generic_sr, host, hostB1, local_sr_on_hostB1)
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
@pytest.mark.big_vm # and ideally with a big VM to test it scales
@pytest.mark.usefixtures("hostA2", "local_sr_on_hostA2")
class Test:
def test_cold_intrapool_migration(self, host, hostA2, vm_on_ext_sr, local_sr_on_hostA2):
cold_migration_then_come_back(vm_on_ext_sr, host, hostA2, local_sr_on_hostA2)
def test_cold_intrapool_migration(self, host, hostA2, vm_on_generic_sr, local_sr_on_hostA2):
cold_migration_then_come_back(vm_on_generic_sr, host, hostA2, local_sr_on_hostA2)

def test_live_intrapool_migration(self, host, hostA2, vm_on_ext_sr, local_sr_on_hostA2):
live_storage_migration_then_come_back(vm_on_ext_sr, host, hostA2, local_sr_on_hostA2)
def test_live_intrapool_migration(self, host, hostA2, vm_on_generic_sr, local_sr_on_hostA2):
live_storage_migration_then_come_back(vm_on_generi_sr, host, hostA2, local_sr_on_hostA2)
Empty file removed tests/storage/lvm/__init__.py
Empty file.
24 changes: 0 additions & 24 deletions tests/storage/lvm/conftest.py

This file was deleted.

19 changes: 0 additions & 19 deletions tests/storage/lvm/test_lvm_sr_crosspool_migration.py

This file was deleted.

19 changes: 0 additions & 19 deletions tests/storage/lvm/test_lvm_sr_intrapool_migration.py

This file was deleted.

0 comments on commit 1157685

Please sign in to comment.