diff --git a/conftest.py b/conftest.py index 92dc05070..69be1f6db 100644 --- a/conftest.py +++ b/conftest.py @@ -6,7 +6,7 @@ import lib.config as global_config -from lib.common import wait_for, vm_image, is_uuid +from lib.common import safe_split, wait_for, vm_image, is_uuid from lib.common import setup_formatted_and_mounted_disk, teardown_formatted_and_mounted_disk from lib.netutil import is_ipv6 from lib.pool import Pool @@ -283,7 +283,24 @@ def imported_vm(host, vm_ref): name = vm.name() logging.info(">> Reuse VM %s (%s) on host %s" % (vm_ref, name, host)) else: - vm = host.import_vm(vm_ref) + # where to import to: default SR, or first local SR + try: + from data import DEFAULT_SR + except ImportError: + DEFAULT_SR = 'default' + assert DEFAULT_SR in ['default', 'local'] + + if DEFAULT_SR == 'default': + vm = host.import_vm(vm_ref) + elif DEFAULT_SR == 'local': + local_sr_uuids = safe_split( + # xe sr-list doesn't support filtering by host UUID! + host.ssh(['xe sr-list host=$HOSTNAME content-type=user minimal=true']), + ',' + ) + assert local_sr_uuids, "The first pool master (host A1) MUST have a local SR since DEFAULT_SR=='local'" + vm = host.import_vm(vm_ref, local_sr_uuids[0]) + yield vm # teardown if not is_uuid(vm_ref): diff --git a/data.py-dist b/data.py-dist index 55aa737ea..94d325bf1 100644 --- a/data.py-dist +++ b/data.py-dist @@ -32,6 +32,16 @@ VM_IMAGES = { 'mini-linux-x86_64-uefi': 'alpine-uefi-minimal-3.12.0.xva' } +# In some cases, we may prefer to favour a local SR to store test VM disks, +# to avoid latency or unstabilities related to network or shared file servers. +# However it's not good practice to make a local SR the default SR for a pool of several hosts. +# Hence this configuration value that you can set to `local` so that our tests use this SR by default. +# This setting affects VMs managed by the `imported_vm` fixture. +# Possible values: +# - 'default': keep using the pool's default SR +# - 'local': use the first local SR found instead +DEFAULT_SR = 'default' + # Default NFS device config: DEFAULT_NFS_DEVICE_CONFIG = { # 'server': '10.0.0.2', # URL/Hostname of NFS server