Skip to content

Commit 4c2c41f

Browse files
committed
fix e2e tests.
1 parent 685a42f commit 4c2c41f

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

pkg/services/baremetal/host/host.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,9 @@ func (s *Service) ensureSSHKey(sshSecretRef infrav1.SSHSecretRef, sshSecret *cor
354354
return sshKey, actionComplete{}
355355
}
356356

357+
// handleIncompleteBoot checks if the reboot was successful.
358+
// If it was not successful, it tries other reboot methods.
359+
// Order: SSH -> Software -> Hardware.
357360
func (s *Service) handleIncompleteBoot(isRebootIntoRescue, isTimeout, isConnectionRefused bool) (failed bool, err error) {
358361
// Connection refused error might be a sign that the ssh port is wrong - but might also come
359362
// right after a reboot and is expected then. Therefore, we wait for some time and if the
@@ -713,7 +716,10 @@ func (s *Service) validateRescueSystemIsActive(sshClient sshclient.Client) (ok b
713716
if s.scope.HetznerBareMetalHost.Spec.Status.LastUpdated != nil {
714717
timeSinceReboot = time.Since(s.scope.HetznerBareMetalHost.Spec.Status.LastUpdated.Time).String()
715718
}
716-
719+
if !isSSHTimeoutError && !isSSHConnectionRefusedError {
720+
s.scope.Logger.Info("Expected the rescue system, but got different hostname", "hostName", hostName, "timeSinceReboot", timeSinceReboot)
721+
return false, actionContinue{delay: 10 * time.Second}
722+
}
717723
s.scope.Logger.Info("Could not reach rescue system. Will retry some seconds later.", "out", out.String(), "hostName", hostName,
718724
"isSSHTimeoutError", isSSHTimeoutError, "isSSHConnectionRefusedError", isSSHConnectionRefusedError, "timeSinceReboot", timeSinceReboot)
719725
return false, actionContinue{delay: 10 * time.Second}
@@ -1105,9 +1111,12 @@ func (s *Service) actionPreProvisioning(ctx context.Context) actionResult {
11051111
}
11061112
sshClient := s.scope.SSHClientFactory.NewClient(in)
11071113

1108-
ok, res := s.validateRescueSystemIsActive(sshClient)
1109-
if !ok {
1110-
return res
1114+
out := sshClient.GetHostName()
1115+
hostName := trimLineBreak(out.StdOut)
1116+
if hostName != rescue {
1117+
// This is unexpected. We should be in rescue mode.
1118+
return actionError{err: fmt.Errorf("expected rescue system, but got %q: %s", hostName,
1119+
out.String())}
11111120
}
11121121

11131122
exitStatus, output, err := sshClient.ExecutePreProvisionCommand(ctx, s.scope.PreProvisionCommand)
@@ -1141,9 +1150,12 @@ func (s *Service) actionImageInstalling(ctx context.Context) actionResult {
11411150
}
11421151
sshClient := s.scope.SSHClientFactory.NewClient(in)
11431152

1144-
ok, res := s.validateRescueSystemIsActive(sshClient)
1145-
if !ok {
1146-
return res
1153+
out := sshClient.GetHostName()
1154+
hostName := trimLineBreak(out.StdOut)
1155+
if hostName != rescue {
1156+
// This is unexpected. We should be in rescue mode.
1157+
return actionError{err: fmt.Errorf("expected rescue system, but got %q: %s", hostName,
1158+
out.String())}
11471159
}
11481160

11491161
state, err := sshClient.GetInstallImageState()

0 commit comments

Comments
 (0)