packer: Add SetDebug to Build objects
This commit is contained in:
parent
e00a30e729
commit
a45c7fb0ea
|
@ -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 {
|
||||||
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) {
|
||||||
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) {
|
||||||
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 {
|
||||||
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
|
||||||
|
|
|
@ -11,12 +11,13 @@ import (
|
||||||
var testBuildArtifact = &testArtifact{}
|
var testBuildArtifact = &testArtifact{}
|
||||||
|
|
||||||
type testBuild struct {
|
type testBuild struct {
|
||||||
nameCalled bool
|
nameCalled bool
|
||||||
prepareCalled bool
|
prepareCalled bool
|
||||||
runCalled bool
|
runCalled bool
|
||||||
runCache packer.Cache
|
runCache packer.Cache
|
||||||
runUi packer.Ui
|
runUi packer.Ui
|
||||||
cancelCalled bool
|
setDebugCalled bool
|
||||||
|
cancelCalled bool
|
||||||
|
|
||||||
errRunResult 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() {
|
func (b *testBuild) Cancel() {
|
||||||
b.cancelCalled = true
|
b.cancelCalled = true
|
||||||
}
|
}
|
||||||
|
@ -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")
|
||||||
|
|
Loading…
Reference in New Issue