communicator/ssh: request a PTY
This commit is contained in:
parent
1a8395baab
commit
1e61cc2bd3
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue