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
4b4fe228
Commit
4b4fe228
authored
Jun 13, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
helper/communicator: can be disabled
parent
d545431f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
94 additions
and
6 deletions
+94
-6
helper/communicator/config.go
helper/communicator/config.go
+5
-0
helper/communicator/config_test.go
helper/communicator/config_test.go
+28
-0
helper/communicator/step_connect.go
helper/communicator/step_connect.go
+22
-6
helper/communicator/step_connect_test.go
helper/communicator/step_connect_test.go
+39
-0
No files found.
helper/communicator/config.go
View file @
4b4fe228
...
...
@@ -10,6 +10,7 @@ import (
// Config is the common configuration that communicators allow within
// a builder.
type
Config
struct
{
Type
string
`mapstructure:"communicator"`
SSHHost
string
`mapstructure:"ssh_host"`
SSHPort
int
`mapstructure:"ssh_port"`
SSHUsername
string
`mapstructure:"ssh_username"`
...
...
@@ -20,6 +21,10 @@ type Config struct {
}
func
(
c
*
Config
)
Prepare
(
ctx
*
interpolate
.
Context
)
[]
error
{
if
c
.
Type
==
""
{
c
.
Type
=
"ssh"
}
if
c
.
SSHPort
==
0
{
c
.
SSHPort
=
22
}
...
...
helper/communicator/config_test.go
0 → 100644
View file @
4b4fe228
package
communicator
import
(
"testing"
"github.com/mitchellh/packer/template/interpolate"
)
func
testConfig
()
*
Config
{
return
&
Config
{
SSHUsername
:
"root"
,
}
}
func
TestConfigType
(
t
*
testing
.
T
)
{
c
:=
testConfig
()
if
err
:=
c
.
Prepare
(
testContext
(
t
));
len
(
err
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
err
)
}
if
c
.
Type
!=
"ssh"
{
t
.
Fatal
(
"bad: %#v"
,
c
)
}
}
func
testContext
(
t
*
testing
.
T
)
*
interpolate
.
Context
{
return
nil
}
helper/communicator/step_connect.go
View file @
4b4fe228
package
communicator
import
(
"fmt"
"log"
"github.com/mitchellh/multistep"
gossh
"golang.org/x/crypto/ssh"
)
...
...
@@ -26,14 +29,27 @@ type StepConnect struct {
}
func
(
s
*
StepConnect
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
// Eventually we might switch between multiple of these depending
// on the communicator type.
s
.
substep
=
&
StepConnectSSH
{
Config
:
s
.
Config
,
SSHAddress
:
s
.
SSHAddress
,
SSHConfig
:
s
.
SSHConfig
,
typeMap
:=
map
[
string
]
multistep
.
Step
{
"none"
:
nil
,
"ssh"
:
&
StepConnectSSH
{
Config
:
s
.
Config
,
SSHAddress
:
s
.
SSHAddress
,
SSHConfig
:
s
.
SSHConfig
,
},
}
step
,
ok
:=
typeMap
[
s
.
Config
.
Type
]
if
!
ok
{
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"unknown communicator type: %s"
,
s
.
Config
.
Type
))
return
multistep
.
ActionHalt
}
if
step
==
nil
{
log
.
Printf
(
"[INFO] communicator disabled, will not connect"
)
return
multistep
.
ActionContinue
}
s
.
substep
=
step
return
s
.
substep
.
Run
(
state
)
}
...
...
helper/communicator/step_connect_test.go
0 → 100644
View file @
4b4fe228
package
communicator
import
(
"bytes"
"testing"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
)
func
TestStepConnect_impl
(
t
*
testing
.
T
)
{
var
_
multistep
.
Step
=
new
(
StepConnect
)
}
func
TestStepConnect_none
(
t
*
testing
.
T
)
{
state
:=
testState
(
t
)
step
:=
&
StepConnect
{
Config
:
&
Config
{
Type
:
"none"
,
},
}
defer
step
.
Cleanup
(
state
)
// run the step
if
action
:=
step
.
Run
(
state
);
action
!=
multistep
.
ActionContinue
{
t
.
Fatalf
(
"bad action: %#v"
,
action
)
}
}
func
testState
(
t
*
testing
.
T
)
multistep
.
StateBag
{
state
:=
new
(
multistep
.
BasicStateBag
)
state
.
Put
(
"hook"
,
&
packer
.
MockHook
{})
state
.
Put
(
"ui"
,
&
packer
.
BasicUi
{
Reader
:
new
(
bytes
.
Buffer
),
Writer
:
new
(
bytes
.
Buffer
),
})
return
state
}
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