Commit a45c7fb0 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Add SetDebug to Build objects

parent e00a30e7
......@@ -21,6 +21,12 @@ type Build interface {
// Cancel will cancel a running build. This will block until the build
// is actually completely cancelled.
Cancel()
// SetDebug will enable/disable debug mode. Debug mode is always
// enabled by adding the additional key "packer_debug" to boolean
// true in the configuration of the various components. This must
// be called prior to Prepare.
SetDebug(bool)
}
// A build struct represents a single build job, the result of which should
......@@ -34,6 +40,7 @@ type coreBuild struct {
hooks map[string][]Hook
provisioners []coreBuildProvisioner
debug bool
prepareCalled bool
}
......@@ -103,6 +110,14 @@ func (b *coreBuild) Run(ui Ui, cache Cache) (Artifact, error) {
return b.builder.Run(ui, hook, cache)
}
func (b *coreBuild) SetDebug(val bool) {
if b.prepareCalled {
panic("prepare has already been called")
}
b.debug = val
}
// Cancels the build if it is running.
func (b *coreBuild) Cancel() {
b.builder.Cancel()
......
......@@ -58,6 +58,12 @@ func (b *build) Run(ui packer.Ui, cache packer.Cache) (packer.Artifact, error) {
return Artifact(client), nil
}
func (b *build) SetDebug(val bool) {
if err := b.client.Call("Build.SetDebug", val, new(interface{})); err != nil {
panic(err)
}
}
func (b *build) Cancel() {
if err := b.client.Call("Build.Cancel", new(interface{}), new(interface{})); err != nil {
panic(err)
......@@ -93,6 +99,11 @@ func (b *BuildServer) Run(args *BuildRunArgs, reply *string) error {
return nil
}
func (b *BuildServer) SetDebug(val *bool, reply *interface{}) error {
b.build.SetDebug(*val)
return nil
}
func (b *BuildServer) Cancel(args *interface{}, reply *interface{}) error {
b.build.Cancel()
return nil
......
......@@ -11,12 +11,13 @@ import (
var testBuildArtifact = &testArtifact{}
type testBuild struct {
nameCalled bool
prepareCalled bool
runCalled bool
runCache packer.Cache
runUi packer.Ui
cancelCalled bool
nameCalled bool
prepareCalled bool
runCalled bool
runCache packer.Cache
runUi packer.Ui
setDebugCalled bool
cancelCalled bool
errRunResult bool
}
......@@ -43,6 +44,10 @@ func (b *testBuild) Run(ui packer.Ui, cache packer.Cache) (packer.Artifact, erro
}
}
func (b *testBuild) SetDebug(bool) {
b.setDebugCalled = true
}
func (b *testBuild) Cancel() {
b.cancelCalled = true
}
......@@ -93,6 +98,10 @@ func TestBuildRPC(t *testing.T) {
_, err = bClient.Run(ui, cache)
assert.NotNil(err, "should not nil")
// Test SetDebug
bClient.SetDebug(true)
assert.True(b.setDebugCalled, "should be called")
// Test Cancel
bClient.Cancel()
assert.True(b.cancelCalled, "cancel should be called")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment