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
6b87c42e
Commit
6b87c42e
authored
Jun 06, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: Change provisioner interface to take array of configs
parent
a7896e7c
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
23 additions
and
42 deletions
+23
-42
packer/build.go
packer/build.go
+1
-1
packer/build_test.go
packer/build_test.go
+1
-2
packer/plugin/provisioner.go
packer/plugin/provisioner.go
+2
-2
packer/plugin/provisioner_test.go
packer/plugin/provisioner_test.go
+1
-1
packer/provisioner.go
packer/provisioner.go
+1
-1
packer/provisioner_test.go
packer/provisioner_test.go
+3
-5
packer/rpc/provisioner.go
packer/rpc/provisioner.go
+4
-16
packer/rpc/provisioner_test.go
packer/rpc/provisioner_test.go
+6
-12
provisioner/shell/provisioner.go
provisioner/shell/provisioner.go
+4
-2
No files found.
packer/build.go
View file @
6b87c42e
...
@@ -52,7 +52,7 @@ func (b *coreBuild) Prepare(ui Ui) (err error) {
...
@@ -52,7 +52,7 @@ func (b *coreBuild) Prepare(ui Ui) (err error) {
// Prepare the provisioners
// Prepare the provisioners
// TODO: error handling
// TODO: error handling
for
_
,
coreProv
:=
range
b
.
provisioners
{
for
_
,
coreProv
:=
range
b
.
provisioners
{
coreProv
.
provisioner
.
Prepare
(
coreProv
.
config
,
ui
)
coreProv
.
provisioner
.
Prepare
(
coreProv
.
config
)
}
}
return
return
...
...
packer/build_test.go
View file @
6b87c42e
...
@@ -47,8 +47,7 @@ func TestBuild_Prepare(t *testing.T) {
...
@@ -47,8 +47,7 @@ func TestBuild_Prepare(t *testing.T) {
coreProv
:=
coreB
.
provisioners
[
0
]
coreProv
:=
coreB
.
provisioners
[
0
]
prov
:=
coreProv
.
provisioner
.
(
*
TestProvisioner
)
prov
:=
coreProv
.
provisioner
.
(
*
TestProvisioner
)
assert
.
True
(
prov
.
prepCalled
,
"prepare should be called"
)
assert
.
True
(
prov
.
prepCalled
,
"prepare should be called"
)
assert
.
Equal
(
prov
.
prepConfig
,
42
,
"prepare should be called with proper config"
)
assert
.
Equal
(
prov
.
prepConfigs
,
[]
interface
{}{
42
},
"prepare should be called with proper config"
)
assert
.
Equal
(
prov
.
prepUi
,
ui
,
"prepare should be called with proper ui"
)
}
}
func
TestBuild_Run
(
t
*
testing
.
T
)
{
func
TestBuild_Run
(
t
*
testing
.
T
)
{
...
...
packer/plugin/provisioner.go
View file @
6b87c42e
...
@@ -13,13 +13,13 @@ type cmdProvisioner struct {
...
@@ -13,13 +13,13 @@ type cmdProvisioner struct {
client
*
client
client
*
client
}
}
func
(
c
*
cmdProvisioner
)
Prepare
(
config
interface
{},
ui
packer
.
Ui
)
{
func
(
c
*
cmdProvisioner
)
Prepare
(
config
s
...
interface
{}
)
{
defer
func
()
{
defer
func
()
{
r
:=
recover
()
r
:=
recover
()
c
.
checkExit
(
r
,
nil
)
c
.
checkExit
(
r
,
nil
)
}()
}()
c
.
p
.
Prepare
(
config
,
ui
)
c
.
p
.
Prepare
(
config
s
...
)
}
}
func
(
c
*
cmdProvisioner
)
Provision
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
)
{
func
(
c
*
cmdProvisioner
)
Provision
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
)
{
...
...
packer/plugin/provisioner_test.go
View file @
6b87c42e
...
@@ -9,7 +9,7 @@ import (
...
@@ -9,7 +9,7 @@ import (
type
helperProvisioner
byte
type
helperProvisioner
byte
func
(
helperProvisioner
)
Prepare
(
interface
{},
packer
.
Ui
)
{}
func
(
helperProvisioner
)
Prepare
(
...
interface
{}
)
{}
func
(
helperProvisioner
)
Provision
(
packer
.
Ui
,
packer
.
Communicator
)
{}
func
(
helperProvisioner
)
Provision
(
packer
.
Ui
,
packer
.
Communicator
)
{}
...
...
packer/provisioner.go
View file @
6b87c42e
...
@@ -6,7 +6,7 @@ type Provisioner interface {
...
@@ -6,7 +6,7 @@ type Provisioner interface {
// Prepare is called with the raw configuration and a UI element in
// Prepare is called with the raw configuration and a UI element in
// order to setup the internal state of the provisioner and perform
// order to setup the internal state of the provisioner and perform
// any validation necessary for the provisioner.
// any validation necessary for the provisioner.
Prepare
(
interface
{},
Ui
)
Prepare
(
...
interface
{}
)
// Provision is called to actually provision the machine. A UI is
// Provision is called to actually provision the machine. A UI is
// given to communicate with the user, and a communicator is given that
// given to communicate with the user, and a communicator is given that
...
...
packer/provisioner_test.go
View file @
6b87c42e
...
@@ -4,15 +4,13 @@ import "testing"
...
@@ -4,15 +4,13 @@ import "testing"
type
TestProvisioner
struct
{
type
TestProvisioner
struct
{
prepCalled
bool
prepCalled
bool
prepConfig
interface
{}
prepConfigs
[]
interface
{}
prepUi
Ui
provCalled
bool
provCalled
bool
}
}
func
(
t
*
TestProvisioner
)
Prepare
(
config
interface
{},
ui
Ui
)
{
func
(
t
*
TestProvisioner
)
Prepare
(
config
s
...
interface
{}
)
{
t
.
prepCalled
=
true
t
.
prepCalled
=
true
t
.
prepConfig
=
config
t
.
prepConfigs
=
configs
t
.
prepUi
=
ui
}
}
func
(
t
*
TestProvisioner
)
Provision
(
Ui
,
Communicator
)
{
func
(
t
*
TestProvisioner
)
Provision
(
Ui
,
Communicator
)
{
...
...
packer/rpc/provisioner.go
View file @
6b87c42e
...
@@ -18,8 +18,7 @@ type ProvisionerServer struct {
...
@@ -18,8 +18,7 @@ type ProvisionerServer struct {
}
}
type
ProvisionerPrepareArgs
struct
{
type
ProvisionerPrepareArgs
struct
{
Config
interface
{}
Configs
[]
interface
{}
RPCAddress
string
}
}
type
ProvisionerProvisionArgs
struct
{
type
ProvisionerProvisionArgs
struct
{
...
@@ -29,12 +28,8 @@ type ProvisionerProvisionArgs struct {
...
@@ -29,12 +28,8 @@ type ProvisionerProvisionArgs struct {
func
Provisioner
(
client
*
rpc
.
Client
)
*
provisioner
{
func
Provisioner
(
client
*
rpc
.
Client
)
*
provisioner
{
return
&
provisioner
{
client
}
return
&
provisioner
{
client
}
}
}
func
(
p
*
provisioner
)
Prepare
(
config
interface
{},
ui
packer
.
Ui
)
{
func
(
p
*
provisioner
)
Prepare
(
configs
...
interface
{})
{
// TODO: Error handling
args
:=
&
ProvisionerPrepareArgs
{
configs
}
server
:=
rpc
.
NewServer
()
RegisterUi
(
server
,
ui
)
args
:=
&
ProvisionerPrepareArgs
{
config
,
serveSingleConn
(
server
)}
p
.
client
.
Call
(
"Provisioner.Prepare"
,
args
,
new
(
interface
{}))
p
.
client
.
Call
(
"Provisioner.Prepare"
,
args
,
new
(
interface
{}))
}
}
...
@@ -49,14 +44,7 @@ func (p *provisioner) Provision(ui packer.Ui, comm packer.Communicator) {
...
@@ -49,14 +44,7 @@ func (p *provisioner) Provision(ui packer.Ui, comm packer.Communicator) {
}
}
func
(
p
*
ProvisionerServer
)
Prepare
(
args
*
ProvisionerPrepareArgs
,
reply
*
interface
{})
error
{
func
(
p
*
ProvisionerServer
)
Prepare
(
args
*
ProvisionerPrepareArgs
,
reply
*
interface
{})
error
{
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
args
.
RPCAddress
)
p
.
p
.
Prepare
(
args
.
Configs
...
)
if
err
!=
nil
{
return
err
}
ui
:=
&
Ui
{
client
}
p
.
p
.
Prepare
(
args
.
Config
,
ui
)
return
nil
return
nil
}
}
...
...
packer/rpc/provisioner_test.go
View file @
6b87c42e
...
@@ -9,17 +9,15 @@ import (
...
@@ -9,17 +9,15 @@ import (
type
testProvisioner
struct
{
type
testProvisioner
struct
{
prepareCalled
bool
prepareCalled
bool
prepareConfig
interface
{}
prepareConfigs
[]
interface
{}
prepareUi
packer
.
Ui
provCalled
bool
provCalled
bool
provComm
packer
.
Communicator
provComm
packer
.
Communicator
provUi
packer
.
Ui
provUi
packer
.
Ui
}
}
func
(
p
*
testProvisioner
)
Prepare
(
config
interface
{},
ui
packer
.
Ui
)
{
func
(
p
*
testProvisioner
)
Prepare
(
config
s
...
interface
{}
)
{
p
.
prepareCalled
=
true
p
.
prepareCalled
=
true
p
.
prepareConfig
=
config
p
.
prepareConfigs
=
configs
p
.
prepareUi
=
ui
}
}
func
(
p
*
testProvisioner
)
Provision
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
)
{
func
(
p
*
testProvisioner
)
Provision
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
)
{
...
@@ -45,17 +43,13 @@ func TestProvisionerRPC(t *testing.T) {
...
@@ -45,17 +43,13 @@ func TestProvisionerRPC(t *testing.T) {
// Test Prepare
// Test Prepare
config
:=
42
config
:=
42
ui
:=
&
testUi
{}
pClient
:=
Provisioner
(
client
)
pClient
:=
Provisioner
(
client
)
pClient
.
Prepare
(
config
,
ui
)
pClient
.
Prepare
(
config
)
assert
.
True
(
p
.
prepareCalled
,
"prepare should be called"
)
assert
.
True
(
p
.
prepareCalled
,
"prepare should be called"
)
assert
.
Equal
(
p
.
prepareConfig
,
42
,
"prepare should be called with right arg"
)
assert
.
Equal
(
p
.
prepareConfigs
,
[]
interface
{}{
42
},
"prepare should be called with right arg"
)
p
.
prepareUi
.
Say
(
"foo"
)
assert
.
True
(
ui
.
sayCalled
,
"say should be called"
)
// Test Provision
// Test Provision
ui
=
&
testUi
{}
ui
:
=
&
testUi
{}
comm
:=
&
testCommunicator
{}
comm
:=
&
testCommunicator
{}
pClient
.
Provision
(
ui
,
comm
)
pClient
.
Provision
(
ui
,
comm
)
assert
.
True
(
p
.
provCalled
,
"provision should be called"
)
assert
.
True
(
p
.
provCalled
,
"provision should be called"
)
...
...
provisioner/shell/provisioner.go
View file @
6b87c42e
...
@@ -29,9 +29,11 @@ type Provisioner struct {
...
@@ -29,9 +29,11 @@ type Provisioner struct {
config
config
config
config
}
}
func
(
p
*
Provisioner
)
Prepare
(
raw
interface
{},
ui
packer
.
Ui
)
{
func
(
p
*
Provisioner
)
Prepare
(
raw
s
...
interface
{}
)
{
// TODO: errors
// TODO: errors
_
=
mapstructure
.
Decode
(
raw
,
&
p
.
config
)
for
_
,
raw
:=
range
raws
{
_
=
mapstructure
.
Decode
(
raw
,
&
p
.
config
)
}
if
p
.
config
.
RemotePath
==
""
{
if
p
.
config
.
RemotePath
==
""
{
p
.
config
.
RemotePath
=
DefaultRemotePath
p
.
config
.
RemotePath
=
DefaultRemotePath
...
...
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