add echo test to winrm connection.
This commit is contained in:
parent
0047de9b96
commit
959db1ac16
@ -1,13 +1,17 @@
|
|||||||
package communicator
|
package communicator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/packer/communicator/winrm"
|
"github.com/hashicorp/packer/communicator/winrm"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
|
winrmcmd "github.com/masterzen/winrm"
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -141,6 +145,39 @@ func (s *StepConnectWinRM) waitForWinRM(state multistep.StateBag, cancel <-chan
|
|||||||
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
// run an "echo" command to make sure winrm is actually connected before moving on.
|
||||||
|
var connectCheckCommand = winrmcmd.Powershell(`if (Test-Path variable:global:ProgressPreference){$ProgressPreference='SilentlyContinue'}; echo "WinRM connected."`)
|
||||||
|
var retryableSleep = 5 * time.Second
|
||||||
|
// run an "echo" command to make sure that the winrm is connected
|
||||||
|
for {
|
||||||
|
cmd := &packer.RemoteCmd{Command: connectCheckCommand}
|
||||||
|
var buf, buf2 bytes.Buffer
|
||||||
|
cmd.Stdout = &buf
|
||||||
|
cmd.Stdout = io.MultiWriter(cmd.Stdout, &buf2)
|
||||||
|
select {
|
||||||
|
case <-cancel:
|
||||||
|
log.Println("WinRM wait canceled, exiting loop")
|
||||||
|
return comm, fmt.Errorf("WinRM wait canceled")
|
||||||
|
case <-time.After(retryableSleep):
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("Checking that WinRM is connected with: '%s'", connectCheckCommand)
|
||||||
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
err := cmd.StartWithUi(comm, ui)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Communication connection err: %s", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("Connected to machine")
|
||||||
|
stdoutToRead := buf2.String()
|
||||||
|
if !strings.Contains(stdoutToRead, "WinRM connected.") {
|
||||||
|
log.Printf("echo didn't succeed; retrying...")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
return comm, nil
|
return comm, nil
|
||||||
}
|
}
|
||||||
|
@ -197,8 +197,6 @@ var waitForCommunicator = func(p *Provisioner) error {
|
|||||||
|
|
||||||
log.Printf("Connected to machine")
|
log.Printf("Connected to machine")
|
||||||
stdoutToRead := buf2.String()
|
stdoutToRead := buf2.String()
|
||||||
buf2.Reset()
|
|
||||||
buf.Reset()
|
|
||||||
if !strings.Contains(stdoutToRead, "restarted.") {
|
if !strings.Contains(stdoutToRead, "restarted.") {
|
||||||
log.Printf("echo didn't succeed; retrying...")
|
log.Printf("echo didn't succeed; retrying...")
|
||||||
continue
|
continue
|
||||||
|
Loading…
x
Reference in New Issue
Block a user