Skip to content

Commit 910782b

Browse files
authored
Merge pull request #518 from xcp-ng/vml/xcpng-1061
Add a Host.wait_for_xapi_enabled method
2 parents 8ecc354 + 4f736dd commit 910782b

3 files changed

Lines changed: 44 additions & 15 deletions

File tree

lib/host.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
strtobool,
2626
to_xapi_bool,
2727
wait_for,
28+
wait_for_not,
2829
)
2930
from lib.netutil import wrap_ip
3031
from lib.network import Network
@@ -555,7 +556,36 @@ def restart_toolstack(self, verify: bool = False) -> None:
555556
logging.info("Restart toolstack on host %s" % self)
556557
self.ssh('xe-toolstack-restart')
557558
if verify:
558-
wait_for(self.is_enabled, "Wait for host enabled", timeout_secs=30 * 60)
559+
self.wait_for_xapi_enabled()
560+
561+
def wait_for_host_down(self, timeout_secs: int = 2 * 60) -> None:
562+
wait_for_not(
563+
lambda: commands.local_cmd(["ping", "-c1", self.hostname_or_ip], check=False).returncode == 0,
564+
"Wait for host down",
565+
timeout_secs=timeout_secs,
566+
retry_delay_secs=2,
567+
)
568+
569+
def wait_for_host_up(self, timeout_secs: int = 10 * 60) -> None:
570+
wait_for(
571+
lambda: commands.local_cmd(["ping", "-c1", self.hostname_or_ip], check=False).returncode == 0,
572+
"Wait for host up",
573+
timeout_secs=timeout_secs,
574+
retry_delay_secs=10,
575+
)
576+
577+
def wait_for_ssh_reachable(self, timeout_secs: int = 10 * 60) -> None:
578+
wait_for(
579+
lambda: commands.local_cmd(["nc", "-zw5", self.hostname_or_ip, "22"], check=False).returncode == 0,
580+
"Wait for ssh up on host",
581+
timeout_secs=timeout_secs,
582+
retry_delay_secs=5
583+
)
584+
585+
def wait_for_xapi_enabled(self, timeout_secs: int = 30 * 60) -> None:
586+
logging.info(f"Wait for XAPI to complete initialization on {self.hostname_or_ip}")
587+
self.ssh(f"xapi-wait-init-complete {timeout_secs}")
588+
assert self.is_enabled()
559589

560590
def is_enabled(self) -> bool:
561591
try:
@@ -679,12 +709,10 @@ def reboot(self, verify: bool = False) -> None:
679709
# error code. Instead, we schedule the reboot a few seconds later to let the ssh command return properly.
680710
self.ssh('systemd-run --on-active=2s reboot')
681711
if verify:
682-
wait_for(lambda: os.system(f"ping -c1 {self.hostname_or_ip} > /dev/null 2>&1"), "Wait for host down")
683-
wait_for(lambda: not os.system(f"ping -c1 {self.hostname_or_ip} > /dev/null 2>&1"),
684-
"Wait for host up", timeout_secs=10 * 60, retry_delay_secs=10)
685-
wait_for(lambda: not os.system(f"nc -zw5 {self.hostname_or_ip} 22"),
686-
"Wait for ssh up on host", timeout_secs=10 * 60, retry_delay_secs=5)
687-
wait_for(self.is_enabled, "Wait for XAPI to be ready", timeout_secs=30 * 60)
712+
self.wait_for_host_down()
713+
self.wait_for_host_up()
714+
self.wait_for_ssh_reachable()
715+
self.wait_for_xapi_enabled()
688716

689717
def management_network(self) -> str:
690718
return self.xe('network-list', {'bridge': self.inventory['MANAGEMENT_INTERFACE']}, minimal=True)

lib/pool.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from packaging import version
88

99
import lib.commands as commands
10-
from lib.common import HostAddress, _param_get, _param_set, safe_split, wait_for, wait_for_not
10+
from lib.common import HostAddress, _param_get, _param_set, safe_split, wait_for_not
1111
from lib.efi import EFIAuth
1212
from lib.host import Host
1313
from lib.sr import SR
@@ -30,10 +30,7 @@ def __init__(self, master_hostname_or_ip: HostAddress) -> None:
3030

3131
# wait for XAPI startup to be done, or we can get "Connection
3232
# refused (calling connect )" when calling self.hosts_uuids()
33-
wait_for(lambda: commands.ssh_with_result(master_hostname_or_ip,
34-
'xapi-wait-init-complete 60').returncode == 0,
35-
f"Wait for XAPI init to be complete on {master_hostname_or_ip}",
36-
timeout_secs=30 * 60)
33+
self.master.wait_for_xapi_enabled()
3734

3835
logging.info("Getting Pool info for %r", master_hostname_or_ip)
3936
for host_uuid in self.hosts_uuids():
@@ -294,7 +291,11 @@ def eject_host(self, host: Host) -> None:
294291
master.xe('pool-eject', {'host-uuid': host.uuid, 'force': True})
295292
wait_for_not(lambda: host.uuid in self.hosts_uuids(), f"Wait for host {host} to be ejected of pool {master}.")
296293
self.hosts = [h for h in self.hosts if h.uuid != host.uuid]
297-
wait_for(host.is_enabled, f"Wait for host {host} to restart in its own pool.", timeout_secs=10 * 60)
294+
# The ejected host should reboot
295+
host.wait_for_host_down()
296+
host.wait_for_host_up()
297+
host.wait_for_ssh_reachable()
298+
host.wait_for_xapi_enabled()
298299

299300
def network_named(self, network_name: str) -> str:
300301
return self.master.xe('network-list', {'name-label': network_name}, minimal=True)

tests/install/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ def _test_firstboot(self, create_vms: list[VM], mode: str, *,
207207
# pool master must be reachable here
208208
pool = Pool(ip)
209209

210-
# wait for XAPI
211-
wait_for(pool.master.is_enabled, "Wait for XAPI to be ready", timeout_secs=30 * 60)
210+
# Master should be available now that the pool is instanciated
211+
assert pool.master.is_enabled()
212212

213213
if lsb_rel in ["8.2.1", "8.3.0", "8.4.0"]:
214214
SERVICES = ["control-domain-params-init",

0 commit comments

Comments
 (0)