Skip to content

Commit c409347

Browse files
committed
t/m/test_host_evacuate.py: Support pool of more than 2 hosts
This test only worked with pool contains 2 hosts, since the destination host is known before using host_evacuate (as there is no other option). When running with more hosts in pool, the dest host will be selected dynamically, there is no options to force the destination host. So on 3 hosts pool there are 50% chances the desired one will be used. The test is now waiting the VM to be running and then checking that the destination host is different than the source one. The VDI check is also preserved but may be unnecessary since all hosts in pool are expected to have references to VDIs. There is no need to set the destination host in parameter anymore, but second host still appear as a requirement (since pool should at least contain 2 pools to use the evacuate feature). Signed-off-by: Philippe Coval <philippe.coval@vates.tech>
1 parent 9d8c607 commit c409347

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

tests/migration/test_host_evacuate.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# Must NOT be the network used to access the NFS SR.
2424
# This network will be disconnected at some point during the tests
2525

26-
def _host_evacuate_test(source_host: Host, dest_host: Host, network_uuid: str | None,
26+
def _host_evacuate_test(source_host: Host, network_uuid: str | None,
2727
vm: VM, expect_error: bool = False, error: str = "") -> None:
2828
vm.start(on=source_host.uuid)
2929
vm.wait_for_os_booted()
@@ -37,9 +37,11 @@ def _host_evacuate_test(source_host: Host, dest_host: Host, network_uuid: str |
3737
else:
3838
logging.info(f"Attempt evacuating host {source_host}. This should fail.")
3939
source_host.xe('host-evacuate', args)
40-
wait_for(lambda: vm.all_vdis_on_host(dest_host), "Wait for all VDIs on destination host")
41-
wait_for(lambda: vm.is_running_on_host(dest_host), "Wait for VM to be running on destination host")
4240
vm.wait_for_os_booted()
41+
dest_host = vm.get_residence_host()
42+
logging.info(f"VM migrated from {source_host} to {dest_host}")
43+
assert dest_host != source_host, "Destination host should differ from source"
44+
assert vm.all_vdis_on_host(dest_host), "Check for all VDIs on destination host"
4345
assert not expect_error, "host-evacuate should have raised: %s" % error
4446
except SSHCommandFailed as e:
4547
if not (expect_error and e.stdout.find(error) > -1):
@@ -66,14 +68,14 @@ def _save_ip_configuration_mode(host: Host, pif_uuid: str) -> dict[str, str | bo
6668
@pytest.mark.small_vm # what we test here is that evacuate works, the goal is not to test with various VMs
6769
class TestHostEvacuate:
6870
def test_host_evacuate(self, host: Host, hostA2: Host, vm_on_nfs_sr: VM) -> None:
69-
_host_evacuate_test(host, hostA2, None, vm_on_nfs_sr)
71+
_host_evacuate_test(host, None, vm_on_nfs_sr)
7072

7173
@pytest.mark.complex_prerequisites # requires a special network setup.
7274
@pytest.mark.small_vm # what we test here is the network-uuid option, the goal is not to test with various VMs
7375
@pytest.mark.usefixtures("host_at_least_8_3")
7476
class TestHostEvacuateWithNetwork:
7577
def test_host_evacuate_with_network(self, host: Host, hostA2: Host, second_network: str, vm_on_nfs_sr: VM) -> None:
76-
_host_evacuate_test(host, hostA2, second_network, vm_on_nfs_sr)
78+
_host_evacuate_test(host, second_network, vm_on_nfs_sr)
7779

7880
def test_host_evacuate_with_network_no_ip(
7981
self, host: Host, hostA2: Host, second_network: str, vm_on_nfs_sr: VM
@@ -86,7 +88,7 @@ def test_host_evacuate_with_network_no_ip(
8688
host.xe(reconfigure_method, {'uuid': pif_uuid, 'mode': 'none'})
8789
try:
8890
no_ip_error = 'The specified interface cannot be used because it has no IP address'
89-
_host_evacuate_test(host, hostA2, second_network, vm_on_nfs_sr, True, no_ip_error)
91+
_host_evacuate_test(host, second_network, vm_on_nfs_sr, True, no_ip_error)
9092
finally:
9193
logging.info(f"Restore the configuration of PIF {pif_uuid}")
9294
host.xe(reconfigure_method, args)
@@ -100,7 +102,7 @@ def test_host_evacuate_with_network_not_attached(
100102
try:
101103
not_attached_error = \
102104
'The operation you requested cannot be performed because the specified PIF is currently unplugged'
103-
_host_evacuate_test(host, hostA2, second_network, vm_on_nfs_sr, True, not_attached_error)
105+
_host_evacuate_test(host, second_network, vm_on_nfs_sr, True, not_attached_error)
104106
finally:
105107
logging.info(f"Re-plug PIF {pif_uuid}")
106108
host.xe('pif-plug', {'uuid': pif_uuid})
@@ -116,7 +118,7 @@ def test_host_evacuate_with_network_not_present(
116118
host.xe('pif-forget', {'uuid': pif_uuid})
117119
try:
118120
not_present_error = 'This host has no PIF on the given network'
119-
_host_evacuate_test(host, hostA2, second_network, vm_on_nfs_sr, True, not_present_error)
121+
_host_evacuate_test(host, second_network, vm_on_nfs_sr, True, not_present_error)
120122
finally:
121123
host.xe('pif-scan', {'host-uuid': hostA2.uuid})
122124
pif_uuid = host.xe('pif-list', {'host-uuid': hostA2.uuid, 'network-uuid': second_network}, minimal=True)

0 commit comments

Comments
 (0)