Skip to content

Commit

Permalink
Merge pull request #206 from xcp-ng/stormi/local-vms
Browse files Browse the repository at this point in the history
Add data.py DEFAULT_SR setting
  • Loading branch information
stormi authored Mar 5, 2024
2 parents 9bf7adb + b18aea4 commit 56845e5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
21 changes: 19 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 10 additions & 0 deletions data.py-dist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 56845e5

Please sign in to comment.