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
1cea606f
Commit
1cea606f
authored
Jun 02, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
communicator/ssh: Adhere to new Communicator interface
parent
a21fe8c4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
29 deletions
+21
-29
communicator/ssh/communicator.go
communicator/ssh/communicator.go
+9
-23
communicator/ssh/communicator_test.go
communicator/ssh/communicator_test.go
+12
-6
No files found.
communicator/ssh/communicator.go
View file @
1cea606f
...
...
@@ -23,33 +23,19 @@ func New(c net.Conn, config *ssh.ClientConfig) (result *comm, err error) {
return
}
func
(
c
*
comm
)
Start
(
cmd
string
)
(
remote
*
packer
.
RemoteCommand
,
err
error
)
{
func
(
c
*
comm
)
Start
(
cmd
*
packer
.
RemoteCmd
)
(
err
error
)
{
session
,
err
:=
c
.
client
.
NewSession
()
if
err
!=
nil
{
return
}
// Create the buffers to store our stdin/stdout/stderr
stdin
:=
new
(
bytes
.
Buffer
)
stdout
:=
new
(
bytes
.
Buffer
)
stderr
:=
new
(
bytes
.
Buffer
)
// Setup our session
session
.
Stdin
=
stdin
session
.
Stdout
=
stdout
session
.
Stderr
=
stderr
// Setup the remote command
remote
=
&
packer
.
RemoteCommand
{
Stdin
:
stdin
,
Stdout
:
stdout
,
Stderr
:
stderr
,
Exited
:
false
,
ExitStatus
:
-
1
,
}
session
.
Stdin
=
cmd
.
Stdin
session
.
Stdout
=
cmd
.
Stdout
session
.
Stderr
=
cmd
.
Stderr
log
.
Printf
(
"starting remote command: %s"
,
cmd
)
err
=
session
.
Start
(
cmd
+
"
\n
"
)
log
.
Printf
(
"starting remote command: %s"
,
cmd
.
Command
)
err
=
session
.
Start
(
cmd
.
Command
+
"
\n
"
)
if
err
!=
nil
{
return
}
...
...
@@ -60,15 +46,15 @@ func (c *comm) Start(cmd string) (remote *packer.RemoteCommand, err error) {
defer
session
.
Close
()
err
:=
session
.
Wait
()
remote
.
ExitStatus
=
0
cmd
.
ExitStatus
=
0
if
err
!=
nil
{
exitErr
,
ok
:=
err
.
(
*
ssh
.
ExitError
)
if
ok
{
remote
.
ExitStatus
=
exitErr
.
ExitStatus
()
cmd
.
ExitStatus
=
exitErr
.
ExitStatus
()
}
}
remote
.
Exited
=
true
cmd
.
Exited
=
true
}()
return
...
...
communicator/ssh/communicator_test.go
View file @
1cea606f
...
...
@@ -8,6 +8,7 @@ import (
"net"
"strings"
"testing"
"time"
)
// private key for mock server
...
...
@@ -178,19 +179,24 @@ func TestStart(t *testing.T) {
t
.
Fatalf
(
"error connecting to SSH: %s"
,
err
)
}
remote
,
err
:=
client
.
Start
(
"echo foo"
)
var
cmd
packer
.
RemoteCmd
stdout
:=
new
(
bytes
.
Buffer
)
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"
)
remote
.
Wait
()
for
!
cmd
.
Exited
{
time
.
Sleep
(
50
*
time
.
Millisecond
)
}
// Should have the correct output
output
:=
remote
.
Stdout
.
(
*
bytes
.
Buffer
)
.
String
()
if
output
!=
"ack: echo foo"
{
t
.
Fatalf
(
"unknown output: %#v"
,
output
)
if
stdout
.
String
()
!=
"ack: echo foo"
{
t
.
Fatalf
(
"unknown output: %#v"
,
stdout
.
String
())
}
}
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