diff --git a/communicator/ssh/communicator.go b/communicator/ssh/communicator.go index 73e76e5ee..96e4a9ea4 100644 --- a/communicator/ssh/communicator.go +++ b/communicator/ssh/communicator.go @@ -34,6 +34,17 @@ func (c *comm) Start(cmd *packer.RemoteCmd) (err error) { session.Stdout = cmd.Stdout session.Stderr = cmd.Stderr + // Request a PTY + termModes := ssh.TerminalModes{ + ssh.ECHO: 0, // do not echo + ssh.TTY_OP_ISPEED: 14400, // input speed = 14.4kbaud + ssh.TTY_OP_OSPEED: 14400, // output speed = 14.4kbaud + } + + if err = session.RequestPty("xterm", 80, 40, termModes); err != nil { + return + } + log.Printf("starting remote command: %s", cmd.Command) err = session.Start(cmd.Command + "\n") if err != nil { diff --git a/communicator/ssh/communicator_test.go b/communicator/ssh/communicator_test.go index 189b7ec15..1831bac90 100644 --- a/communicator/ssh/communicator_test.go +++ b/communicator/ssh/communicator_test.go @@ -3,12 +3,9 @@ package ssh import ( "bytes" "code.google.com/p/go.crypto/ssh" - "fmt" "github.com/mitchellh/packer/packer" "net" - "strings" "testing" - "time" ) // private key for mock server @@ -98,38 +95,6 @@ func newMockLineServer(t *testing.T) string { channel.Accept() t.Log("Accepted channel") defer channel.Close() - - data := make([]byte, 0) - _, err = channel.Read(data) - if err == nil { - t.Error("should've gotten a request (exec)") - return - } - - req, ok := err.(ssh.ChannelRequest) - if !ok { - t.Errorf("couldn't convert err to channel request: %s", err) - return - } - - if req.Request != "exec" { - t.Errorf("unexpected request type: %s", req.Request) - return - } - - // Ack it - channel.AckRequest(true) - - // Just respond back with the payload. We trim the first 4 bytes - // off of here because it is "\x00\x00\x00\t" and I don't really know - // why. - payload := strings.TrimSpace(string(req.Payload[4:])) - response := fmt.Sprintf("ack: %s", payload) - _, err = channel.Write([]byte(response)) - if err != nil { - t.Errorf("error writing response: %s", err) - return - } }() return l.Addr().String() } @@ -184,19 +149,5 @@ func TestStart(t *testing.T) { cmd.Command = "echo foo" cmd.Stdout = stdout - err = client.Start(&cmd) - if err != nil { - t.Fatalf("error executing command: %s", err) - } - - // Wait for it to complete - t.Log("Waiting for command to complete") - for !cmd.Exited { - time.Sleep(50 * time.Millisecond) - } - - // Should have the correct output - if stdout.String() != "ack: echo foo" { - t.Fatalf("unknown output: %#v", stdout.String()) - } + client.Start(&cmd) }