Skip to content

Commit

Permalink
Merge pull request #187 from xcp-ng/stormi/only-use-xo-for-migrate
Browse files Browse the repository at this point in the history
Only connect XO for migration tests
  • Loading branch information
stormi authored Jan 22, 2024
2 parents 65ce81d + ae97b28 commit 833b24c
Show file tree
Hide file tree
Showing 25 changed files with 47 additions and 33 deletions.
30 changes: 22 additions & 8 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from lib.common import setup_formatted_and_mounted_disk, teardown_formatted_and_mounted_disk
from lib.pool import Pool
from lib.vm import VM
from lib.xo import xo_cli

# Import package-scoped fixtures. Although we need to define them in a separate file so that we can
# then import them in individual packages to fix the buggy package scope handling by pytest, we also
Expand Down Expand Up @@ -88,15 +89,8 @@ def pytest_configure(config):
global_config.ssh_output_max_lines = int(config.getoption('--ssh-output-max-lines'))

def setup_host(hostname_or_ip):
logging.info(">>> Connect host %s" % hostname_or_ip)
pool = Pool(hostname_or_ip)
h = pool.master
# XO connection
if not h.skip_xo_config:
h.xo_server_add(h.user, h.password)
else:
h.xo_get_server_id(store=True)
wait_for(h.xo_server_connected, timeout_secs=10)
return h

@pytest.fixture(scope='session')
Expand All @@ -105,8 +99,28 @@ def hosts(request):
hostname_list = request.param.split(',')
host_list = [setup_host(hostname_or_ip) for hostname_or_ip in hostname_list]
yield host_list

@pytest.fixture(scope='session')
def registered_xo_cli():
# The fixture is not responsible for establishing the connection.
# We just check that xo-cli is currently registered
try:
xo_cli('server.getAll')
except Exception as e:
raise Exception(f"Check for registered xo_cli failed: {e}")

@pytest.fixture(scope='session')
def hosts_with_xo(hosts, registered_xo_cli):
for h in hosts:
logging.info(">>> Connect host %s" % h)
if not h.skip_xo_config:
h.xo_server_add(h.user, h.password)
else:
h.xo_get_server_id(store=True)
wait_for(h.xo_server_connected, timeout_secs=10)
yield hosts
# teardown
for h in host_list:
for h in hosts:
if not h.skip_xo_config:
logging.info("<<< Disconnect host %s" % h)
h.xo_server_remove()
Expand Down
6 changes: 2 additions & 4 deletions lib/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,19 +349,17 @@ def yum_restore_saved_state(self):
self.saved_packages_list = None
self.saved_rollback_id = None

def reboot(self, verify=False, reconnect_xo=True):
def reboot(self, verify=False):
logging.info("Reboot host %s" % self)
try:
self.ssh(['reboot'])
except commands.SSHCommandFailed as e:
# ssh connection may get killed by the reboot and terminate with an error code
if "closed by remote host" not in e.stdout:
raise
if verify or reconnect_xo:
if verify:
wait_for_not(self.is_enabled, "Wait for host down")
wait_for(self.is_enabled, "Wait for host up", timeout_secs=1800)
if reconnect_xo and self.is_master():
self.xo_server_reconnect()

def management_network(self):
return self.xe('network-list', {'bridge': self.inventory['MANAGEMENT_INTERFACE']}, minimal=True)
Expand Down
1 change: 1 addition & 0 deletions tests/guest-tools/unix/test_guest_tools_unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def test_clean_shutdown(self, running_vm):
vm.start()
vm.wait_for_vm_running_and_ssh_up()

@pytest.mark.usefixtures('hosts_with_xo')
def test_storage_migration(self, running_vm, host, hostA2, local_sr_on_hostA2, state):
vm = running_vm
# migrate to default SR on hostA2
Expand Down
2 changes: 1 addition & 1 deletion tests/misc/test_basic_without_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_checkpoint(self, imported_vm):
# Live migration tests
# We want to test storage migration (memory+disks) and live migration without storage migration (memory only).
# The order will depend on the initial location of the VM: a local SR or a shared SR.
@pytest.mark.usefixtures("hostA2")
@pytest.mark.usefixtures("hostA2", 'hosts_with_xo')
def test_live_migrate(self, imported_vm, existing_shared_sr):
def live_migrate(vm, dest_host, dest_sr, check_vdis=False):
vm.migrate(dest_host, dest_sr)
Expand Down
1 change: 1 addition & 0 deletions tests/misc/test_cross_pool_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

@pytest.mark.multi_vms # run on a variety of VMs
@pytest.mark.big_vm # and also on a really big VM ideally
@pytest.mark.usefixtures('hosts_with_xo')
def test_cross_pool_migration(hostB1, imported_vm):
vm = imported_vm.clone()
try:
Expand Down
2 changes: 1 addition & 1 deletion tests/storage/cephfs/test_cephfs_sr_crosspool_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@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
@pytest.mark.usefixtures("hostB1", "local_sr_on_hostB1")
@pytest.mark.usefixtures("hostB1", "hosts_with_xo", "local_sr_on_hostB1")
class Test:
def test_cold_crosspool_migration(self, host, hostB1, vm_on_cephfs_sr, cephfs_sr, local_sr_on_hostB1):
cold_migration_then_come_back(vm_on_cephfs_sr, host, cephfs_sr, hostB1, local_sr_on_hostB1)
Expand Down
2 changes: 1 addition & 1 deletion tests/storage/cephfs/test_cephfs_sr_intrapool_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@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
@pytest.mark.usefixtures("hostA2", "local_sr_on_hostA2")
@pytest.mark.usefixtures("hostA2", "hosts_with_xo", "local_sr_on_hostA2")
class Test:
def test_live_intrapool_shared_migration(self, host, hostA2, vm_on_cephfs_sr, cephfs_sr):
live_storage_migration_then_come_back(vm_on_cephfs_sr, host, cephfs_sr, hostA2, cephfs_sr)
Expand Down
2 changes: 1 addition & 1 deletion tests/storage/ext/test_ext_sr_crosspool_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@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
@pytest.mark.usefixtures("hostB1", "local_sr_on_hostB1")
@pytest.mark.usefixtures("hostB1", "hosts_with_xo", "local_sr_on_hostB1")
class Test:
def test_cold_crosspool_migration(self, host, hostB1, vm_on_ext_sr, ext_sr, local_sr_on_hostB1):
cold_migration_then_come_back(vm_on_ext_sr, host, ext_sr, hostB1, local_sr_on_hostB1)
Expand Down
2 changes: 1 addition & 1 deletion tests/storage/ext/test_ext_sr_intrapool_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@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
@pytest.mark.usefixtures("hostA2", "local_sr_on_hostA2")
@pytest.mark.usefixtures("hostA2", "hosts_with_xo", "local_sr_on_hostA2")
class Test:
def test_cold_intrapool_migration(self, host, hostA2, vm_on_ext_sr, ext_sr, local_sr_on_hostA2):
cold_migration_then_come_back(vm_on_ext_sr, host, ext_sr, hostA2, local_sr_on_hostA2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@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
@pytest.mark.usefixtures("hostB1", "local_sr_on_hostB1", "sr_disk_for_all_hosts")
@pytest.mark.usefixtures("hostB1", "hosts_with_xo", "local_sr_on_hostB1", "sr_disk_for_all_hosts")
class Test:
def test_cold_crosspool_migration(self, host, hostB1, vm_on_glusterfs_sr, glusterfs_sr, local_sr_on_hostB1):
cold_migration_then_come_back(vm_on_glusterfs_sr, host, glusterfs_sr, hostB1, local_sr_on_hostB1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@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
@pytest.mark.usefixtures("hostA2", "local_sr_on_hostA2", "sr_disk_for_all_hosts")
@pytest.mark.usefixtures("hostA2", "hosts_with_xo", "local_sr_on_hostA2", "sr_disk_for_all_hosts")
class Test:
def test_live_intrapool_shared_migration(self, host, hostA2, vm_on_glusterfs_sr, glusterfs_sr):
live_storage_migration_then_come_back(vm_on_glusterfs_sr, host, glusterfs_sr, hostA2, glusterfs_sr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@pytest.mark.small_vm # run with a small VM to test the features
@pytest.mark.big_vm # and ideally on a big VM to test it scales
@pytest.mark.usefixtures("hostB1", "local_sr_on_hostB1")
@pytest.mark.usefixtures("hostB1", "hosts_with_xo", "local_sr_on_hostB1")
class Test:
def test_cold_crosspool_migration(self, host, hostB1, vm_on_linstor_sr, linstor_sr, local_sr_on_hostB1):
cold_migration_then_come_back(vm_on_linstor_sr, host, linstor_sr, hostB1, local_sr_on_hostB1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@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
@pytest.mark.usefixtures("hostA2", "local_sr_on_hostA2")
@pytest.mark.usefixtures("hostA2", "hosts_with_xo", "local_sr_on_hostA2")
class Test:
def test_live_intrapool_shared_migration(self, host, hostA2, vm_on_linstor_sr, linstor_sr):
live_storage_migration_then_come_back(vm_on_linstor_sr, host, linstor_sr, hostA2, linstor_sr)
Expand Down
2 changes: 1 addition & 1 deletion tests/storage/lvm/test_lvm_sr_crosspool_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@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
@pytest.mark.usefixtures("hostB1", "local_sr_on_hostB1")
@pytest.mark.usefixtures("hostB1", "hosts_with_xo", "local_sr_on_hostB1")
class Test:
def test_cold_crosspool_migration(self, host, hostB1, vm_on_lvm_sr, lvm_sr, local_sr_on_hostB1):
cold_migration_then_come_back(vm_on_lvm_sr, host, lvm_sr, hostB1, local_sr_on_hostB1)
Expand Down
2 changes: 1 addition & 1 deletion tests/storage/lvm/test_lvm_sr_intrapool_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@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
@pytest.mark.usefixtures("hostA2", "local_sr_on_hostA2")
@pytest.mark.usefixtures("hostA2", "hosts_with_xo", "local_sr_on_hostA2")
class Test:
def test_cold_intrapool_migration(self, host, hostA2, vm_on_lvm_sr, lvm_sr, local_sr_on_hostA2):
cold_migration_then_come_back(vm_on_lvm_sr, host, lvm_sr, hostA2, local_sr_on_hostA2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@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
@pytest.mark.usefixtures("hostB1", "local_sr_on_hostB1")
@pytest.mark.usefixtures("hostB1", "hosts_with_xo", "local_sr_on_hostB1")
class Test:
def test_cold_crosspool_migration(self, host, hostB1, vm_on_lvmoiscsi_sr, lvmoiscsi_sr, local_sr_on_hostB1):
cold_migration_then_come_back(vm_on_lvmoiscsi_sr, host, lvmoiscsi_sr, hostB1, local_sr_on_hostB1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@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
@pytest.mark.usefixtures("hostA2", "local_sr_on_hostA2")
@pytest.mark.usefixtures("hostA2", "hosts_with_xo", "local_sr_on_hostA2")
class Test:
def test_live_intrapool_shared_migration(self, host, hostA2, vm_on_lvmoiscsi_sr, lvmoiscsi_sr):
live_storage_migration_then_come_back(vm_on_lvmoiscsi_sr, host, lvmoiscsi_sr, hostA2, lvmoiscsi_sr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@pytest.mark.small_vm # run with a small VM to test the features
@pytest.mark.big_vm # and ideally on a big VM to test it scales
@pytest.mark.usefixtures("hostB1", "local_sr_on_hostB1")
@pytest.mark.usefixtures("hostB1", "hosts_with_xo", "local_sr_on_hostB1")
class Test:
def test_cold_crosspool_migration(self, host, hostB1, vm_on_moosefs_sr, moosefs_sr, local_sr_on_hostB1):
cold_migration_then_come_back(vm_on_moosefs_sr, host, moosefs_sr, hostB1, local_sr_on_hostB1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@pytest.mark.small_vm # run with a small VM to test the features
@pytest.mark.big_vm # and ideally on a big VM to test it scales
@pytest.mark.usefixtures("hostA2", "local_sr_on_hostA2")
@pytest.mark.usefixtures("hostA2", "hosts_with_xo", "local_sr_on_hostA2")
class Test:
def test_live_intrapool_shared_migration(self, host, hostA2, vm_on_moosefs_sr, moosefs_sr):
live_storage_migration_then_come_back(vm_on_moosefs_sr, host, moosefs_sr, hostA2, moosefs_sr)
Expand Down
2 changes: 1 addition & 1 deletion tests/storage/nfs/test_nfs_sr_crosspool_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@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
@pytest.mark.usefixtures("hostB1", "local_sr_on_hostB1")
@pytest.mark.usefixtures("hostB1", "hosts_with_xo", "local_sr_on_hostB1")
class Test:
def test_cold_crosspool_migration(self, host, hostB1, vm_on_nfs_sr, nfs_sr, local_sr_on_hostB1):
cold_migration_then_come_back(vm_on_nfs_sr, host, nfs_sr, hostB1, local_sr_on_hostB1)
Expand Down
2 changes: 1 addition & 1 deletion tests/storage/nfs/test_nfs_sr_intrapool_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@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
@pytest.mark.usefixtures("hostA2", "local_sr_on_hostA2")
@pytest.mark.usefixtures("hostA2", "hosts_with_xo", "local_sr_on_hostA2")
class Test:
def test_live_intrapool_shared_migration(self, host, hostA2, vm_on_nfs_sr, nfs_sr):
live_storage_migration_then_come_back(vm_on_nfs_sr, host, nfs_sr, hostA2, nfs_sr)
Expand Down
2 changes: 1 addition & 1 deletion tests/storage/xfs/test_xfs_sr_crosspool_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@pytest.mark.small_vm # run with a small VM to test the features
@pytest.mark.big_vm # and ideally on a big VM to test it scales
@pytest.mark.usefixtures("hostB1", "local_sr_on_hostB1")
@pytest.mark.usefixtures("hostB1", "hosts_with_xo", "local_sr_on_hostB1")
class Test:
def test_cold_crosspool_migration(self, host, hostB1, vm_on_xfs_sr, xfs_sr, local_sr_on_hostB1):
cold_migration_then_come_back(vm_on_xfs_sr, host, xfs_sr, hostB1, local_sr_on_hostB1)
Expand Down
2 changes: 1 addition & 1 deletion tests/storage/xfs/test_xfs_sr_intrapool_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@pytest.mark.small_vm # run with a small VM to test the features
@pytest.mark.big_vm # and ideally on a big VM to test it scales
@pytest.mark.usefixtures("hostA2", "local_sr_on_hostA2")
@pytest.mark.usefixtures("hostA2", "hosts_with_xo", "local_sr_on_hostA2")
class Test:
def test_cold_intrapool_migration(self, host, hostA2, vm_on_xfs_sr, xfs_sr, local_sr_on_hostA2):
cold_migration_then_come_back(vm_on_xfs_sr, host, xfs_sr, hostA2, local_sr_on_hostA2)
Expand Down
2 changes: 1 addition & 1 deletion tests/storage/zfs/test_zfs_sr_crosspool_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@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
@pytest.mark.usefixtures("hostB1", "local_sr_on_hostB1")
@pytest.mark.usefixtures("hostB1", "hosts_with_xo", "local_sr_on_hostB1")
class Test:
def test_cold_crosspool_migration(self, host, hostB1, vm_on_zfs_sr, zfs_sr, local_sr_on_hostB1):
cold_migration_then_come_back(vm_on_zfs_sr, host, zfs_sr, hostB1, local_sr_on_hostB1)
Expand Down
2 changes: 1 addition & 1 deletion tests/storage/zfs/test_zfs_sr_intrapool_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@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
@pytest.mark.usefixtures("hostA2", "local_sr_on_hostA2")
@pytest.mark.usefixtures("hostA2", "hosts_with_xo", "local_sr_on_hostA2")
class Test:
def test_cold_intrapool_migration(self, host, hostA2, vm_on_zfs_sr, zfs_sr, local_sr_on_hostA2):
cold_migration_then_come_back(vm_on_zfs_sr, host, zfs_sr, hostA2, local_sr_on_hostA2)
Expand Down

0 comments on commit 833b24c

Please sign in to comment.