From 59c89faaf44f566dd72a2aa92fe8a897ddd2a034 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 16 Jul 2013 11:15:47 -0700 Subject: [PATCH] builder/common: only count handshake error if auth tried --- builder/common/step_connect_ssh.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/builder/common/step_connect_ssh.go b/builder/common/step_connect_ssh.go index 2f32b7c0f..61698380c 100644 --- a/builder/common/step_connect_ssh.go +++ b/builder/common/step_connect_ssh.go @@ -8,6 +8,7 @@ import ( "github.com/mitchellh/packer/communicator/ssh" "github.com/mitchellh/packer/packer" "log" + "strings" "time" ) @@ -133,7 +134,14 @@ func (s *StepConnectSSH) waitForSSH(state map[string]interface{}) (packer.Commun if err != nil { log.Printf("SSH handshake err: %s", err) - handshakeAttempts += 1 + // Only count this as an attempt if we were able to attempt + // to authenticate. Note this is very brittle since it depends + // on the string of the error... but I don't see any other way. + if strings.Contains(err.Error(), "authenticate") { + log.Printf("Detected authentication error. Increasing handshake attempts.") + handshakeAttempts += 1 + } + if handshakeAttempts < 10 { // Try to connect via SSH a handful of times continue