|
25 | 25 | strtobool, |
26 | 26 | to_xapi_bool, |
27 | 27 | wait_for, |
| 28 | + wait_for_not, |
28 | 29 | ) |
29 | 30 | from lib.netutil import wrap_ip |
30 | 31 | from lib.network import Network |
@@ -555,7 +556,36 @@ def restart_toolstack(self, verify: bool = False) -> None: |
555 | 556 | logging.info("Restart toolstack on host %s" % self) |
556 | 557 | self.ssh('xe-toolstack-restart') |
557 | 558 | 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() |
559 | 589 |
|
560 | 590 | def is_enabled(self) -> bool: |
561 | 591 | try: |
@@ -679,12 +709,10 @@ def reboot(self, verify: bool = False) -> None: |
679 | 709 | # error code. Instead, we schedule the reboot a few seconds later to let the ssh command return properly. |
680 | 710 | self.ssh('systemd-run --on-active=2s reboot') |
681 | 711 | 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() |
688 | 716 |
|
689 | 717 | def management_network(self) -> str: |
690 | 718 | return self.xe('network-list', {'bridge': self.inventory['MANAGEMENT_INTERFACE']}, minimal=True) |
|
0 commit comments