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 { ...@@ -21,6 +21,12 @@ type Build interface {
// Cancel will cancel a running build. This will block until the build // Cancel will cancel a running build. This will block until the build
// is actually completely cancelled. // is actually completely cancelled.
Cancel() 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 // A build struct represents a single build job, the result of which should
...@@ -34,6 +40,7 @@ type coreBuild struct { ...@@ -34,6 +40,7 @@ type coreBuild struct {
hooks map[string][]Hook hooks map[string][]Hook
provisioners []coreBuildProvisioner provisioners []coreBuildProvisioner
debug bool
prepareCalled bool prepareCalled bool
} }
...@@ -103,6 +110,14 @@ func (b *coreBuild) Run(ui Ui, cache Cache) (Artifact, error) { ...@@ -103,6 +110,14 @@ func (b *coreBuild) Run(ui Ui, cache Cache) (Artifact, error) {
return b.builder.Run(ui, hook, cache) 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. // Cancels the build if it is running.
func (b *coreBuild) Cancel() { func (b *coreBuild) Cancel() {
b.builder.Cancel() b.builder.Cancel()
......
...@@ -58,6 +58,12 @@ func (b *build) Run(ui packer.Ui, cache packer.Cache) (packer.Artifact, error) { ...@@ -58,6 +58,12 @@ func (b *build) Run(ui packer.Ui, cache packer.Cache) (packer.Artifact, error) {
return Artifact(client), nil 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() { func (b *build) Cancel() {
if err := b.client.Call("Build.Cancel", new(interface{}), new(interface{})); err != nil { if err := b.client.Call("Build.Cancel", new(interface{}), new(interface{})); err != nil {
panic(err) panic(err)
...@@ -93,6 +99,11 @@ func (b *BuildServer) Run(args *BuildRunArgs, reply *string) error { ...@@ -93,6 +99,11 @@ func (b *BuildServer) Run(args *BuildRunArgs, reply *string) error {
return nil 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 { func (b *BuildServer) Cancel(args *interface{}, reply *interface{}) error {
b.build.Cancel() b.build.Cancel()
return nil return nil
......
...@@ -16,6 +16,7 @@ type testBuild struct { ...@@ -16,6 +16,7 @@ type testBuild struct {
runCalled bool runCalled bool
runCache packer.Cache runCache packer.Cache
runUi packer.Ui runUi packer.Ui
setDebugCalled bool
cancelCalled bool cancelCalled bool
errRunResult bool errRunResult bool
...@@ -43,6 +44,10 @@ func (b *testBuild) Run(ui packer.Ui, cache packer.Cache) (packer.Artifact, erro ...@@ -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() { func (b *testBuild) Cancel() {
b.cancelCalled = true b.cancelCalled = true
} }
...@@ -93,6 +98,10 @@ func TestBuildRPC(t *testing.T) { ...@@ -93,6 +98,10 @@ func TestBuildRPC(t *testing.T) {
_, err = bClient.Run(ui, cache) _, err = bClient.Run(ui, cache)
assert.NotNil(err, "should not nil") assert.NotNil(err, "should not nil")
// Test SetDebug
bClient.SetDebug(true)
assert.True(b.setDebugCalled, "should be called")
// Test Cancel // Test Cancel
bClient.Cancel() bClient.Cancel()
assert.True(b.cancelCalled, "cancel should be called") 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