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
95d4b845
Commit
95d4b845
authored
Jun 16, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2251 from mitchellh/b-warn-prov
packer: HookProvision errors if no communicator
parents
944ada85
2d13db30
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
7 deletions
+39
-7
common/step_provision.go
common/step_provision.go
+4
-2
packer/build_test.go
packer/build_test.go
+1
-1
packer/builder_mock.go
packer/builder_mock.go
+1
-1
packer/provisioner.go
packer/provisioner.go
+12
-0
packer/provisioner_test.go
packer/provisioner_test.go
+21
-3
No files found.
common/step_provision.go
View file @
95d4b845
...
...
@@ -23,9 +23,11 @@ type StepProvision struct {
func
(
s
*
StepProvision
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
comm
:=
s
.
Comm
if
comm
==
nil
{
comm
=
state
.
Get
(
"communicator"
)
.
(
packer
.
Communicator
)
raw
,
ok
:=
state
.
Get
(
"communicator"
)
.
(
packer
.
Communicator
)
if
ok
{
comm
=
raw
.
(
packer
.
Communicator
)
}
}
hook
:=
state
.
Get
(
"hook"
)
.
(
packer
.
Hook
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
...
...
packer/build_test.go
View file @
95d4b845
...
...
@@ -202,7 +202,7 @@ func TestBuild_Run(t *testing.T) {
}
// Verify provisioners run
dispatchHook
.
Run
(
HookProvision
,
nil
,
n
il
,
42
)
dispatchHook
.
Run
(
HookProvision
,
nil
,
n
ew
(
MockCommunicator
)
,
42
)
prov
:=
build
.
provisioners
[
0
]
.
provisioner
.
(
*
MockProvisioner
)
if
!
prov
.
ProvCalled
{
t
.
Fatal
(
"should be called"
)
...
...
packer/builder_mock.go
View file @
95d4b845
...
...
@@ -43,7 +43,7 @@ func (tb *MockBuilder) Run(ui Ui, h Hook, c Cache) (Artifact, error) {
}
if
h
!=
nil
{
if
err
:=
h
.
Run
(
HookProvision
,
ui
,
n
il
,
nil
);
err
!=
nil
{
if
err
:=
h
.
Run
(
HookProvision
,
ui
,
n
ew
(
MockCommunicator
)
,
nil
);
err
!=
nil
{
return
nil
,
err
}
}
...
...
packer/provisioner.go
View file @
95d4b845
...
...
@@ -38,6 +38,18 @@ type ProvisionHook struct {
// Runs the provisioners in order.
func
(
h
*
ProvisionHook
)
Run
(
name
string
,
ui
Ui
,
comm
Communicator
,
data
interface
{})
error
{
// Shortcut
if
len
(
h
.
Provisioners
)
==
0
{
return
nil
}
if
comm
==
nil
{
return
fmt
.
Errorf
(
"No communicator found for provisioners! This is usually because the
\n
"
+
"`communicator` config was set to
\"
none
\"
. If you have any provisioners
\n
"
+
"then a communicator is required. Please fix this to continue."
)
}
defer
func
()
{
h
.
lock
.
Lock
()
defer
h
.
lock
.
Unlock
()
...
...
packer/provisioner_test.go
View file @
95d4b845
...
...
@@ -19,7 +19,7 @@ func TestProvisionHook(t *testing.T) {
pB
:=
&
MockProvisioner
{}
ui
:=
testUi
()
var
comm
Communicator
=
n
il
var
comm
Communicator
=
n
ew
(
MockCommunicator
)
var
data
interface
{}
=
nil
hook
:=
&
ProvisionHook
{
...
...
@@ -37,6 +37,24 @@ func TestProvisionHook(t *testing.T) {
}
}
func
TestProvisionHook_nilComm
(
t
*
testing
.
T
)
{
pA
:=
&
MockProvisioner
{}
pB
:=
&
MockProvisioner
{}
ui
:=
testUi
()
var
comm
Communicator
=
nil
var
data
interface
{}
=
nil
hook
:=
&
ProvisionHook
{
Provisioners
:
[]
Provisioner
{
pA
,
pB
},
}
err
:=
hook
.
Run
(
"foo"
,
ui
,
comm
,
data
)
if
err
==
nil
{
t
.
Fatal
(
"should error"
)
}
}
func
TestProvisionHook_cancel
(
t
*
testing
.
T
)
{
var
lock
sync
.
Mutex
order
:=
make
([]
string
,
0
,
2
)
...
...
@@ -59,7 +77,7 @@ func TestProvisionHook_cancel(t *testing.T) {
finished
:=
make
(
chan
struct
{})
go
func
()
{
hook
.
Run
(
"foo"
,
nil
,
n
il
,
nil
)
hook
.
Run
(
"foo"
,
nil
,
n
ew
(
MockCommunicator
)
,
nil
)
close
(
finished
)
}()
...
...
@@ -74,7 +92,7 @@ func TestProvisionHook_cancel(t *testing.T) {
<-
finished
// Verify order
if
order
[
0
]
!=
"cancel"
||
order
[
1
]
!=
"prov"
{
if
len
(
order
)
!=
2
||
order
[
0
]
!=
"cancel"
||
order
[
1
]
!=
"prov"
{
t
.
Fatalf
(
"bad: %#v"
,
order
)
}
}
...
...
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