builder/common: only count handshake error if auth tried

This commit is contained in:
Mitchell Hashimoto 2013-07-16 11:15:47 -07:00
parent 29279415d0
commit 59c89faaf4
1 changed files with 9 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/mitchellh/packer/communicator/ssh" "github.com/mitchellh/packer/communicator/ssh"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"log" "log"
"strings"
"time" "time"
) )
@ -133,7 +134,14 @@ func (s *StepConnectSSH) waitForSSH(state map[string]interface{}) (packer.Commun
if err != nil { if err != nil {
log.Printf("SSH handshake err: %s", err) 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 { if handshakeAttempts < 10 {
// Try to connect via SSH a handful of times // Try to connect via SSH a handful of times
continue continue