Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
1e61cc2b
Commit
1e61cc2b
authored
Jun 23, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
communicator/ssh: request a PTY
parent
1a8395ba
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
50 deletions
+12
-50
communicator/ssh/communicator.go
communicator/ssh/communicator.go
+11
-0
communicator/ssh/communicator_test.go
communicator/ssh/communicator_test.go
+1
-50
No files found.
communicator/ssh/communicator.go
View file @
1e61cc2b
...
...
@@ -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
{
...
...
communicator/ssh/communicator_test.go
View file @
1e61cc2b
...
...
@@ -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
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment