}
# Switch off, setup PXE and switch on to the installer
-power_state($ho, 0);
-setup_netboot_installer();
-power_cycle_sleep($ho);
-power_state($ho, 1);
-
-# Wait for the host to finish booting
-logm("Waiting for the installer to boot");
-await_tcp(get_timeout($ho,'reboot',$timeout), 5, $ho);
+power_reboot_attempts($ho, sub {
+ setup_netboot_installer();
+}, sub {
+ # Wait for the host to finish booting
+ logm("Waiting for the installer to boot");
+ my $wait_start = time;
+ await_tcp(get_timeout($ho,'reboot',$timeout), 5, $ho);
+
+ # We want to check that we actually rebooted. We do this by
+ # comparing the (putative) installer environment's uptime,
+ # with the time we spent waiting for it to appear.
+ my $timeoutput = target_cmd_output_root($ho,
+ 'date +%s; sysctl -n kern.boottime');
+ logm("got:\n$timeoutput");
+ $timeoutput =~ s{^(\d+)\n}{} or die "date: $timeoutput ?";
+ my $target_now = $1;
+ $timeoutput =~ m{\ssec\s?=\s?(\d+)\b} or die "sysctl: $timeoutput ?";
+ my $target_boottime = $1;
+
+ my $uptime = $target_now - $target_boottime;
+ my $elapsed = time - $wait_start;
+ logm("uptime=$uptime elapsed=$elapsed");
+ $uptime < $elapsed or die "uptime >= elapsed";
+
+}, undef, 'install');
if ($bootonly) {
hostprop_putative_record($ho, "MemdiskAppend", $memdisk_append)